Filter out items other than non-generic functions and statics in our version of exported_symbols#1833
Conversation
Does this even make any sense? Looks like something rustc should reject... |
Probably doesn't. That crate also puts // In a dependency.
#[no_mangle]
#[allow(unused_attributes)]
pub struct Foo;I believe the error should be I experimented with it further and found an ICE that this PR // In a dependency.
#[no_mangle]
#[allow(no_mangle_generic_items)]
fn foo<T>() {}DetailsI believe it should also cause |
|
If we start ignoring some |
It probably simple never looks up the |
I think the corresponding source code is https://github.com/rust-lang/rust/blob/2962e7c0089d5c136f4e9600b7abccfbbde4973d/compiler/rustc_codegen_ssa/src/back/symbol_export.rs#L84-L102. |
exported_symbolsexported_symbols
| #[no_mangle] | ||
| pub fn assoc_fn_as_exported_symbol() -> i32 { |
There was a problem hiding this comment.
(This is testing #[no_mangle] on Node::ImplItem(&hir::ImplItem { kind: hir::ImplItemKind::Fn(..), .. }), which is included in exported_symbols (but previously broken in Miri: da2ed6f -- I fix that together in this PR in order to test this).)
I can't test this in tests/run-pass, because #[no_mangle] only seems to work on associated functions that are public in a library crate...
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=f1244afcdd26e2a28445f6e82ca46b50
If the associated function is used directly, it can works with rustc when compiling as a binrary, but it still doesn't work in Miri:
https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=46fc298b46ff44093c45cab9fddb6650
There was a problem hiding this comment.
So you are saying even with this patch, https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=46fc298b46ff44093c45cab9fddb6650 fails? Could you open an issue for that?
|
This looks reasonable, thanks. :) |
|
📌 Commit da2ed6f has been approved by |
|
☀️ Test successful - checks-actions |
#[no_mangle]on auseitem can make Miri ICE when compiling a dependency (rust-lang/rust#86261):Details
This might be because in #1776, we override the
exported_symbolsquery, and our version ofexported_symbolscan return auseitem which don't have a name if theuseitem is tagged with#[no_mangle], and then:rustc_codegen_ssa::back::symbol_export::symbol_name_for_instance_in_crateis called for for everyexported_symbols: https://github.com/rust-lang/rust/blob/fb3ea63d9b4c3e9bb90d4250b870faaffb9c8fd2/compiler/rustc_codegen_ssa/src/back/linker.rs#L1300-L1304rustc_middle::middle::exported_symbols::ExportedSymbol::symbol_name_for_local_instance: https://github.com/rust-lang/rust/blob/fb3ea63d9b4c3e9bb90d4250b870faaffb9c8fd2/compiler/rustc_codegen_ssa/src/back/symbol_export.rs#L412rustc_symbol_mangling::symbol_name_provider: https://github.com/rust-lang/rust/blob/fb3ea63d9b4c3e9bb90d4250b870faaffb9c8fd2/compiler/rustc_middle/src/middle/exported_symbols.rs#L37-L44item_name: https://github.com/rust-lang/rust/blob/fb3ea63d9b4c3e9bb90d4250b870faaffb9c8fd2/compiler/rustc_symbol_mangling/src/lib.rs#L216, which triggers the ICEIt might also be problematic for
miri/src/shims/foreign_items.rs
Line 165 in d39f0c6
item_name, but Miri cannot compile the dependency, so that code can't be reached.Therefore, this PR makes
exported_symbolsfilter out all items that are not functions or statics, so all items returned will have a name, which avoids the ICE (I have tested it in the https://github.com/jorgecarleitao/arrow2 repository).(This PR also includes a commit that fixes a small (unrelated) bug for
#[no_mangle]on associated functions -- I found that because I notice#[no_mangle]is supported on associated functions and they should not be filtered out inexported_symbols.)Fixes (when the submodule is bumped) rust-lang/rust#86261.