rust-lang / rust-lang/rust

Functions marked with #[no_mangle] are not GC-ed on powerpc

Open
#144,777 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-linkers C-bug O-PowerPC T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Newly introduced test by this commit fails for powerpc target.
The code used from this issue report also fails to link on powerpc target, due to unresolved symbols.

I tried this code:

// src/main.rs

unsafe extern "C" {
    unsafe static UNDEFINED: usize;
}

#[unsafe(no_mangle)]
pub fn used() {
    println!("UNDEFINED = {}", unsafe { UNDEFINED });
}

pub fn marker() -> usize {
    0
}

fn main() {
    assert_eq!(marker(), 0_usize);
}
cargo build --target powerpc-unknown-linux-gnu

I expected to see this happen: it builds

Instead, this happened: it emits linker errors

error: linking with `powerpc-linux-gnu-gcc` failed: exit status: 1
  |
  = note:  "powerpc-linux-gnu-gcc" "-m32" "/tmp/rustcgCiFys/symbols.o" "<8 object files omitted>" "-Wl,--as-needed" "-Wl,-Bstatic" "<sysroot>/lib/rustlib/powerpc-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-*,librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-L" "/tmp/rustcgCiFys/raw-dylibs" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "<sysroot>/lib/rustlib/powerpc-unknown-linux-gnu/lib" "-o" "/home/projects/rust-test/target/powerpc-unknown-linux-gnu/debug/deps/test_rust-3c4b8a270f49f452" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: /usr/lib/gcc-cross/powerpc-linux-gnu/12/../../../../powerpc-linux-gnu/bin/ld: /home/projects/rust-test/target/powerpc-unknown-linux-gnu/debug/deps/test_rust-3c4b8a270f49f452.42850mbhj0t4hj3povrah4dmz.1ofm0p2.rcgu.o:(.got2+0x0): undefined reference to `UNDEFINED'
          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
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib)

error: could not compile `test-rust` (bin "test-rust") due to 1 previous error
Meta

rustc --version --verbose:

rustc 1.88.0 (6b00bc388 2025-06-23)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reproduction in src/main.rs and run cargo build --target powerpc-unknown-linux-gnu to confirm the unresolved UNDEFINED symbol. Compare the newly introduced test in the linked commit with the powerpc failure and trace the no_mangle and linker garbage-collection behavior. Done means the test and example link successfully for the powerpc target.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.