[msan] Handle mixed track-origins and keep-going settings (llvm part).
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Fri, 31 May 2013 12:04:29 +0000 (12:04 +0000)
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Fri, 31 May 2013 12:04:29 +0000 (12:04 +0000)
Before this change, each module defined a weak_odr global __msan_track_origins
with a value of 1 if origin tracking is enabled, 0 if disabled. If there are
modules with different values, any of them may win. If 0 wins, and there is at
least one module with 1, the program will most likely crash.

With this change, __msan_track_origins is only emitted if origin tracking is
on. Then runtime library detects if there is at least one module with origin
tracking, and enables runtime support for it.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@182997 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Instrumentation/MemorySanitizer.cpp
test/Instrumentation/MemorySanitizer/msan_basic.ll

index 58108290d8d0784ce3284c60fd40166f583a53f8..a3a688d7c8d26e39b7c44cfe5a933efca2c06b13 100644 (file)
@@ -366,11 +366,13 @@ bool MemorySanitizer::doInitialization(Module &M) {
   appendToGlobalCtors(M, cast<Function>(M.getOrInsertFunction(
                       "__msan_init", IRB.getVoidTy(), NULL)), 0);
 
-  new GlobalVariable(M, IRB.getInt32Ty(), true, GlobalValue::WeakODRLinkage,
-                     IRB.getInt32(TrackOrigins), "__msan_track_origins");
+  if (TrackOrigins)
+    new GlobalVariable(M, IRB.getInt32Ty(), true, GlobalValue::WeakODRLinkage,
+                       IRB.getInt32(TrackOrigins), "__msan_track_origins");
 
-  new GlobalVariable(M, IRB.getInt32Ty(), true, GlobalValue::WeakODRLinkage,
-                     IRB.getInt32(ClKeepGoing), "__msan_keep_going");
+  if (ClKeepGoing)
+    new GlobalVariable(M, IRB.getInt32Ty(), true, GlobalValue::WeakODRLinkage,
+                       IRB.getInt32(ClKeepGoing), "__msan_keep_going");
 
   return true;
 }
index 433b8bab4ccc79201d1d9faa14c954bb7251ac54..3a8092bdc46bd56e7d1ba6cd17636a5d97c7eca8 100644 (file)
@@ -10,8 +10,9 @@ target triple = "x86_64-unknown-linux-gnu"
 
 ; Check the presence and the linkage type of __msan_track_origins and
 ; other interface symbols.
-; CHECK: @__msan_track_origins = weak_odr constant i32 0
-; CHECK: @__msan_keep_going = weak_odr constant i32 0
+; CHECK-NOT: @__msan_track_origins
+; CHECK-ORIGINS: @__msan_track_origins = weak_odr constant i32 1
+; CHECK-NOT: @__msan_keep_going = weak_odr constant i32 0
 ; CHECK: @__msan_retval_tls = external thread_local(initialexec) global [{{.*}}]
 ; CHECK: @__msan_retval_origin_tls = external thread_local(initialexec) global i32
 ; CHECK: @__msan_param_tls = external thread_local(initialexec) global [{{.*}}]