llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-llvm-transforms Author: Vitaly Buka (vitalybuka) <details> <summary>Changes</summary> Place `msan.module_ctor` in a COMDAT section by default when the target supports COMDAT. Without COMDAT deduplication, every translation unit emits its own `msan.module_ctor` function and `.init_array` entry into the linked binary. The old GNU gold bug (PR19002) that kept `-msan-with-comdat` off by default was fixed in binutils 2.26, and ASan and HWASan already place their module constructors in COMDAT by default. Addressing `noundef` mismatches across ABI-compatible boundaries such as Rust/C++ FFI (https://github.com/rust-lang/rust/issues/165040) increases MSan instrumentation size when TLS shadow writes cannot be skipped. This is part of a series of changes to reduce MSan binary size. Assisted-by: Gemini --- Full diff: https://github.com/llvm/llvm-project/pull/238678.diff 4 Files Affected: - (modified) llvm/lib/Transforms/Instrumentation/InstrumentationOptions.td (+1-3) - (modified) llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp (+1-1) - (modified) llvm/test/Instrumentation/MemorySanitizer/comdat_ctor.ll (+2-2) - (modified) llvm/test/Instrumentation/MemorySanitizer/msan-pass-second-run.ll (+1-1) ``````````diff diff --git a/llvm/lib/Transforms/Instrumentation/InstrumentationOptions.td b/llvm/lib/Transforms/Instrumentation/InstrumentationOptions.td index 046d9d2804110..b26a8c1b6ab31 100644 --- a/llvm/lib/Transforms/Instrumentation/InstrumentationOptions.td +++ b/llvm/lib/Transforms/Instrumentation/InstrumentationOptions.td @@ -505,9 +505,7 @@ defm : ValueField<"msan-switch-precision", "int", "99", // or heap) the uninitialized bits came from originally. defm : OptionalValueField<"msan-track-origins", "int", "Track origins (allocation sites) of poisoned memory">; -// This is off by default because of a bug in gold: -// https://sourceware.org/bugzilla/show_bug.cgi?id=19002 -defm : BoolField<"msan-with-comdat", "false", +defm : BoolField<"msan-with-comdat", "true", "Place MSan constructors in comdat sections">; defm : ValueField<"msan-xor-mask", "uint64_t", "0", "Define custom MSan XorMask">; diff --git a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp index 3a7f3722b8afe..f8c51fe4d4110 100644 --- a/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp @@ -580,7 +580,7 @@ void insertModuleCtor(const InstrumentationOptions &Opts, Module &M) { // This callback is invoked when the functions are created the first // time. Hook them into the global ctors list in that case: [&](Function *Ctor, FunctionCallee) { - if (!Opts.msan_with_comdat) { + if (!Opts.msan_with_comdat || !M.getTargetTriple().supportsCOMDAT()) { appendToGlobalCtors(M, Ctor, 0); return; } diff --git a/llvm/test/Instrumentation/MemorySanitizer/comdat_ctor.ll b/llvm/test/Instrumentation/MemorySanitizer/comdat_ctor.ll index 77dffd67cf62a..c838ca73fcea2 100644 --- a/llvm/test/Instrumentation/MemorySanitizer/comdat_ctor.ll +++ b/llvm/test/Instrumentation/MemorySanitizer/comdat_ctor.ll @@ -10,7 +10,7 @@ define void @f() { } ;. ; CHECK: @llvm.used = appending global [1 x ptr] [ptr @msan.module_ctor], section "llvm.metadata" -; CHECK: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 0, ptr @msan.module_ctor, ptr null }] +; CHECK: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 0, ptr @msan.module_ctor, ptr @msan.module_ctor }] ; CHECK: @__msan_retval_tls = external thread_local(initialexec) global [100 x i64] ; CHECK: @__msan_retval_origin_tls = external thread_local(initialexec) global i32 ; CHECK: @__msan_param_tls = external thread_local(initialexec) global [100 x i64] @@ -35,7 +35,7 @@ define void @f() { ; ; ; CHECK-LABEL: define internal void @msan.module_ctor( -; CHECK-SAME: ) #[[ATTR0:[0-9]+]] { +; CHECK-SAME: ) #[[ATTR0:[0-9]+]] comdat { ; CHECK-NEXT: call void @__msan_init() ; CHECK-NEXT: ret void ; diff --git a/llvm/test/Instrumentation/MemorySanitizer/msan-pass-second-run.ll b/llvm/test/Instrumentation/MemorySanitizer/msan-pass-second-run.ll index c4d5927e4a7f4..865e03014a586 100644 --- a/llvm/test/Instrumentation/MemorySanitizer/msan-pass-second-run.ll +++ b/llvm/test/Instrumentation/MemorySanitizer/msan-pass-second-run.ll @@ -7,7 +7,7 @@ target triple = "x86_64-unknown-linux-gnu" ;. ; CHECK: @llvm.used = appending global [1 x ptr] [ptr @msan.module_ctor], section "llvm.metadata" -; CHECK: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 0, ptr @msan.module_ctor, ptr null }] +; CHECK: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 0, ptr @msan.module_ctor, ptr @msan.module_ctor }] ; CHECK: @__msan_retval_tls = external thread_local(initialexec) global [100 x i64] ; CHECK: @__msan_retval_origin_tls = external thread_local(initialexec) global i32 ; CHECK: @__msan_param_tls = external thread_local(initialexec) global [100 x i64] `````````` </details> https://github.com/llvm/llvm-project/pull/238678 _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
