[llvm] r298889 - Revert "[asan] Put ctor/dtor in comdat."

Alex Shlyapnikov via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 27 16:11:47 PDT 2017


Author: alekseyshl
Date: Mon Mar 27 18:11:47 2017
New Revision: 298889

URL: http://llvm.org/viewvc/llvm-project?rev=298889&view=rev
Log:
Revert "[asan] Put ctor/dtor in comdat."

Speculative revert, some libfuzzer tests are affected.

This reverts commit r298756.

Removed:
    llvm/trunk/test/Instrumentation/AddressSanitizer/no-globals.ll
Modified:
    llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
    llvm/trunk/test/Instrumentation/AddressSanitizer/instrument_global.ll

Modified: llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp?rev=298889&r1=298888&r2=298889&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/AddressSanitizer.cpp Mon Mar 27 18:11:47 2017
@@ -606,7 +606,7 @@ class AddressSanitizerModule : public Mo
 private:
   void initializeCallbacks(Module &M);
 
-  bool InstrumentGlobals(IRBuilder<> &IRB, Module &M, bool *CtorComdat);
+  bool InstrumentGlobals(IRBuilder<> &IRB, Module &M);
   void InstrumentGlobalsCOFF(IRBuilder<> &IRB, Module &M,
                              ArrayRef<GlobalVariable *> ExtendedGlobals,
                              ArrayRef<Constant *> MetadataInitializers);
@@ -645,9 +645,6 @@ private:
   Function *AsanUnregisterGlobals;
   Function *AsanRegisterImageGlobals;
   Function *AsanUnregisterImageGlobals;
-
-  Function *AsanCtorFunction = nullptr;
-  Function *AsanDtorFunction = nullptr;
 };
 
 // Stack poisoning does not play well with exception handling.
@@ -1431,13 +1428,8 @@ void AddressSanitizerModule::poisonOneIn
 void AddressSanitizerModule::createInitializerPoisonCalls(
     Module &M, GlobalValue *ModuleName) {
   GlobalVariable *GV = M.getGlobalVariable("llvm.global_ctors");
-  if (!GV)
-    return;
-
-  ConstantArray *CA = dyn_cast<ConstantArray>(GV->getInitializer());
-  if (!CA)
-    return;
 
+  ConstantArray *CA = cast<ConstantArray>(GV->getInitializer());
   for (Use &OP : CA->operands()) {
     if (isa<ConstantAggregateZero>(OP)) continue;
     ConstantStruct *CS = cast<ConstantStruct>(OP);
@@ -1643,10 +1635,11 @@ AddressSanitizerModule::CreateMetadataGl
 }
 
 IRBuilder<> AddressSanitizerModule::CreateAsanModuleDtor(Module &M) {
-  AsanDtorFunction =
+  Function *AsanDtorFunction =
       Function::Create(FunctionType::get(Type::getVoidTy(*C), false),
                        GlobalValue::InternalLinkage, kAsanModuleDtorName, &M);
   BasicBlock *AsanDtorBB = BasicBlock::Create(*C, "", AsanDtorFunction);
+  appendToGlobalDtors(M, AsanDtorFunction, kAsanCtorAndDtorPriority);
 
   return IRBuilder<>(ReturnInst::Create(*C, AsanDtorBB));
 }
@@ -1762,10 +1755,7 @@ void AddressSanitizerModule::InstrumentG
 // This function replaces all global variables with new variables that have
 // trailing redzones. It also creates a function that poisons
 // redzones and inserts this function into llvm.global_ctors.
-// Sets *CtorComdat to true if the global registration code emitted into the
-// asan constructor is comdat-compatible.
-bool AddressSanitizerModule::InstrumentGlobals(IRBuilder<> &IRB, Module &M, bool *CtorComdat) {
-  *CtorComdat = false;
+bool AddressSanitizerModule::InstrumentGlobals(IRBuilder<> &IRB, Module &M) {
   GlobalsMD.init(M);
 
   SmallVector<GlobalVariable *, 16> GlobalsToChange;
@@ -1775,10 +1765,7 @@ bool AddressSanitizerModule::InstrumentG
   }
 
   size_t n = GlobalsToChange.size();
-  if (n == 0) {
-    *CtorComdat = true;
-    return false;
-  }
+  if (n == 0) return false;
 
   auto &DL = M.getDataLayout();
 
@@ -1950,36 +1937,17 @@ bool AddressSanitizerModule::runOnModule
   if (CompileKernel)
     return false;
 
-  // Create a module constructor. A destructor is created lazily because not all
-  // platforms, and not all modules need it.
+  Function *AsanCtorFunction;
   std::tie(AsanCtorFunction, std::ignore) = createSanitizerCtorAndInitFunctions(
       M, kAsanModuleCtorName, kAsanInitName, /*InitArgTypes=*/{},
       /*InitArgs=*/{}, kAsanVersionCheckName);
+  appendToGlobalCtors(M, AsanCtorFunction, kAsanCtorAndDtorPriority);
 
-  bool CtorComdat = true;
   bool Changed = false;
   // TODO(glider): temporarily disabled globals instrumentation for KASan.
   if (ClGlobals) {
     IRBuilder<> IRB(AsanCtorFunction->getEntryBlock().getTerminator());
-    Changed |= InstrumentGlobals(IRB, M, &CtorComdat);
-  }
-
-  // Put the constructor and destructor in comdat if both
-  // (1) global instrumentation is not TU-specific
-  // (2) target is ELF.
-  if (TargetTriple.isOSBinFormatELF() && CtorComdat) {
-    AsanCtorFunction->setComdat(M.getOrInsertComdat(kAsanModuleCtorName));
-    appendToGlobalCtors(M, AsanCtorFunction, kAsanCtorAndDtorPriority,
-                        AsanCtorFunction);
-    if (AsanDtorFunction) {
-      AsanDtorFunction->setComdat(M.getOrInsertComdat(kAsanModuleDtorName));
-      appendToGlobalDtors(M, AsanDtorFunction, kAsanCtorAndDtorPriority,
-                          AsanDtorFunction);
-    }
-  } else {
-    appendToGlobalCtors(M, AsanCtorFunction, kAsanCtorAndDtorPriority);
-    if (AsanDtorFunction)
-      appendToGlobalDtors(M, AsanDtorFunction, kAsanCtorAndDtorPriority);
+    Changed |= InstrumentGlobals(IRB, M);
   }
 
   return Changed;

Modified: llvm/trunk/test/Instrumentation/AddressSanitizer/instrument_global.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/AddressSanitizer/instrument_global.ll?rev=298889&r1=298888&r2=298889&view=diff
==============================================================================
--- llvm/trunk/test/Instrumentation/AddressSanitizer/instrument_global.ll (original)
+++ llvm/trunk/test/Instrumentation/AddressSanitizer/instrument_global.ll Mon Mar 27 18:11:47 2017
@@ -6,8 +6,8 @@ target triple = "x86_64-unknown-linux-gn
 ; If a global is present, __asan_[un]register_globals should be called from
 ; module ctor/dtor
 
-; CHECK: @__asan_gen_ = private constant [8 x i8] c"<stdin>\00", align 1
 ; CHECK: llvm.global_ctors
+; CHECK: @__asan_gen_ = private constant [8 x i8] c"<stdin>\00", align 1
 ; CHECK: llvm.global_dtors
 
 ; Test that we don't instrument global arrays with static initializer

Removed: llvm/trunk/test/Instrumentation/AddressSanitizer/no-globals.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Instrumentation/AddressSanitizer/no-globals.ll?rev=298888&view=auto
==============================================================================
--- llvm/trunk/test/Instrumentation/AddressSanitizer/no-globals.ll (original)
+++ llvm/trunk/test/Instrumentation/AddressSanitizer/no-globals.ll (removed)
@@ -1,12 +0,0 @@
-; A module with no asan-instrumented globals has no asan destructor, and has an asan constructor in a comdat.
-; RUN: opt -mtriple=x86_64-unknown-linux-gnu < %s -asan -asan-module -S | FileCheck %s
-
-define void @f() {
-  ret void
-}
-
-; CHECK-NOT: @llvm.global_dtors
-; CHECK: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 1, void ()* @asan.module_ctor, i8* bitcast (void ()* @asan.module_ctor to i8*) }]
-; CHECK-NOT: @llvm.global_dtors
-; CHECK: define internal void @asan.module_ctor() comdat
-; CHECK-NOT: @llvm.global_dtors




More information about the llvm-commits mailing list