-
Notifications
You must be signed in to change notification settings - Fork 12.5k
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!
sym operands emit functions without function body
#96623
Labels
A-inline-assembly
Area: inline asm!(..)
C-bug
Category: This is a bug.
requires-nightly
This issue requires a nightly compiler in some way.
Comments
rustbot
added
A-inline-assembly
Area: inline asm!(..)
requires-nightly
This issue requires a nightly compiler in some way.
labels
May 2, 2022
compiler-errors
added a commit
to compiler-errors/rust
that referenced
this issue
May 5, 2022
Collect function instance used in `global_asm!` sym operand The constants used in SymFn operands have FnDef type, so the type of the constant identifies the function. Fixes rust-lang#96623.
compiler-errors
added a commit
to compiler-errors/rust
that referenced
this issue
May 6, 2022
Collect function instance used in `global_asm!` sym operand The constants used in SymFn operands have FnDef type, so the type of the constant identifies the function. Fixes rust-lang#96623.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-inline-assembly
Area: inline asm!(..)
C-bug
Category: This is a bug.
requires-nightly
This issue requires a nightly compiler in some way.
Summary
If a function is only referenced by a
sym
operand inglobal_asm!
, the definition/body of that function will not be emitted by the compiler, and the linker will fail withunresolved symbol
error.Reproduction
Save the following code as
example.rs
: (https://rust.godbolt.org/z/4jbf3eWjb)(
.global _start
is there to stop the linker from pruning unreachable code.)Run
rustc example.rs -Cpanic=abort -Clink-args="-nostdlib"
produces a linker error "undefined reference toexample::main
":objdump -td example.example.2372ba8c-cgu.0.rcgu.o
verifies thatexample::foo
is indeed missing:The emitted llvm-ir looks something like this:
Some observations
The problem only appears if the function in question isn't used anywhere else. If we uncomment line
^4
, the resulting IR will be correctly emitted:Only functions can reproduce, static items work fine, as per line
^2
.Only
global_asm!
can reproduce,asm!
works fine, as per line^3
and co.Meta
cc @Amanieu #94468
@rustbot label +A-inline-assembly +requires-nightly
The text was updated successfully, but these errors were encountered: