-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
global_asm-implemented extern "C" functions are not exported from dylib crates #128071
Comments
The same happens if you implement the function in a static library you link into the dylib. Rustc doesn't know that the function is defined within the dylib, so it doesn't mark it as exported in the version script. |
I think that behavior is fine in theory: there is no way for rust to know that the symbol is defined. but I believe there is currently a way to force the exporting of the symbol. E.g. this does not work std::arch::global_asm! {
".global foo",
"foo:",
"ret",
}
extern "C" {
#[export_name = "foo"]
pub fn foo();
} because
So could it be a solution to provide a way to explicitly export the symbol? |
global_asm and static libraries should probably be handled the same for symbol export. You could look at the issue for the staticlib version of this behavior if such an option is already suggested. |
I tried this code, which is a minimized reproduction of https://github.com/EmbarkStudios/crash-handling/blob/main/crash-context/src/linux/getcontext.rs#L3-L12 and https://github.com/EmbarkStudios/crash-handling/blob/main/crash-context/src/linux/getcontext/x86_64.rs#L48:
With
lib.crate-type
set to["dylib"]
or["cdylib"]
.I expected to see this happen: When building the example code here as an rdylib or cdylib, I expected to see
foo
present in the output dylib's symbols.Instead, this happened: The output dylib has no symbols. It seems that for some reason, despite
foo
being apub fn
, the function is omitted from the list of extern symbols passed into the version-script. The symbol list file in my local case is completely empty. My guess here is that becausefoo
is anextern "C"
function, it's expected that the symbol is exported in some other object file / archive that would be statically linked in and then (maybe) caught by thisrust/compiler/rustc_codegen_ssa/src/back/symbol_export.rs
Lines 82 to 83 in 20f23ab
One way to force the symbol here, as I'm running on an M1 mac, is to do the following:
Meta
Tested on both stable + nightly.
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: