[PATCH] ASan: Use `createSanitizerCtor` to create ctor, and call `__asan_init`

Ismail Pazarbasi ismail.pazarbasi at gmail.com
Wed May 6 15:12:04 PDT 2015


Updated after changes in http://reviews.llvm.org/D8777;

- `createSanitizerCtor` renamed to `createSanitizerCtorAndInitFunctions` to match with changes in http://reviews.llvm.org/D8777
- Added simple check to ensure ASan's ctor is added to module ctors, and `__asan_init_v5` is called from ctor


http://reviews.llvm.org/D8778

Files:
  lib/Transforms/Instrumentation/AddressSanitizer.cpp
  test/Instrumentation/AddressSanitizer/basic.ll

Index: lib/Transforms/Instrumentation/AddressSanitizer.cpp
===================================================================
--- lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -1452,16 +1452,10 @@
   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);
 
Index: test/Instrumentation/AddressSanitizer/basic.ll
===================================================================
--- test/Instrumentation/AddressSanitizer/basic.ll
+++ 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 @@
 ; 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}

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8778.25094.patch
Type: text/x-patch
Size: 2054 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150506/ea7d138c/attachment.bin>


More information about the llvm-commits mailing list