17
17
#include " ErrorReporting.h"
18
18
#include " GlobalHandler.h"
19
19
#include " JIT.h"
20
+ #include " Shared/EnvironmentVar.h"
20
21
#include " Shared/Sanitizer.h"
21
22
#include " Shared/Utils.h"
22
23
#include " Utils/ELF.h"
@@ -939,24 +940,33 @@ GenericDeviceTy::loadBinary(GenericPluginTy &Plugin,
939
940
if (auto Err = callGlobalConstructors (Plugin, *Image))
940
941
return std::move (Err);
941
942
942
- auto GetKernel = [&](StringRef Name) -> GenericKernelTy * {
943
- auto KernelOrErr = constructKernel (Name.data ());
944
- if (Error Err = KernelOrErr.takeError ()) {
945
- REPORT (" Failure to look up kernel: %s\n " ,
946
- toString (std::move (Err)).data ());
947
- return nullptr ;
943
+ auto *&SanitizerTrapInfo = SanitizerTrapInfos[Image];
944
+ GlobalTy TrapId (" __sanitizer_trap_info_ptr" , sizeof (SanitizerTrapInfo),
945
+ &SanitizerTrapInfo);
946
+ GenericGlobalHandlerTy &GHandler = Plugin.getGlobalHandler ();
947
+ if (GHandler.isSymbolInImage (*this , *Image, TrapId.getName ())) {
948
+
949
+ SanitizerTrapInfo = reinterpret_cast <SanitizerTrapInfoTy *>(allocate (
950
+ sizeof (*SanitizerTrapInfo), &SanitizerTrapInfo, TARGET_ALLOC_HOST));
951
+ memset (SanitizerTrapInfo, ' \0 ' , sizeof (SanitizerTrapInfoTy));
952
+
953
+ if (auto Err = GHandler.writeGlobalToDevice (*this , *Image, TrapId))
954
+ return Err;
955
+ {
956
+ auto KernelOrErr = getKernel (" __sanitizer_register" , Image);
957
+ if (auto Err = KernelOrErr.takeError ())
958
+ consumeError (std::move (Err));
959
+ else
960
+ addGPUSanNewFn (*KernelOrErr);
948
961
}
949
- GenericKernelTy &Kernel = *KernelOrErr;
950
- if (auto Err = Kernel.init (*this , *Image)) {
951
- REPORT (" Failure to init kernel: %s\n " , toString (std::move (Err)).data ());
952
- return nullptr ;
962
+ {
963
+ auto KernelOrErr = getKernel (" __sanitizer_unregister" , Image);
964
+ if (auto Err = KernelOrErr.takeError ())
965
+ consumeError (std::move (Err));
966
+ else
967
+ addGPUSanFreeFn (*KernelOrErr);
953
968
}
954
- return &Kernel;
955
- };
956
- if (GenericKernelTy *Kernel = GetKernel (" __sanitizer_register" ))
957
- addGPUSanNewFn (*Kernel);
958
- if (GenericKernelTy *Kernel = GetKernel (" __sanitizer_unregister" ))
959
- addGPUSanFreeFn (*Kernel);
969
+ }
960
970
961
971
// Return the pointer to the table of entries.
962
972
return Image;
@@ -1036,16 +1046,6 @@ Error GenericDeviceTy::setupDeviceMemoryPool(GenericPluginTy &Plugin,
1036
1046
if (auto Err = GHandler.writeGlobalToDevice (*this , Image, TrackerGlobal))
1037
1047
return Err;
1038
1048
1039
- auto *&SanitizerTrapInfo = SanitizerTrapInfos[&Image];
1040
- SanitizerTrapInfo = reinterpret_cast <SanitizerTrapInfoTy *>(allocate (
1041
- sizeof (*SanitizerTrapInfo), &SanitizerTrapInfo, TARGET_ALLOC_HOST));
1042
- memset (SanitizerTrapInfo, ' \0 ' , sizeof (SanitizerTrapInfoTy));
1043
-
1044
- GlobalTy TrapId (" __sanitizer_trap_info_ptr" , sizeof (SanitizerTrapInfo),
1045
- &SanitizerTrapInfo);
1046
- if (auto Err = GHandler.writeGlobalToDevice (*this , Image, TrapId))
1047
- return Err;
1048
-
1049
1049
// Create the metainfo of the device environment global.
1050
1050
GlobalTy DevEnvGlobal (" __omp_rtl_device_memory_pool" ,
1051
1051
sizeof (DeviceMemoryPoolTy), &DeviceMemoryPool);
@@ -2404,32 +2404,17 @@ void GPUSanTy::checkAndReportError() {
2404
2404
Green (), STI->PtrSlot , STI->PtrTag , STI->PtrKind , STI->AllocationId ,
2405
2405
STI->AllocationTag , STI->AllocationKind , Default ());
2406
2406
2407
- AllocationInfoTy *AllocationInfo = nullptr ;
2408
- if (STI->AllocationStart ) {
2409
- auto AllocationTraceMap = Device.AllocationTraces .getExclusiveAccessor ();
2410
- AllocationInfo = (*AllocationTraceMap)[STI->AllocationStart ];
2411
- }
2412
- if (AllocationInfo) {
2413
- fprintf (stderr, " \n Allocated at\n " );
2414
- fprintf (stderr, " %s" , AllocationInfo->AllocationTrace .c_str ());
2415
-
2416
- if (!AllocationInfo->DeallocationTrace .empty ()) {
2417
- fprintf (stderr, " \n Deallocated at\n " );
2418
- fprintf (stderr, " %s" , AllocationInfo->DeallocationTrace .c_str ());
2419
- }
2420
- }
2421
-
2422
2407
};
2423
2408
2424
2409
switch (STI->ErrorCode ) {
2425
2410
case SanitizerTrapInfoTy::None:
2426
2411
llvm_unreachable (" Unexpected exception" );
2427
2412
case SanitizerTrapInfoTy::ExceedsLength:
2428
- fprintf (stderr, " %sERROR: OffloadSanitizer %s %d \n %s" , Red (),
2413
+ fprintf (stderr, " %sERROR: OffloadSanitizer %s %lu \n %s" , Red (),
2429
2414
" exceeds length" , STI->PtrSlot , Default ());
2430
2415
break ;
2431
2416
case SanitizerTrapInfoTy::ExceedsSlots:
2432
- fprintf (stderr, " %sERROR: OffloadSanitizer %s %d \n %s" , Red (),
2417
+ fprintf (stderr, " %sERROR: OffloadSanitizer %s %lu \n %s" , Red (),
2433
2418
" exceeds slots" , STI->PtrSlot , Default ());
2434
2419
break ;
2435
2420
case SanitizerTrapInfoTy::PointerOutsideAllocation:
@@ -2449,7 +2434,7 @@ void GPUSanTy::checkAndReportError() {
2449
2434
DiagnoseAccess (" use-after-free" );
2450
2435
break ;
2451
2436
case SanitizerTrapInfoTy::MemoryLeak:
2452
- fprintf (stderr, " %sERROR: OffloadSanitizer memory leak at slot %d \n %s" ,
2437
+ fprintf (stderr, " %sERROR: OffloadSanitizer memory leak at slot %lu \n %s" ,
2453
2438
Red (), STI->PtrSlot , Default ());
2454
2439
break ;
2455
2440
case SanitizerTrapInfoTy::GarbagePointer:
0 commit comments