llvm.org GIT mirror llvm / 3c1e414
Revert "[asan] Put ctor/dtor in comdat." Speculative revert, some libfuzzer tests are affected. This reverts commit r298756. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298889 91177308-0d34-0410-b5e6-96231b3b80d8 Alex Shlyapnikov 3 years ago
3 changed file(s) with 12 addition(s) and 56 deletion(s). Raw diff Collapse all Expand all
605605 private:
606606 void initializeCallbacks(Module &M);
607607
608 bool InstrumentGlobals(IRBuilder<> &IRB, Module &M, bool *CtorComdat);
608 bool InstrumentGlobals(IRBuilder<> &IRB, Module &M);
609609 void InstrumentGlobalsCOFF(IRBuilder<> &IRB, Module &M,
610610 ArrayRef ExtendedGlobals,
611611 ArrayRef MetadataInitializers);
644644 Function *AsanUnregisterGlobals;
645645 Function *AsanRegisterImageGlobals;
646646 Function *AsanUnregisterImageGlobals;
647
648 Function *AsanCtorFunction = nullptr;
649 Function *AsanDtorFunction = nullptr;
650647 };
651648
652649 // Stack poisoning does not play well with exception handling.
14301427 void AddressSanitizerModule::createInitializerPoisonCalls(
14311428 Module &M, GlobalValue *ModuleName) {
14321429 GlobalVariable *GV = M.getGlobalVariable("llvm.global_ctors");
1433 if (!GV)
1434 return;
1435
1436 ConstantArray *CA = dyn_cast(GV->getInitializer());
1437 if (!CA)
1438 return;
1439
1430
1431 ConstantArray *CA = cast(GV->getInitializer());
14401432 for (Use &OP : CA->operands()) {
14411433 if (isa(OP)) continue;
14421434 ConstantStruct *CS = cast(OP);
16421634 }
16431635
16441636 IRBuilder<> AddressSanitizerModule::CreateAsanModuleDtor(Module &M) {
1645 AsanDtorFunction =
1637 Function *AsanDtorFunction =
16461638 Function::Create(FunctionType::get(Type::getVoidTy(*C), false),
16471639 GlobalValue::InternalLinkage, kAsanModuleDtorName, &M);
16481640 BasicBlock *AsanDtorBB = BasicBlock::Create(*C, "", AsanDtorFunction);
1641 appendToGlobalDtors(M, AsanDtorFunction, kAsanCtorAndDtorPriority);
16491642
16501643 return IRBuilder<>(ReturnInst::Create(*C, AsanDtorBB));
16511644 }
17611754 // This function replaces all global variables with new variables that have
17621755 // trailing redzones. It also creates a function that poisons
17631756 // redzones and inserts this function into llvm.global_ctors.
1764 // Sets *CtorComdat to true if the global registration code emitted into the
1765 // asan constructor is comdat-compatible.
1766 bool AddressSanitizerModule::InstrumentGlobals(IRBuilder<> &IRB, Module &M, bool *CtorComdat) {
1767 *CtorComdat = false;
1757 bool AddressSanitizerModule::InstrumentGlobals(IRBuilder<> &IRB, Module &M) {
17681758 GlobalsMD.init(M);
17691759
17701760 SmallVector GlobalsToChange;
17741764 }
17751765
17761766 size_t n = GlobalsToChange.size();
1777 if (n == 0) {
1778 *CtorComdat = true;
1779 return false;
1780 }
1767 if (n == 0) return false;
17811768
17821769 auto &DL = M.getDataLayout();
17831770
19491936 if (CompileKernel)
19501937 return false;
19511938
1952 // Create a module constructor. A destructor is created lazily because not all
1953 // platforms, and not all modules need it.
1939 Function *AsanCtorFunction;
19541940 std::tie(AsanCtorFunction, std::ignore) = createSanitizerCtorAndInitFunctions(
19551941 M, kAsanModuleCtorName, kAsanInitName, /*InitArgTypes=*/{},
19561942 /*InitArgs=*/{}, kAsanVersionCheckName);
1957
1958 bool CtorComdat = true;
1943 appendToGlobalCtors(M, AsanCtorFunction, kAsanCtorAndDtorPriority);
1944
19591945 bool Changed = false;
19601946 // TODO(glider): temporarily disabled globals instrumentation for KASan.
19611947 if (ClGlobals) {
19621948 IRBuilder<> IRB(AsanCtorFunction->getEntryBlock().getTerminator());
1963 Changed |= InstrumentGlobals(IRB, M, &CtorComdat);
1964 }
1965
1966 // Put the constructor and destructor in comdat if both
1967 // (1) global instrumentation is not TU-specific
1968 // (2) target is ELF.
1969 if (TargetTriple.isOSBinFormatELF() && CtorComdat) {
1970 AsanCtorFunction->setComdat(M.getOrInsertComdat(kAsanModuleCtorName));
1971 appendToGlobalCtors(M, AsanCtorFunction, kAsanCtorAndDtorPriority,
1972 AsanCtorFunction);
1973 if (AsanDtorFunction) {
1974 AsanDtorFunction->setComdat(M.getOrInsertComdat(kAsanModuleDtorName));
1975 appendToGlobalDtors(M, AsanDtorFunction, kAsanCtorAndDtorPriority,
1976 AsanDtorFunction);
1977 }
1978 } else {
1979 appendToGlobalCtors(M, AsanCtorFunction, kAsanCtorAndDtorPriority);
1980 if (AsanDtorFunction)
1981 appendToGlobalDtors(M, AsanDtorFunction, kAsanCtorAndDtorPriority);
1949 Changed |= InstrumentGlobals(IRB, M);
19821950 }
19831951
19841952 return Changed;
55 ; If a global is present, __asan_[un]register_globals should be called from
66 ; module ctor/dtor
77
8 ; CHECK: llvm.global_ctors
89 ; CHECK: @__asan_gen_ = private constant [8 x i8] c"\00", align 1
9 ; CHECK: llvm.global_ctors
1010 ; CHECK: llvm.global_dtors
1111
1212 ; Test that we don't instrument global arrays with static initializer
+0
-12
test/Instrumentation/AddressSanitizer/no-globals.ll less more
None ; A module with no asan-instrumented globals has no asan destructor, and has an asan constructor in a comdat.
1 ; RUN: opt -mtriple=x86_64-unknown-linux-gnu < %s -asan -asan-module -S | FileCheck %s
2
3 define void @f() {
4 ret void
5 }
6
7 ; CHECK-NOT: @llvm.global_dtors
8 ; 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*) }]
9 ; CHECK-NOT: @llvm.global_dtors
10 ; CHECK: define internal void @asan.module_ctor() comdat
11 ; CHECK-NOT: @llvm.global_dtors