[llvm-branch-commits] [llvm-branch] r353830 - Merging r351322:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Feb 12 03:17:08 PST 2019


Author: hans
Date: Tue Feb 12 03:17:08 2019
New Revision: 353830

URL: http://llvm.org/viewvc/llvm-project?rev=353830&view=rev
Log:
Merging r351322:
------------------------------------------------------------------------
r351322 | pfaffe | 2019-01-16 12:14:07 +0100 (Wed, 16 Jan 2019) | 9 lines

[MSan] Apply the ctor creation scheme of TSan

Summary: To avoid adding an extern function to the global ctors list, apply the changes of D56538 also to MSan.

Reviewers: chandlerc, vitalybuka, fedor.sergeev, leonardchan

Subscribers: hiraditya, bollu, llvm-commits

Differential Revision: https://reviews.llvm.org/D56734
------------------------------------------------------------------------

Added:
    llvm/branches/release_80/test/Instrumentation/MemorySanitizer/global_ctors_2to3.ll
      - copied unchanged from r351322, llvm/trunk/test/Instrumentation/MemorySanitizer/global_ctors_2to3.ll
Modified:
    llvm/branches/release_80/   (props changed)
    llvm/branches/release_80/lib/Transforms/Instrumentation/MemorySanitizer.cpp
    llvm/branches/release_80/test/Instrumentation/MemorySanitizer/msan_basic.ll
    llvm/branches/release_80/test/Instrumentation/MemorySanitizer/msan_llvm_is_constant.ll

Propchange: llvm/branches/release_80/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Feb 12 03:17:08 2019
@@ -1,3 +1,3 @@
 /llvm/branches/Apple/Pertwee:110850,110961
 /llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,351325,351344-351345,351349,351351,351370,351381,351387,351421,351426,351436,351475,351485,351753-351754,351765,351910,351930,351932,352034,352204,352246,352374,352555,352607-352608,352770,352889,352945,353015,353061,353082,353138,353141,353155,353218,353304,353308,353334,353367,353374,353383,353463,353480,353489,353551,353809
+/llvm/trunk:155241,351322,351325,351344-351345,351349,351351,351370,351381,351387,351421,351426,351436,351475,351485,351753-351754,351765,351910,351930,351932,352034,352204,352246,352374,352555,352607-352608,352770,352889,352945,353015,353061,353082,353138,353141,353155,353218,353304,353308,353334,353367,353374,353383,353463,353480,353489,353551,353809

Modified: llvm/branches/release_80/lib/Transforms/Instrumentation/MemorySanitizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_80/lib/Transforms/Instrumentation/MemorySanitizer.cpp?rev=353830&r1=353829&r2=353830&view=diff
==============================================================================
--- llvm/branches/release_80/lib/Transforms/Instrumentation/MemorySanitizer.cpp (original)
+++ llvm/branches/release_80/lib/Transforms/Instrumentation/MemorySanitizer.cpp Tue Feb 12 03:17:08 2019
@@ -321,6 +321,7 @@ static cl::opt<unsigned long long> ClOri
        cl::desc("Define custom MSan OriginBase"),
        cl::Hidden, cl::init(0));
 
+static const char *const kMsanModuleCtorName = "msan.module_ctor";
 static const char *const kMsanInitName = "__msan_init";
 
 namespace {
@@ -586,6 +587,8 @@ private:
 
   /// An empty volatile inline asm that prevents callback merge.
   InlineAsm *EmptyAsm;
+
+  Function *MsanCtorFunction;
 };
 
 /// A legacy function pass for msan instrumentation.
@@ -839,6 +842,8 @@ Value *MemorySanitizer::getKmsanShadowOr
 }
 
 /// Module-level initialization.
+///
+/// inserts a call to __msan_init to the module's constructor list.
 void MemorySanitizer::initializeModule(Module &M) {
   auto &DL = M.getDataLayout();
 
@@ -913,7 +918,22 @@ void MemorySanitizer::initializeModule(M
   OriginStoreWeights = MDBuilder(*C).createBranchWeights(1, 1000);
 
   if (!CompileKernel) {
-    getOrCreateInitFunction(M, kMsanInitName);
+    std::tie(MsanCtorFunction, std::ignore) =
+        getOrCreateSanitizerCtorAndInitFunctions(
+            M, kMsanModuleCtorName, kMsanInitName,
+            /*InitArgTypes=*/{},
+            /*InitArgs=*/{},
+            // This callback is invoked when the functions are created the first
+            // time. Hook them into the global ctors list in that case:
+            [&](Function *Ctor, Function *) {
+              if (!ClWithComdat) {
+                appendToGlobalCtors(M, Ctor, 0);
+                return;
+              }
+              Comdat *MsanCtorComdat = M.getOrInsertComdat(kMsanModuleCtorName);
+              Ctor->setComdat(MsanCtorComdat);
+              appendToGlobalCtors(M, Ctor, 0, Ctor);
+            });
 
     if (TrackOrigins)
       M.getOrInsertGlobal("__msan_track_origins", IRB.getInt32Ty(), [&] {
@@ -4458,6 +4478,8 @@ static VarArgHelper *CreateVarArgHelper(
 }
 
 bool MemorySanitizer::sanitizeFunction(Function &F, TargetLibraryInfo &TLI) {
+  if (!CompileKernel && (&F == MsanCtorFunction))
+    return false;
   MemorySanitizerVisitor Visitor(F, *this, TLI);
 
   // Clear out readonly/readnone attributes.

Modified: llvm/branches/release_80/test/Instrumentation/MemorySanitizer/msan_basic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_80/test/Instrumentation/MemorySanitizer/msan_basic.ll?rev=353830&r1=353829&r2=353830&view=diff
==============================================================================
--- llvm/branches/release_80/test/Instrumentation/MemorySanitizer/msan_basic.ll (original)
+++ llvm/branches/release_80/test/Instrumentation/MemorySanitizer/msan_basic.ll Tue Feb 12 03:17:08 2019
@@ -9,7 +9,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-S128"
 target triple = "x86_64-unknown-linux-gnu"
 
-; CHECK: @llvm.global_ctors {{.*}} { i32 0, void ()* @__msan_init, i8* null }
+; CHECK: @llvm.global_ctors {{.*}} { i32 0, void ()* @msan.module_ctor, i8* null }
 
 ; Check the presence and the linkage type of __msan_track_origins and
 ; other interface symbols.
@@ -991,4 +991,5 @@ define i8* @MismatchingCallMustTailCall(
 ; CHECK-NEXT: ret i8*
 
 
-; CHECK: declare void @__msan_init()
+; CHECK-LABEL: define internal void @msan.module_ctor() {
+; CHECK: call void @__msan_init()

Modified: llvm/branches/release_80/test/Instrumentation/MemorySanitizer/msan_llvm_is_constant.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_80/test/Instrumentation/MemorySanitizer/msan_llvm_is_constant.ll?rev=353830&r1=353829&r2=353830&view=diff
==============================================================================
--- llvm/branches/release_80/test/Instrumentation/MemorySanitizer/msan_llvm_is_constant.ll (original)
+++ llvm/branches/release_80/test/Instrumentation/MemorySanitizer/msan_llvm_is_constant.ll Tue Feb 12 03:17:08 2019
@@ -1,6 +1,9 @@
 ; Make sure MSan doesn't insert shadow checks for @llvm.is.constant.* arguments.
 
+; RUN: opt < %s -msan-kernel=1 -S -passes=msan 2>&1 | FileCheck                \
+; RUN: -check-prefixes=CHECK %s
 ; RUN: opt < %s -msan -msan-kernel=1 -S | FileCheck -check-prefixes=CHECK %s
+; RUN: opt < %s -S -passes=msan 2>&1 | FileCheck -check-prefixes=CHECK %s
 ; RUN: opt < %s -msan -S | FileCheck -check-prefixes=CHECK %s
 
 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"




More information about the llvm-branch-commits mailing list