aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend.cpp
diff options
context:
space:
mode:
authorJesse Meyer <jesse.r.meyer@me.com>2026-02-02 13:34:36 -0500
committerJesse Meyer <jesse.r.meyer@me.com>2026-02-03 20:16:20 -0500
commit9eba12948a8e0c1b41cb5a63a4c781025ee61def (patch)
treea7b5bf5a343bf473f89102bc19d3f3d238efa17c /src/llvm_backend.cpp
parent43ad4a1d9f18a89822e1b9f554adef1a228136db (diff)
Skip sanitizer IR passes when LTO is enabled
With ThinLTO, the linker runs sanitizer passes at link time via -fsanitize= flags, where it has whole-program visibility. Running them at bitcode emission too double-instruments every module, producing hundreds of "Redundant instrumentation detected" warnings. Per-function sanitize/no_sanitize attributes are preserved in the bitcode and respected by the linker's pass. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Diffstat (limited to 'src/llvm_backend.cpp')
-rw-r--r--src/llvm_backend.cpp23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp
index 43f6f8f03..931813f42 100644
--- a/src/llvm_backend.cpp
+++ b/src/llvm_backend.cpp
@@ -2454,14 +2454,21 @@ gb_internal WORKER_TASK_PROC(lb_llvm_module_pass_worker_proc) {
// tsan - Linux, Darwin
// ubsan - Linux, Darwin, Windows (NOT SUPPORTED WITH LLVM C-API)
- if (build_context.sanitizer_flags & SanitizerFlag_Address) {
- array_add(&passes, "asan");
- }
- if (build_context.sanitizer_flags & SanitizerFlag_Memory) {
- array_add(&passes, "msan");
- }
- if (build_context.sanitizer_flags & SanitizerFlag_Thread) {
- array_add(&passes, "tsan");
+ // With LTO, sanitizer passes run at link time (via -fsanitize= linker flags)
+ // where the linker has whole-program visibility. Running them here too would
+ // double-instrument every module, producing "Redundant instrumentation" warnings.
+ // Per-function sanitize attributes in the bitcode are preserved and respected
+ // by the linker's sanitizer pass.
+ if (build_context.lto_kind == LTO_None) {
+ if (build_context.sanitizer_flags & SanitizerFlag_Address) {
+ array_add(&passes, "asan");
+ }
+ if (build_context.sanitizer_flags & SanitizerFlag_Memory) {
+ array_add(&passes, "msan");
+ }
+ if (build_context.sanitizer_flags & SanitizerFlag_Thread) {
+ array_add(&passes, "tsan");
+ }
}
if (passes.count == 0) {