diff options
Diffstat (limited to 'lib/Transforms/Instrumentation/AddressSanitizer.cpp')
| -rw-r--r-- | lib/Transforms/Instrumentation/AddressSanitizer.cpp | 34 | 
1 files changed, 21 insertions, 13 deletions
| diff --git a/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/lib/Transforms/Instrumentation/AddressSanitizer.cpp index b034ccc469338..7eea44d6aca03 100644 --- a/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -613,7 +613,15 @@ public:                                    bool UseGlobalsGC = true)        : ModulePass(ID), CompileKernel(CompileKernel || ClEnableKasan),          Recover(Recover || ClRecover), -        UseGlobalsGC(UseGlobalsGC && ClUseGlobalsGC) {} +        UseGlobalsGC(UseGlobalsGC && ClUseGlobalsGC), +        // 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; +        // and both suffer from gold PR19002 for which UseGlobalsGC constructor +        // argument is designed as workaround. Therefore, disable both +        // ClWithComdat and ClUseGlobalsGC unless the frontend says it's ok to +        // do globals-gc. +        UseCtorComdat(UseGlobalsGC && ClWithComdat) {}    bool runOnModule(Module &M) override;    static char ID; // Pass identification, replacement for typeid    StringRef getPassName() const override { return "AddressSanitizerModule"; } @@ -656,6 +664,7 @@ private:    bool CompileKernel;    bool Recover;    bool UseGlobalsGC; +  bool UseCtorComdat;    Type *IntptrTy;    LLVMContext *C;    Triple TargetTriple; @@ -1677,7 +1686,7 @@ AddressSanitizerModule::CreateMetadataGlobal(Module &M, Constant *Initializer,                       : GlobalVariable::PrivateLinkage;    GlobalVariable *Metadata = new GlobalVariable(        M, Initializer->getType(), false, Linkage, Initializer, -      Twine("__asan_global_") + GlobalValue::getRealLinkageName(OriginalName)); +      Twine("__asan_global_") + GlobalValue::dropLLVMManglingEscape(OriginalName));    Metadata->setSection(getGlobalMetadataSection());    return Metadata;  } @@ -1782,7 +1791,7 @@ void AddressSanitizerModule::InstrumentGlobalsMachO(    // On recent Mach-O platforms, use a structure which binds the liveness of    // the global variable to the metadata struct. Keep the list of "Liveness" GV    // created to be added to llvm.compiler.used -  StructType *LivenessTy = StructType::get(IntptrTy, IntptrTy, nullptr); +  StructType *LivenessTy = StructType::get(IntptrTy, IntptrTy);    SmallVector<GlobalValue *, 16> LivenessGlobals(ExtendedGlobals.size());    for (size_t i = 0; i < ExtendedGlobals.size(); i++) { @@ -1793,9 +1802,9 @@ void AddressSanitizerModule::InstrumentGlobalsMachO(      // On recent Mach-O platforms, we emit the global metadata in a way that      // allows the linker to properly strip dead globals. -    auto LivenessBinder = ConstantStruct::get( -        LivenessTy, Initializer->getAggregateElement(0u), -        ConstantExpr::getPointerCast(Metadata, IntptrTy), nullptr); +    auto LivenessBinder = +        ConstantStruct::get(LivenessTy, Initializer->getAggregateElement(0u), +                            ConstantExpr::getPointerCast(Metadata, IntptrTy));      GlobalVariable *Liveness = new GlobalVariable(          M, LivenessTy, false, GlobalVariable::InternalLinkage, LivenessBinder,          Twine("__asan_binder_") + G->getName()); @@ -1893,7 +1902,7 @@ bool AddressSanitizerModule::InstrumentGlobals(IRBuilder<> &IRB, Module &M, bool    // We initialize an array of such structures and pass it to a run-time call.    StructType *GlobalStructTy =        StructType::get(IntptrTy, IntptrTy, IntptrTy, IntptrTy, IntptrTy, -                      IntptrTy, IntptrTy, IntptrTy, nullptr); +                      IntptrTy, IntptrTy, IntptrTy);    SmallVector<GlobalVariable *, 16> NewGlobals(n);    SmallVector<Constant *, 16> Initializers(n); @@ -1929,10 +1938,9 @@ bool AddressSanitizerModule::InstrumentGlobals(IRBuilder<> &IRB, Module &M, bool      assert(((RightRedzoneSize + SizeInBytes) % MinRZ) == 0);      Type *RightRedZoneTy = ArrayType::get(IRB.getInt8Ty(), RightRedzoneSize); -    StructType *NewTy = StructType::get(Ty, RightRedZoneTy, nullptr); -    Constant *NewInitializer = -        ConstantStruct::get(NewTy, G->getInitializer(), -                            Constant::getNullValue(RightRedZoneTy), nullptr); +    StructType *NewTy = StructType::get(Ty, RightRedZoneTy); +    Constant *NewInitializer = ConstantStruct::get( +        NewTy, G->getInitializer(), Constant::getNullValue(RightRedZoneTy));      // Create a new global variable with enough space for a redzone.      GlobalValue::LinkageTypes Linkage = G->getLinkage(); @@ -2013,7 +2021,7 @@ bool AddressSanitizerModule::InstrumentGlobals(IRBuilder<> &IRB, Module &M, bool          ConstantExpr::getPointerCast(Name, IntptrTy),          ConstantExpr::getPointerCast(ModuleName, IntptrTy),          ConstantInt::get(IntptrTy, MD.IsDynInit), SourceLoc, -        ConstantExpr::getPointerCast(ODRIndicator, IntptrTy), nullptr); +        ConstantExpr::getPointerCast(ODRIndicator, IntptrTy));      if (ClInitializers && MD.IsDynInit) HasDynamicallyInitializedGlobals = true; @@ -2073,7 +2081,7 @@ bool AddressSanitizerModule::runOnModule(Module &M) {    // Put the constructor and destructor in comdat if both    // (1) global instrumentation is not TU-specific    // (2) target is ELF. -  if (ClWithComdat && TargetTriple.isOSBinFormatELF() && CtorComdat) { +  if (UseCtorComdat && TargetTriple.isOSBinFormatELF() && CtorComdat) {      AsanCtorFunction->setComdat(M.getOrInsertComdat(kAsanModuleCtorName));      appendToGlobalCtors(M, AsanCtorFunction, kAsanCtorAndDtorPriority,                          AsanCtorFunction); | 
