Skip to content

global_asm! issues LLVM error "undefined temporary symbol" for non-existent numerical labels #140179

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

Open
pqcfox opened this issue Apr 23, 2025 · 1 comment
Labels
A-global-asm Area: `global_asm!` C-discussion Category: Discussion or questions that doesn't represent real issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@pqcfox
Copy link

pqcfox commented Apr 23, 2025

I've found that if I place undefined local numeric labels in a global_asm! block, that rustc will yield an LLVM (?) error error: Undefined temporary symbol .Ltmp0, presumably as the numeric label is replaced with a temporary symbol .Ltmp0.

Here's a minimum viable example:

use std::arch::global_asm;

fn main () {}

global_asm!(
    "jmp 100f"
);

(Playground link: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=ddb9a35af1ac6a0c4d3a145253605252)

Notably, changing the label to a (global) text label as in the following doesn't cause any error to be issued.

use std::arch::global_asm;

fn main () {}

global_asm!(
    "jmp .label"
);

I wasn't sure if this is something that would fall into the purview of Rust to handle with a more direct error message, but wanted to raise it as a potential issue since I'd expect either (a) no error message as in the case of the global label or (b) a typical rustc error message indicating where in the code the issue lies.

Meta

rustc --version --verbose:

rustc 1.85.1 (4eb161250 2025-03-15)
binary: rustc
commit-hash: 4eb161250e340c8f48f66e2b929ef4a5bed7c181
commit-date: 2025-03-15
host: x86_64-unknown-linux-gnu
release: 1.85.1
LLVM version: 19.1.7

Also verified with nightly:

rustc 1.88.0-nightly (d6c1e454a 2025-04-21)
binary: rustc
commit-hash: d6c1e454aa8af5e7e59fbf5c4e7d3128d2f99582
commit-date: 2025-04-21
host: x86_64-unknown-linux-gnu
release: 1.88.0-nightly
LLVM version: 20.1.2
@pqcfox pqcfox added the C-bug Category: This is a bug. label Apr 23, 2025
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Apr 23, 2025
@bjorn3
Copy link
Member

bjorn3 commented Apr 23, 2025

Notably, changing the label to a (global) text label as in the following doesn't cause any error to be issued.

That will cause the symbol .label to be imported from another object file. It doesn't cause an error because the entire section that contains the jmp .label gets removed by the linker as we pass --gc-sections. If I pass -Clink-dead-code=yes to disable this, I get:

error: linking with `cc` failed: exit status: 1
  |
  = note:  "cc" "-m64" "/tmp/rustcXCbmew/symbols.o" "<2 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,libcfg_if-*,liblibc-*,liballoc-*,librustc_std_workspace_core-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "<sysroot>/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "rust_out" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: /usr/bin/ld: rust_out.rust_out.5f0bdc08ea4efb31-cgu.0.rcgu.o:(.text+0x1): undefined reference to `.label'
          collect2: error: ld returned 1 exit status
          
  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link

error: aborting due to 1 previous error

presumably as the numeric label is replaced with a temporary symbol .Ltmp0.

Indeed. rustc --emit asm shows:

	.text
	.file	"rust_out.5f0bdc08ea4efb31-cgu.0"


	jmp	.Ltmp0



	.section	.text._ZN3std2rt10lang_start17h19f5fd841b73ea7fE,"ax",@progbits
[...]

@lolbinarycat lolbinarycat added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 30, 2025
@jieyouxu jieyouxu added C-discussion Category: Discussion or questions that doesn't represent real issues. A-global-asm Area: `global_asm!` and removed C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels May 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-global-asm Area: `global_asm!` C-discussion Category: Discussion or questions that doesn't represent real issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants