You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We should disallow that. If the item is defined in a different crate than it is used, LLVM would make up entirely different symbols and you did get a linker error. Even within a crate there is no guarantee that the definition and the user end up in the same codegen unit. Basically the use case I can think of where it would not be UB is a #[used] static that is not referenced anywhere.
Basically the use case I can think of where it would not be UB is a #[used] static that is not referenced anywhere.
But even in this case, is there an advantage to LLVM generating that name? You could just use #[used] without export_name or no_mangle for the same effect right?
Activity
folkertdev commentedon Apr 19, 2026
The issue reproduces just with
#[unsafe(export_name = "")], no need for the newline.An empty argument to
export_namehas some interesting behavior: it circumvents rust name mangling and instead has LLVM make up a symbol:https://godbolt.org/z/555eKdjWe
I wonder if that has any practical uses, or whether we should just disallow the empty string as an argument.
bjorn3 commentedon Apr 19, 2026
We should disallow that. If the item is defined in a different crate than it is used, LLVM would make up entirely different symbols and you did get a linker error. Even within a crate there is no guarantee that the definition and the user end up in the same codegen unit. Basically the use case I can think of where it would not be UB is a
#[used]static that is not referenced anywhere.folkertdev commentedon Apr 19, 2026
Basically the use case I can think of where it would not be UB is a
#[used]static that is not referenced anywhere.But even in this case, is there an advantage to LLVM generating that name? You could just use
#[used]withoutexport_nameorno_manglefor the same effect right?bjorn3 commentedon Apr 19, 2026
I don't think there is an advantage to having LLVM generate the name. It is just the only case I can think of where it would not be UB.
Rollup merge of rust-lang#155515 - folkertdev:export-name-not-empty, …
Rollup merge of rust-lang#155515 - folkertdev:export-name-not-empty, …
Rollup merge of rust-lang#155515 - folkertdev:export-name-not-empty, …
Rollup merge of rust-lang#155515 - folkertdev:export-name-not-empty, …