mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[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 llvm-svn: 351322
This commit is contained in:
parent
78f30ff3a6
commit
fb3cf99af4
@ -321,6 +321,7 @@ static cl::opt<unsigned long long> ClOriginBase("msan-origin-base",
|
||||
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::getKmsanShadowOriginAccessFn(bool isStore, int size) {
|
||||
}
|
||||
|
||||
/// 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(Module &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(Function &Func, MemorySanitizer &Msan,
|
||||
}
|
||||
|
||||
bool MemorySanitizer::sanitizeFunction(Function &F, TargetLibraryInfo &TLI) {
|
||||
if (!CompileKernel && (&F == MsanCtorFunction))
|
||||
return false;
|
||||
MemorySanitizerVisitor Visitor(F, *this, TLI);
|
||||
|
||||
// Clear out readonly/readnone attributes.
|
||||
|
18
test/Instrumentation/MemorySanitizer/global_ctors_2to3.ll
Normal file
18
test/Instrumentation/MemorySanitizer/global_ctors_2to3.ll
Normal file
@ -0,0 +1,18 @@
|
||||
; MSan converts 2-element global_ctors to 3-element when adding the new entry.
|
||||
; RUN: opt < %s -msan-with-comdat -S -passes=msan 2>&1 | FileCheck %s
|
||||
; RUN: opt < %s -msan -msan-with-comdat -S | FileCheck %s
|
||||
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64-unknown-linux-gnu"
|
||||
|
||||
; CHECK: $msan.module_ctor = comdat any
|
||||
; CHECK: @llvm.global_ctors = appending global [2 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @f, i8* null }, { i32, void ()*, i8* } { i32 0, void ()* @msan.module_ctor, i8* bitcast (void ()* @msan.module_ctor to i8*) }]
|
||||
|
||||
@llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 65535, void ()* @f }]
|
||||
|
||||
define internal void @f() {
|
||||
entry:
|
||||
ret void
|
||||
}
|
||||
|
||||
; CHECK: define internal void @msan.module_ctor() comdat {
|
@ -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(i32 %a) sanitize_memory {
|
||||
; CHECK-NEXT: ret i8*
|
||||
|
||||
|
||||
; CHECK: declare void @__msan_init()
|
||||
; CHECK-LABEL: define internal void @msan.module_ctor() {
|
||||
; CHECK: call void @__msan_init()
|
||||
|
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user