Skip to content

Excess object in staticlib archive eventually causing link error #125619

Closed
@XrXr

Description

@XrXr

I tried this code:

$ # on aarch64-unknown-linux-gnu
$ rustc --crate-type staticlib -C lto=thin -O /dev/null
$ ar x libnull.a
$ nm *multc3.o

I expected to see this happen:

The nm output shouldn't say U __builtin_copysignq, since that's an x86 intrinsic unavailable on aarch64-unknown-linux-gnu

Instead, this happened:

$ nm *multc3.o
                 U __addtf3
                 U __builtin_copysignq
                 U __floatsitf
                 U __letf2
0000000000000000 T __multc3
                 U __multf3
                 U __subtf3
                 U __unordtf2

Over in Ruby, because we consume the static archive by partial linking it into an .o file first, we've been getting reports of link errors due to this unused object in the archive:

partial linking yjit/target/release/libyjit.a into yjit/target/release/libyjit.o
linking miniruby
/usr/bin/ld: yjit/target/release/libyjit.o: in function `__multc3':
/cargo/registry/src/index.crates.io-6f17d22bba15001f/compiler_builtins-0.1.108/./lib/builtins/multc3.c:33:(.text.__multc3+0x30c): undefined reference to `__builtin_copysignq'
/usr/bin/ld: /cargo/registry/src/index.crates.io-6f17d22bba15001f/compiler_builtins-0.1.108/./lib/builtins/multc3.c:34:(.text.__multc3+0x394): undefined reference to `__builtin_copysignq'
/usr/bin/ld: /cargo/registry/src/index.crates.io-6f17d22bba15001f/compiler_builtins-0.1.108/./lib/builtins/multc3.c:42:(.text.__multc3+0x7f4): undefined reference to `__builtin_copysignq'
/usr/bin/ld: /cargo/registry/src/index.crates.io-6f17d22bba15001f/compiler_builtins-0.1.108/./lib/builtins/multc3.c:43:(.text.__multc3+0x864): undefined reference to `__builtin_copysignq'
/usr/bin/ld: /cargo/registry/src/index.crates.io-6f17d22bba15001f/compiler_builtins-0.1.108/./lib/builtins/multc3.c:47:(.text.__multc3+0x8c4): undefined reference to `__builtin_copysignq'
/usr/bin/ld: yjit/target/release/libyjit.o:/cargo/registry/src/index.crates.io-6f17d22bba15001f/compiler_builtins-0.1.108/./lib/builtins/multc3.c:38: more undefined references to `__builtin_copysignq' follow
collect2: error: ld returned 1 exit status

It looks like this particular intrinsic comes from a file that isn't included for ARM Windows targets:

https://github.com/rust-lang/compiler-builtins/blob/c04eb9e1afb72bdf943f5e5d77b3812f40526602/build.rs#L537-L539

so in fact it should be completely unused. In the README for compiler-builtins, the file is listed under "Unimplemented" and seemingly with no plan for usage:

These builtins involve floating-point types ("f80" and complex numbers) that are not supported by Rust.

I'm wondering if rust could stop including this object in the archive.

Meta

This is regression that started in 1.78.0. With 1.77.0 the nm output is:

$ nm *multc3.o
                 U __addtf3
                 U __floatsitf
                 U __letf2
0000000000000000 T __multc3
                 U __multf3
                 U __subtf3
                 U __unordtf2

and it works fine for ruby.

Issue exists in latest nightly.

rustc --version --verbose:

rustc 1.80.0-nightly (bdbbb6c6a 2024-05-26)
binary: rustc
commit-hash: bdbbb6c6a718d4d196131aa16bafb60e850311d9
commit-date: 2024-05-26
host: aarch64-unknown-linux-gnu
release: 1.80.0-nightly
LLVM version: 18.1.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.C-external-bugCategory: issue that is caused by bugs in software beyond our controlO-AArch64Armv8-A or later processors in AArch64 modeO-muslTarget: The musl libcT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.llvm-fixed-upstreamIssue expected to be fixed by the next major LLVM upgrade, or backported fixesregression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions