Skip to content

Commit d9a3423

Browse files
committed
miri: make sure we can find link_section statics even for the local crate
1 parent fc555cd commit d9a3423

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

compiler/rustc_passes/src/reachable.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
3030
use rustc_hir::intravisit::{self, Visitor};
3131
use rustc_hir::Node;
3232
use rustc_middle::bug;
33-
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
33+
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
3434
use rustc_middle::middle::privacy::{self, Level};
3535
use rustc_middle::mir::interpret::{ConstAllocation, ErrorHandled, GlobalAlloc};
3636
use rustc_middle::query::Providers;
@@ -178,15 +178,7 @@ impl<'tcx> ReachableContext<'tcx> {
178178
if !self.any_library {
179179
// If we are building an executable, only explicitly extern
180180
// types need to be exported.
181-
let codegen_attrs = if self.tcx.def_kind(search_item).has_codegen_attrs() {
182-
self.tcx.codegen_fn_attrs(search_item)
183-
} else {
184-
CodegenFnAttrs::EMPTY
185-
};
186-
let is_extern = codegen_attrs.contains_extern_indicator();
187-
let std_internal =
188-
codegen_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL);
189-
if is_extern || std_internal {
181+
if has_custom_linkage(self.tcx, search_item) {
190182
self.reachable_symbols.insert(search_item);
191183
}
192184
} else {
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() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
in tls_callback

0 commit comments

Comments
 (0)