Skip to content

Commit 73b5842

Browse files
committed
Mark ___asan_globals_registered as an exported symbol for LTO
Fixes #113404
1 parent 6e8acbd commit 73b5842

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

compiler/rustc_codegen_ssa/src/back/symbol_export.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ fn exported_symbols_provider_local(
265265
externally_injected_weak_symbols.push("__msan_track_origins");
266266
}
267267
}
268+
if tcx.sess.opts.unstable_opts.sanitizer.contains(SanitizerSet::ADDRESS) {
269+
// Similar to profiling, preserve weak asan symbols during LTO.
270+
externally_injected_weak_symbols.push("___asan_globals_registered");
271+
}
268272
symbols.extend(externally_injected_weak_symbols.into_iter().map(|sym| {
269273
let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, sym));
270274
(
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Verifies that AddressSanitizer symbols show up as expected in LLVM IR
2+
// with -Zsanitizer (DO NOT SUBMIT: add ASAN (no LTO) and ASAN-LTO2 (lto=fat) tests).
3+
//
4+
// Notes about the `compile-flags` below:
5+
//
6+
// * The original issue only reproed with LTO - this is why this angle has
7+
// extra test coverage via different `revisions`
8+
// * To observe the failure/repro at LLVM-IR level we need to use `staticlib`
9+
// which necessitates `-C prefer-dynamic=false` - without the latter flag,
10+
// we would have run into "cannot prefer dynamic linking when performing LTO".
11+
//
12+
// needs-sanitizer-address
13+
//
14+
// revisions:ASAN ASAN-LTO
15+
//[ASAN] compile-flags: -Zsanitizer=address
16+
//[ASAN-LTO] compile-flags: -Zsanitizer=address -C prefer-dynamic=false -C lto
17+
18+
#![crate_type="staticlib"]
19+
20+
// The test below mimics `CACHED_POW10` from `library/core/src/num/flt2dec/strategy/grisu.rs` which
21+
// (because of incorrect handling of `___asan_globals_registered` during LTO) was incorrectly
22+
// reported as an ODR violation in https://crbug.com/1459233#c1. Before this bug was fixed,
23+
// `___asan_globals_registered` would show up as `internal global i64`.
24+
//
25+
// See https://github.com/rust-lang/rust/issues/113404 for more discussion.
26+
//
27+
// CHECK: @___asan_globals_registered = common hidden global i64 0
28+
// CHECK: @__start_asan_globals = extern_weak hidden global i64
29+
// CHECK: @__stop_asan_globals = extern_weak hidden global i64
30+
#[no_mangle]
31+
pub static CACHED_POW10: [(u64, i16, i16); 4] = [
32+
(0xe61acf033d1a45df, -1087, -308),
33+
(0xab70fe17c79ac6ca, -1060, -300),
34+
(0xff77b1fcbebcdc4f, -1034, -292),
35+
(0xbe5691ef416bd60c, -1007, -284),
36+
];

0 commit comments

Comments
 (0)