llvm.org GIT mirror llvm / be9ff87
[esan] Specify which tool via a global variable Summary: Adds a global variable to specify the tool, to support handling early interceptors that invoke instrumented code and require shadow memory to be initialized prior to __esan_init() being invoked. Reviewers: aizatsky Subscribers: vitalybuka, zhaoqin, kcc, eugenis, llvm-commits Differential Revision: http://reviews.llvm.org/D20973 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@271715 91177308-0d34-0410-b5e6-96231b3b80d8 Derek Bruening 4 years ago
1 changed file(s) with 13 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
7070 static const char *const EsanModuleDtorName = "esan.module_dtor";
7171 static const char *const EsanInitName = "__esan_init";
7272 static const char *const EsanExitName = "__esan_exit";
73
74 // We need to specify the tool to the runtime earlier than
75 // the ctor is called in some cases, so we set a global variable.
76 static const char *const EsanWhichToolName = "__esan_which_tool";
7377
7478 // We must keep these Shadow* constants consistent with the esan runtime.
7579 // FIXME: Try to place these shadow constants, the names of the __esan_*
429433 // Create the variable passed to EsanInit and EsanExit.
430434 Constant *ToolInfoArg = createEsanInitToolInfoArg(M);
431435 // Constructor
436 // We specify the tool type both in the EsanWhichToolName global
437 // and as an arg to the init routine as a sanity check.
432438 std::tie(EsanCtorFunction, std::ignore) = createSanitizerCtorAndInitFunctions(
433439 M, EsanModuleCtorName, EsanInitName, /*InitArgTypes=*/{OrdTy, Int8PtrTy},
434440 /*InitArgs=*/{
437443 appendToGlobalCtors(M, EsanCtorFunction, EsanCtorAndDtorPriority);
438444
439445 createDestructor(M, ToolInfoArg);
446
447 new GlobalVariable(M, OrdTy, true,
448 GlobalValue::WeakAnyLinkage,
449 ConstantInt::get(OrdTy,
450 static_cast(Options.ToolType)),
451 EsanWhichToolName);
452
440453 return true;
441454 }
442455