|
| 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