|
11 | 11 | extern crate rustc_codegen_ssa; |
12 | 12 | extern crate rustc_data_structures; |
13 | 13 | extern crate rustc_driver; |
14 | | -extern crate rustc_hir; |
15 | 14 | extern crate rustc_interface; |
16 | 15 | extern crate rustc_log; |
17 | 16 | extern crate rustc_middle; |
@@ -48,14 +47,9 @@ use miri::{ |
48 | 47 | use rustc_codegen_ssa::traits::CodegenBackend; |
49 | 48 | use rustc_data_structures::sync::{self, DynSync}; |
50 | 49 | use rustc_driver::Compilation; |
51 | | -use rustc_hir::{self as hir, Node}; |
52 | 50 | use rustc_interface::interface::Config; |
53 | 51 | use rustc_interface::util::DummyCodegenBackend; |
54 | 52 | use rustc_log::tracing::debug; |
55 | | -use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; |
56 | | -use rustc_middle::middle::exported_symbols::{ |
57 | | - ExportedSymbol, SymbolExportInfo, SymbolExportKind, SymbolExportLevel, |
58 | | -}; |
59 | 53 | use rustc_middle::query::LocalCrate; |
60 | 54 | use rustc_middle::ty::TyCtxt; |
61 | 55 | use rustc_session::config::{CrateType, ErrorOutputType, OptLevel}; |
@@ -258,58 +252,14 @@ impl rustc_driver::Callbacks for MiriDepCompilerCalls { |
258 | 252 | // Queries overridden here affect the data stored in `rmeta` files of dependencies, |
259 | 253 | // which will be used later in non-`MIRI_BE_RUSTC` mode. |
260 | 254 | config.override_queries = Some(|_, local_providers| { |
261 | | - // We need to add #[used] symbols to exported_symbols for `lookup_link_section`. |
262 | | - // FIXME handle this somehow in rustc itself to avoid this hack. |
263 | | - local_providers.queries.exported_non_generic_symbols = |tcx, LocalCrate| { |
264 | | - let reachable_set = tcx.with_stable_hashing_context(|mut hcx| { |
265 | | - tcx.reachable_set(()).to_sorted(&mut hcx, true) |
266 | | - }); |
267 | | - tcx.arena.alloc_from_iter( |
268 | | - // This is based on: |
269 | | - // https://github.com/rust-lang/rust/blob/2962e7c0089d5c136f4e9600b7abccfbbde4973d/compiler/rustc_codegen_ssa/src/back/symbol_export.rs#L62-L63 |
270 | | - // https://github.com/rust-lang/rust/blob/2962e7c0089d5c136f4e9600b7abccfbbde4973d/compiler/rustc_codegen_ssa/src/back/symbol_export.rs#L174 |
271 | | - reachable_set.into_iter().filter_map(|&local_def_id| { |
272 | | - // Do the same filtering that rustc does: |
273 | | - // https://github.com/rust-lang/rust/blob/2962e7c0089d5c136f4e9600b7abccfbbde4973d/compiler/rustc_codegen_ssa/src/back/symbol_export.rs#L84-L102 |
274 | | - // Otherwise it may cause unexpected behaviours and ICEs |
275 | | - // (https://github.com/rust-lang/rust/issues/86261). |
276 | | - let is_reachable_non_generic = matches!( |
277 | | - tcx.hir_node_by_def_id(local_def_id), |
278 | | - Node::Item(&hir::Item { |
279 | | - kind: hir::ItemKind::Static(..) | hir::ItemKind::Fn{ .. }, |
280 | | - .. |
281 | | - }) | Node::ImplItem(&hir::ImplItem { |
282 | | - kind: hir::ImplItemKind::Fn(..), |
283 | | - .. |
284 | | - }) |
285 | | - if !tcx.generics_of(local_def_id).requires_monomorphization(tcx) |
286 | | - ); |
287 | | - if !is_reachable_non_generic { |
288 | | - return None; |
289 | | - } |
290 | | - let codegen_fn_attrs = tcx.codegen_fn_attrs(local_def_id); |
291 | | - if codegen_fn_attrs.contains_extern_indicator() |
292 | | - || codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::USED_COMPILER) |
293 | | - || codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::USED_LINKER) |
294 | | - { |
295 | | - Some(( |
296 | | - ExportedSymbol::NonGeneric(local_def_id.to_def_id()), |
297 | | - // Some dummy `SymbolExportInfo` here. We only use |
298 | | - // `exported_symbols` in shims/foreign_items.rs and the export info |
299 | | - // is ignored. |
300 | | - SymbolExportInfo { |
301 | | - level: SymbolExportLevel::C, |
302 | | - kind: SymbolExportKind::Text, |
303 | | - used: false, |
304 | | - rustc_std_internal_symbol: false, |
305 | | - }, |
306 | | - )) |
307 | | - } else { |
308 | | - None |
309 | | - } |
310 | | - }), |
311 | | - ) |
312 | | - } |
| 255 | + // `exported_non_generic_symbols` is usually empty because we don't codegen anything. |
| 256 | + // However, we need it for `lookup_link_section`. |
| 257 | + // So overwrite the query with a version that dooes something even without codegen. |
| 258 | + local_providers.queries.exported_non_generic_symbols = |
| 259 | + |tcx, LocalCrate| rustc_codegen_ssa::back::exported_non_generic_symbols_helper(tcx); |
| 260 | + // `exported_non_generic_symbols_helper` calls `reachable_non_generics`. |
| 261 | + local_providers.queries.reachable_non_generics = |
| 262 | + |tcx, LocalCrate| rustc_codegen_ssa::back::reachable_non_generics_helper(tcx); |
313 | 263 | }); |
314 | 264 |
|
315 | 265 | // Register our custom extra symbols. |
|
0 commit comments