Skip to content

Commit 70df591

Browse files
authored
Rollup merge of #126938 - RalfJung:link_section, r=compiler-errors
miri: make sure we can find link_section statics even for the local crate Miri needs some way to iterate all the exported functions and "used" statics of all crates. For dependency crates, this already works fine since we can overwrite the query resonsible for computing `exported_symbols`, but it turns out for local binary crates this does not work: for binaries, `reachable_set` skips a lot of its logic and only checks `contains_extern_indicator()` and `RUSTC_STD_INTERNAL_SYMBOL`. Other flags like `CodegenFnAttrFlags::USED` are entirely ignored. This PR proposes to use the same check, `has_custom_linkage`, in binaries that we already use to drive the main workqueue of the reachability recursive traversal. I have no idea why binaries used a slightly different check that ignores `USED` -- was that deliberate or does it just not matter most of the time?
2 parents 033c0d3 + 79b4eac commit 70df591

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

tests/pass/tls/win_tls_callback.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//! Ensure that we call Windows TLS callbacks in the local crate.
2+
//@only-target-windows
3+
// Calling eprintln in the callback seems to (re-)initialize some thread-local storage
4+
// and then leak the memory allocated for that. Let's just ignore these leaks,
5+
// that's not what this test is about.
6+
//@compile-flags: -Zmiri-ignore-leaks
7+
8+
#[link_section = ".CRT$XLB"]
9+
#[used] // Miri only considers explicitly `#[used]` statics for `lookup_link_section`
10+
pub static CALLBACK: unsafe extern "system" fn(*const (), u32, *const ()) = tls_callback;
11+
12+
unsafe extern "system" fn tls_callback(_h: *const (), _dw_reason: u32, _pv: *const ()) {
13+
eprintln!("in tls_callback");
14+
}
15+
16+
fn main() {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
in tls_callback

0 commit comments

Comments
 (0)