Index: compiler-rt/trunk/lib/esan/esan.h =================================================================== --- compiler-rt/trunk/lib/esan/esan.h +++ compiler-rt/trunk/lib/esan/esan.h @@ -34,8 +34,6 @@ extern bool EsanIsInitialized; -extern ToolType WhichTool; - void initializeLibrary(ToolType Tool); int finalizeLibrary(); // Esan creates the variable per tool per compilation unit at compile time Index: compiler-rt/trunk/lib/esan/esan.cpp =================================================================== --- compiler-rt/trunk/lib/esan/esan.cpp +++ compiler-rt/trunk/lib/esan/esan.cpp @@ -30,7 +30,6 @@ namespace __esan { bool EsanIsInitialized; -ToolType WhichTool; ShadowMapping Mapping; // Different tools use different scales within the same shadow mapping scheme. @@ -65,22 +64,22 @@ void processRangeAccess(uptr PC, uptr Addr, int Size, bool IsWrite) { VPrintf(3, "in esan::%s %p: %c %p %d\n", __FUNCTION__, PC, IsWrite ? 'w' : 'r', Addr, Size); - if (WhichTool == ESAN_CacheFrag) { + if (__esan_which_tool == ESAN_CacheFrag) { // TODO(bruening): add shadow mapping and update shadow bits here. // We'll move this to cache_frag.cpp once we have something. - } else if (WhichTool == ESAN_WorkingSet) { + } else if (__esan_which_tool == ESAN_WorkingSet) { processRangeAccessWorkingSet(PC, Addr, Size, IsWrite); } } bool processSignal(int SigNum, void (*Handler)(int), void (**Result)(int)) { - if (WhichTool == ESAN_WorkingSet) + if (__esan_which_tool == ESAN_WorkingSet) return processWorkingSetSignal(SigNum, Handler, Result); return true; } bool processSigaction(int SigNum, const void *Act, void *OldAct) { - if (WhichTool == ESAN_WorkingSet) + if (__esan_which_tool == ESAN_WorkingSet) return processWorkingSetSigaction(SigNum, Act, OldAct); return true; } @@ -140,7 +139,7 @@ DCHECK(verifyShadowScheme()); - Mapping.initialize(ShadowScale[WhichTool]); + Mapping.initialize(ShadowScale[__esan_which_tool]); VPrintf(1, "Shadow scale=%d offset=%p\n", Mapping.Scale, Mapping.Offset); @@ -150,7 +149,7 @@ (ShadowEnd - ShadowStart) >> 30); uptr Map; - if (WhichTool == ESAN_WorkingSet) { + if (__esan_which_tool == ESAN_WorkingSet) { // We want to identify all shadow pages that are touched so we start // out inaccessible. Map = (uptr)MmapFixedNoAccess(ShadowStart, ShadowEnd- ShadowStart, @@ -176,10 +175,9 @@ void initializeLibrary(ToolType Tool) { // We assume there is only one thread during init. if (EsanIsInitialized) { - CHECK(Tool == WhichTool); + CHECK(Tool == __esan_which_tool); return; } - WhichTool = Tool; SanitizerToolName = "EfficiencySanitizer"; CacheBinaryName(); initializeFlags(); @@ -190,17 +188,17 @@ ::__cxa_atexit((void (*)())finalizeLibrary); VPrintf(1, "in esan::%s\n", __FUNCTION__); - if (WhichTool <= ESAN_None || WhichTool >= ESAN_Max) { - Printf("ERROR: unknown tool %d requested\n", WhichTool); + if (__esan_which_tool <= ESAN_None || __esan_which_tool >= ESAN_Max) { + Printf("ERROR: unknown tool %d requested\n", __esan_which_tool); Die(); } initializeShadow(); initializeInterceptors(); - if (WhichTool == ESAN_CacheFrag) { + if (__esan_which_tool == ESAN_CacheFrag) { initializeCacheFrag(); - } else if (WhichTool == ESAN_WorkingSet) { + } else if (__esan_which_tool == ESAN_WorkingSet) { initializeWorkingSet(); } @@ -209,9 +207,9 @@ int finalizeLibrary() { VPrintf(1, "in esan::%s\n", __FUNCTION__); - if (WhichTool == ESAN_CacheFrag) { + if (__esan_which_tool == ESAN_CacheFrag) { return finalizeCacheFrag(); - } else if (WhichTool == ESAN_WorkingSet) { + } else if (__esan_which_tool == ESAN_WorkingSet) { return finalizeWorkingSet(); } return 0; @@ -219,7 +217,7 @@ void processCompilationUnitInit(void *Ptr) { VPrintf(2, "in esan::%s\n", __FUNCTION__); - if (WhichTool == ESAN_CacheFrag) { + if (__esan_which_tool == ESAN_CacheFrag) { DCHECK(Ptr != nullptr); processCacheFragCompilationUnitInit(Ptr); } else { @@ -231,7 +229,7 @@ // For the main executable module, this is called after finalizeLibrary. void processCompilationUnitExit(void *Ptr) { VPrintf(2, "in esan::%s\n", __FUNCTION__); - if (WhichTool == ESAN_CacheFrag) { + if (__esan_which_tool == ESAN_CacheFrag) { DCHECK(Ptr != nullptr); processCacheFragCompilationUnitExit(Ptr); } else { Index: compiler-rt/trunk/lib/esan/esan_interface.cpp =================================================================== --- compiler-rt/trunk/lib/esan/esan_interface.cpp +++ compiler-rt/trunk/lib/esan/esan_interface.cpp @@ -18,7 +18,10 @@ using namespace __esan; // NOLINT void __esan_init(ToolType Tool, void *Ptr) { - WhichTool = Tool; + if (Tool != __esan_which_tool) { + Printf("ERROR: tool mismatch: %d vs %d\n", Tool, __esan_which_tool); + Die(); + } initializeLibrary(Tool); processCompilationUnitInit(Ptr); } Index: compiler-rt/trunk/lib/esan/esan_interface_internal.h =================================================================== --- compiler-rt/trunk/lib/esan/esan_interface_internal.h +++ compiler-rt/trunk/lib/esan/esan_interface_internal.h @@ -32,6 +32,11 @@ ESAN_Max, } ToolType; +// To handle interceptors that invoke instrumented code prior to +// __esan_init() being called, the instrumentation module creates this +// global variable specifying the tool. +extern ToolType __esan_which_tool; + // This function should be called at the very beginning of the process, // before any instrumented code is executed and before any call to malloc. SANITIZER_INTERFACE_ATTRIBUTE void __esan_init(ToolType Tool, void *Ptr);