From 914ef58002574b4ddeec9c105b406b3ba3ade5dc Mon Sep 17 00:00:00 2001 From: Ismail Pazarbasi Date: Thu, 7 May 2015 21:40:46 +0000 Subject: [PATCH] ASan: Use `createSanitizerCtor` to create ctor, and call `__asan_init` Reviewers: kcc, samsonov Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D8778 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@236777 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../Instrumentation/AddressSanitizer.cpp | 14 ++++---------- test/Instrumentation/AddressSanitizer/basic.ll | 4 ++++ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/lib/Transforms/Instrumentation/AddressSanitizer.cpp index 1f2f30b9c96..e368a95e3ec 100644 --- a/lib/Transforms/Instrumentation/AddressSanitizer.cpp +++ b/lib/Transforms/Instrumentation/AddressSanitizer.cpp @@ -1452,16 +1452,10 @@ bool AddressSanitizer::doInitialization(Module &M) { IntptrTy = Type::getIntNTy(*C, LongSize); TargetTriple = Triple(M.getTargetTriple()); - AsanCtorFunction = - Function::Create(FunctionType::get(Type::getVoidTy(*C), false), - GlobalValue::InternalLinkage, kAsanModuleCtorName, &M); - BasicBlock *AsanCtorBB = BasicBlock::Create(*C, "", AsanCtorFunction); - // call __asan_init in the module ctor. - IRBuilder<> IRB(ReturnInst::Create(*C, AsanCtorBB)); - AsanInitFunction = checkSanitizerInterfaceFunction( - M.getOrInsertFunction(kAsanInitName, IRB.getVoidTy(), nullptr)); - AsanInitFunction->setLinkage(Function::ExternalLinkage); - IRB.CreateCall(AsanInitFunction); + std::tie(AsanCtorFunction, AsanInitFunction) = + createSanitizerCtorAndInitFunctions(M, kAsanModuleCtorName, kAsanInitName, + /*InitArgTypes=*/{}, + /*InitArgs=*/{}); Mapping = getShadowMapping(TargetTriple, LongSize); diff --git a/test/Instrumentation/AddressSanitizer/basic.ll b/test/Instrumentation/AddressSanitizer/basic.ll index 21153aeaa64..2490510fc76 100644 --- a/test/Instrumentation/AddressSanitizer/basic.ll +++ b/test/Instrumentation/AddressSanitizer/basic.ll @@ -4,6 +4,7 @@ target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64" target triple = "x86_64-unknown-linux-gnu" +; CHECK: @llvm.global_ctors = {{.*}}@asan.module_ctor define i32 @test_load(i32* %a) sanitize_address { ; CHECK-LABEL: @test_load @@ -169,5 +170,8 @@ define void @memintr_test(i8* %a, i8* %b) nounwind uwtable sanitize_address { ; CHECK: __asan_memcpy ; CHECK: ret void +; CHECK: define internal void @asan.module_ctor() +; CHECK: call void @__asan_init_v5() + ; PROF ; CHECK: ![[PROF]] = !{!"branch_weights", i32 1, i32 100000} -- 2.34.1