Skip to content

Commit e3abbd4

Browse files
committed
Auto merge of #114946 - anforowicz:generic-fix-for-asan-lto, r=tmiasko
Preserve ASAN-related symbols during LTO. Fixes #113404
2 parents 4e21162 + e6dddbd commit e3abbd4

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

Diff for: compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,13 @@ extern "C" void LLVMRustPrintPasses() {
10581058
extern "C" void LLVMRustRunRestrictionPass(LLVMModuleRef M, char **Symbols,
10591059
size_t Len) {
10601060
auto PreserveFunctions = [=](const GlobalValue &GV) {
1061+
// Preserve LLVM-injected, ASAN-related symbols.
1062+
// See also https://github.com/rust-lang/rust/issues/113404.
1063+
if (GV.getName() == "___asan_globals_registered") {
1064+
return true;
1065+
}
1066+
1067+
// Preserve symbols exported from Rust modules.
10611068
for (size_t I = 0; I < Len; I++) {
10621069
if (GV.getName() == Symbols[I]) {
10631070
return true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Verifies that AddressSanitizer symbols show up as expected in LLVM IR with `-Zsanitizer`.
2+
// This is a regression test for https://github.com/rust-lang/rust/issues/113404
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+
// The test is restricted to `only-linux`, because the sanitizer-related instrumentation is target
13+
// specific. In particular, `___asan_globals_registered` is only used in the
14+
// `InstrumentGlobalsELF` and `InstrumentGlobalsMachO` code paths. The `only-linux` filter is
15+
// narrower than really needed (i.e. narrower than ELF-or-MachO), but this seems ok - having a
16+
// linux-only regression test should be sufficient here.
17+
//
18+
// needs-sanitizer-address
19+
// only-linux
20+
//
21+
// revisions:ASAN ASAN-FAT-LTO
22+
//[ASAN] compile-flags: -Zsanitizer=address
23+
//[ASAN-FAT-LTO] compile-flags: -Zsanitizer=address -Cprefer-dynamic=false -Clto=fat
24+
25+
#![crate_type="staticlib"]
26+
27+
// The test below mimics `CACHED_POW10` from `library/core/src/num/flt2dec/strategy/grisu.rs` which
28+
// (because of incorrect handling of `___asan_globals_registered` during LTO) was incorrectly
29+
// reported as an ODR violation in https://crbug.com/1459233#c1. Before this bug was fixed,
30+
// `___asan_globals_registered` would show up as `internal global i64` rather than `common hidden
31+
// global i64`. (The test expectations ignore the exact type because on `arm-android` the type
32+
// is `i32` rather than `i64`.)
33+
//
34+
// CHECK: @___asan_globals_registered = common hidden global
35+
// CHECK: @__start_asan_globals = extern_weak hidden global
36+
// CHECK: @__stop_asan_globals = extern_weak hidden global
37+
#[no_mangle]
38+
pub static CACHED_POW10: [(u64, i16, i16); 4] = [
39+
(0xe61acf033d1a45df, -1087, -308),
40+
(0xab70fe17c79ac6ca, -1060, -300),
41+
(0xff77b1fcbebcdc4f, -1034, -292),
42+
(0xbe5691ef416bd60c, -1007, -284),
43+
];

0 commit comments

Comments
 (0)