Skip to content

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

@ptatrai

Description

@ptatrai

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.O-PowerPCTarget: PowerPC processorsneeds-triageThis issue may need triage. Remove it if it has been sufficiently triaged.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions