Index: lib/esan/esan.h =================================================================== --- lib/esan/esan.h +++ lib/esan/esan.h @@ -37,6 +37,10 @@ void initializeLibrary(ToolType Tool); int finalizeLibrary(); +// Esan creates the variable per tool per compilation unit at compile time +// and passes its pointer Ptr to the runtime library. +void processCompilationUnitInit(void *Ptr); +void processCompilationUnitExit(void *Ptr); void processRangeAccess(uptr PC, uptr Addr, int Size, bool IsWrite); void initializeInterceptors(); Index: lib/esan/esan.cpp =================================================================== --- lib/esan/esan.cpp +++ lib/esan/esan.cpp @@ -177,4 +177,14 @@ return 0; } +void processCompilationUnitInit(void *Ptr) { + VPrintf(2, "in esan::%s\n", __FUNCTION__); +} + +// This is called when the containing module is unloaded. +// For the main executable module, this is called after finalizeLibrary. +void processCompilationUnitExit(void *Ptr) { + VPrintf(2, "in esan::%s\n", __FUNCTION__); +} + } // namespace __esan Index: lib/esan/esan.syms.extra =================================================================== --- lib/esan/esan.syms.extra +++ lib/esan/esan.syms.extra @@ -1,3 +1,4 @@ __esan_init +__esan_exit __esan_aligned* __esan_unaligned* Index: lib/esan/esan_interface.cpp =================================================================== --- lib/esan/esan_interface.cpp +++ lib/esan/esan_interface.cpp @@ -17,8 +17,14 @@ using namespace __esan; // NOLINT -void __esan_init(ToolType Tool) { +void __esan_init(ToolType Tool, void *Ptr) { + WhichTool = Tool; initializeLibrary(Tool); + processCompilationUnitInit(Ptr); +} + +void __esan_exit(void *Ptr) { + processCompilationUnitExit(Ptr); } void __esan_aligned_load1(void *Addr) { Index: lib/esan/esan_interface_internal.h =================================================================== --- lib/esan/esan_interface_internal.h +++ lib/esan/esan_interface_internal.h @@ -32,7 +32,8 @@ // 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); +SANITIZER_INTERFACE_ATTRIBUTE void __esan_init(ToolType Tool, void *Ptr); +SANITIZER_INTERFACE_ATTRIBUTE void __esan_exit(void *Ptr); // The instrumentation module will insert a call to one of these routines prior // to each load and store instruction for which we do not have "fastpath" Index: test/esan/TestCases/struct-simple.cpp =================================================================== --- /dev/null +++ test/esan/TestCases/struct-simple.cpp @@ -0,0 +1,38 @@ +// RUN: %clang_esan_frag -O0 %s -DPART -c -o %t-part.o 2>&1 +// RUN: %clang_esan_frag -O0 %s -DMAIN -c -o %t-main.o 2>&1 +// RUN: %clang_esan_frag -O0 %t-part.o %t-main.o -o %t 2>&1 +// RUN: %env_esan_opts=verbosity=2 %run %t 2>&1 | FileCheck %s + +// We generate two different object files from this file with different +// macros, and then link them together. We do this to test how we handle +// separate compilation with multiple compilation units. + +#include + +extern "C" { + void part(); +} + +//===-- compilation unit without main function ----------------------------===// + +#ifdef PART +void part() +{ +} +#endif // PART + +//===-- compilation unit with main function -------------------------------===// + +#ifdef MAIN +int main(int argc, char **argv) { + // CHECK: in esan::initializeLibrary + // CHECK: in esan::processCompilationUnitInit + // CHECK: in esan::processCompilationUnitInit + part(); + return 0; + // CHECK-NEXT: in esan::finalizeLibrary + // CHECK-NEXT: {{.*}}EfficiencySanitizer is not finished: nothing yet to report + // CHECK: in esan::processCompilationUnitExit + // CHECK: in esan::processCompilationUnitExit +} +#endif // MAIN