mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-01 05:01:59 +01:00
[asan] Add clang flag -fsanitize-address-use-odr-indicator
Reviewers: eugenis, m.ostapenko, ygribov Subscribers: hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D55157 llvm-svn: 348327
This commit is contained in:
parent
b6cd2e2aef
commit
8943dc47fc
@ -149,7 +149,8 @@ FunctionPass *createAddressSanitizerFunctionPass(bool CompileKernel = false,
|
||||
bool UseAfterScope = false);
|
||||
ModulePass *createAddressSanitizerModulePass(bool CompileKernel = false,
|
||||
bool Recover = false,
|
||||
bool UseGlobalsGC = true);
|
||||
bool UseGlobalsGC = true,
|
||||
bool UseOdrIndicator = true);
|
||||
|
||||
// Insert MemorySanitizer instrumentation (detection of uninitialized reads)
|
||||
FunctionPass *createMemorySanitizerPass(int TrackOrigins = 0,
|
||||
|
@ -735,9 +735,12 @@ public:
|
||||
|
||||
explicit AddressSanitizerModule(bool CompileKernel = false,
|
||||
bool Recover = false,
|
||||
bool UseGlobalsGC = true)
|
||||
: ModulePass(ID),
|
||||
UseGlobalsGC(UseGlobalsGC && ClUseGlobalsGC),
|
||||
bool UseGlobalsGC = true,
|
||||
bool UseOdrIndicator = false)
|
||||
: ModulePass(ID), UseGlobalsGC(UseGlobalsGC && ClUseGlobalsGC),
|
||||
// Enable aliases as they should have no downside with ODR indicators.
|
||||
UsePrivateAlias(UseOdrIndicator || ClUsePrivateAlias),
|
||||
UseOdrIndicator(UseOdrIndicator || ClUseOdrIndicator),
|
||||
// Not a typo: ClWithComdat is almost completely pointless without
|
||||
// ClUseGlobalsGC (because then it only works on modules without
|
||||
// globals, which are rare); it is a prerequisite for ClUseGlobalsGC;
|
||||
@ -746,10 +749,9 @@ public:
|
||||
// ClWithComdat and ClUseGlobalsGC unless the frontend says it's ok to
|
||||
// do globals-gc.
|
||||
UseCtorComdat(UseGlobalsGC && ClWithComdat) {
|
||||
this->Recover = ClRecover.getNumOccurrences() > 0 ?
|
||||
ClRecover : Recover;
|
||||
this->CompileKernel = ClEnableKasan.getNumOccurrences() > 0 ?
|
||||
ClEnableKasan : CompileKernel;
|
||||
this->Recover = ClRecover.getNumOccurrences() > 0 ? ClRecover : Recover;
|
||||
this->CompileKernel =
|
||||
ClEnableKasan.getNumOccurrences() > 0 ? ClEnableKasan : CompileKernel;
|
||||
}
|
||||
|
||||
bool runOnModule(Module &M) override;
|
||||
@ -794,6 +796,8 @@ private:
|
||||
bool CompileKernel;
|
||||
bool Recover;
|
||||
bool UseGlobalsGC;
|
||||
bool UsePrivateAlias;
|
||||
bool UseOdrIndicator;
|
||||
bool UseCtorComdat;
|
||||
Type *IntptrTy;
|
||||
LLVMContext *C;
|
||||
@ -1093,9 +1097,11 @@ INITIALIZE_PASS(
|
||||
|
||||
ModulePass *llvm::createAddressSanitizerModulePass(bool CompileKernel,
|
||||
bool Recover,
|
||||
bool UseGlobalsGC) {
|
||||
bool UseGlobalsGC,
|
||||
bool UseOdrIndicator) {
|
||||
assert(!CompileKernel || Recover);
|
||||
return new AddressSanitizerModule(CompileKernel, Recover, UseGlobalsGC);
|
||||
return new AddressSanitizerModule(CompileKernel, Recover, UseGlobalsGC,
|
||||
UseOdrIndicator);
|
||||
}
|
||||
|
||||
static size_t TypeSizeToSizeIndex(uint32_t TypeSize) {
|
||||
@ -2177,14 +2183,14 @@ bool AddressSanitizerModule::InstrumentGlobals(IRBuilder<> &IRB, Module &M, bool
|
||||
bool CanUsePrivateAliases =
|
||||
TargetTriple.isOSBinFormatELF() || TargetTriple.isOSBinFormatMachO() ||
|
||||
TargetTriple.isOSBinFormatWasm();
|
||||
if (CanUsePrivateAliases && ClUsePrivateAlias) {
|
||||
if (CanUsePrivateAliases && UsePrivateAlias) {
|
||||
// Create local alias for NewGlobal to avoid crash on ODR between
|
||||
// instrumented and non-instrumented libraries.
|
||||
InstrumentedGlobal =
|
||||
GlobalAlias::create(GlobalValue::PrivateLinkage, "", NewGlobal);
|
||||
}
|
||||
|
||||
if (ClUseOdrIndicator) {
|
||||
if (UseOdrIndicator) {
|
||||
// With local aliases, we need to provide another externally visible
|
||||
// symbol __odr_asan_XXX to detect ODR violation.
|
||||
auto *ODRIndicatorSym =
|
||||
|
Loading…
x
Reference in New Issue
Block a user