Skip to content
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

Undefined reference to getauxval in function init_have_lse_atomics when compiling to nightly aarch64-unknown-linux-musl #89626

Open
XAMPPRocky opened this issue Oct 7, 2021 · 41 comments
Assignees
Labels
A-linkage Area: linking into static, shared libraries and binaries A-linkers Area: linkers... you gotta love linkers C-bug Category: This is a bug. O-Arm Target: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 state O-musl Target: The musl libc P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@XAMPPRocky
Copy link
Member

Code

I received this pull request, which caught a regression for aarch64-unknown-linux-musl when compiling for nightly. The same process works for stable and beta. I don't have a machine that can easily compile to this platform, so I can't reduce it at the moment: librasn/rasn#49

Version it worked on

It most recently worked on: Works on stable and beta 1.56.0-beta.4 (e6e620e1c 2021-10-04)

Version with regression

rustc --version --verbose: 1.57.0-nightly (0eabf25 2021-10-06)

Backtrace

= note: /rust/lib/rustlib/aarch64-unknown-linux-musl/lib/libcompiler_builtins-cbf6a032efba8222.rlib(cpu_model.o): In function `init_have_lse_atomics':
          /cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.49/./lib/builtins/cpu_model.c:786: undefined reference to `getauxval'
          collect2: error: ld returned 1 exit status
          
= help: 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#cargorustc-link-libkindname)
@XAMPPRocky XAMPPRocky added O-Arm Target: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 state O-musl Target: The musl libc C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Oct 7, 2021
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. and removed regression-untriaged Untriaged performance or correctness regression. labels Oct 7, 2021
@XAMPPRocky XAMPPRocky changed the title Undefined reference to getauxval' in function init_have_lse_atomics when compiling to nightly aarch64-unknown-linux-musl` Undefined reference to getauxval in function init_have_lse_atomics when compiling to nightly aarch64-unknown-linux-musl Oct 7, 2021
@nbdd0121
Copy link
Contributor

nbdd0121 commented Oct 7, 2021

@nbdd0121
Copy link
Contributor

nbdd0121 commented Oct 7, 2021

@rustbot label E-needs-bisection

@rustbot rustbot added the E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc label Oct 7, 2021
@XAMPPRocky
Copy link
Member Author

Tagging #76992 and #85805 since they seem relevant and maybe a potential fix.

@apiraino
Copy link
Contributor

apiraino commented Oct 14, 2021

forcing notification for prioritization

@rustbot label -I-prioritize +T-compiler +I-prioritize

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 14, 2021
@apiraino apiraino added I-prioritize Issue: Indicates that prioritization has been requested for this issue. and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Oct 14, 2021
@tonyg
Copy link

tonyg commented Oct 15, 2021

See also cross-rs/cross#598.

(NB. that issue has a bit of waffley analysis, but also a workaround.)

@jbg
Copy link

jbg commented Oct 18, 2021

Any ideas for the equivalent workaround when not using cross? aarch64-unknown-linux-musl is the host as well as the target here (CI build in an Alpine container) and I'm hitting this issue. I tried setting either RUSTFLAGS or CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS to -C link-arg=/usr/lib/libc.a but it causes a ton of duplicate symbol errors.

@joseluisq
Copy link

@jbg I know that this issue is all about nightly Rust but we faced this via Cross (which BTW is not what you are using) but we switched back to stable 1.55 and our CI built again for now.
I don't know if that helps you.

@jbg
Copy link

jbg commented Oct 18, 2021

Thanks! this particular codebase has to use a gated feature so going back to stable isn't an option for now.

@tonyg
Copy link

tonyg commented Oct 18, 2021

@jbg Ah, that's interesting. For me, it looked like there was no libc being linked at all, so adding it to the end worked out well. For you, I'm guessing there's some reference to libc earlier in the linker command line. Unfortunately if I remember rightly the linker command-line is order-sensitive, with later mentions of object/library files supplying symbols needed by earlier files. But I thought also that mentioning a library was idempotent!

What are the duplicate symbols you see? Can you run your build with -vv to see what command-line rustc invocation you have? Finally, /usr/lib/libc.a isn't present on any of my systems: instead I need to supply /usr/lib/[SOMEARCH]/libc.a. Could varying the libc.a you supply work in your context?

@jbg
Copy link

jbg commented Oct 18, 2021

I just noticed that the libc crate is in the dependency tree (transitively), and it seems to be the source of the duplicate symbols when I try to use the RUSTFLAGS="-C link-arg=/usr/lib/libc.a" workaround:

error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crt1.o" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crti.o" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crtbegin.o" "/target/debug/build/libc-98210b609d8e5a26/build_script_build-98210b609d8e5a26.build_script_build.8cb445ef-cgu.0.rcgu.o" "/target/debug/build/libc-98210b609d8e5a26/build_script_build-98210b609d8e5a26.build_script_build.8cb445ef-cgu.1.rcgu.o" "/target/debug/build/libc-98210b609d8e5a26/build_script_build-98210b609d8e5a26.build_script_build.8cb445ef-cgu.10.rcgu.o" "/target/debug/build/libc-98210b609d8e5a26/build_script_build-98210b609d8e5a26.build_script_build.8cb445ef-cgu.11.rcgu.o" "/target/debug/build/libc-98210b609d8e5a26/build_script_build-98210b609d8e5a26.build_script_build.8cb445ef-cgu.12.rcgu.o" "/target/debug/build/libc-98210b609d8e5a26/build_script_build-98210b609d8e5a26.build_script_build.8cb445ef-cgu.13.rcgu.o" "/target/debug/build/libc-98210b609d8e5a26/build_script_build-98210b609d8e5a26.build_script_build.8cb445ef-cgu.14.rcgu.o" "/target/debug/build/libc-98210b609d8e5a26/build_script_build-98210b609d8e5a26.build_script_build.8cb445ef-cgu.15.rcgu.o" "/target/debug/build/libc-98210b609d8e5a26/build_script_build-98210b609d8e5a26.build_script_build.8cb445ef-cgu.2.rcgu.o" "/target/debug/build/libc-98210b609d8e5a26/build_script_build-98210b609d8e5a26.build_script_build.8cb445ef-cgu.3.rcgu.o" "/target/debug/build/libc-98210b609d8e5a26/build_script_build-98210b609d8e5a26.build_script_build.8cb445ef-cgu.4.rcgu.o" "/target/debug/build/libc-98210b609d8e5a26/build_script_build-98210b609d8e5a26.build_script_build.8cb445ef-cgu.5.rcgu.o" "/target/debug/build/libc-98210b609d8e5a26/build_script_build-98210b609d8e5a26.build_script_build.8cb445ef-cgu.6.rcgu.o" "/target/debug/build/libc-98210b609d8e5a26/build_script_build-98210b609d8e5a26.build_script_build.8cb445ef-cgu.7.rcgu.o" "/target/debug/build/libc-98210b609d8e5a26/build_script_build-98210b609d8e5a26.build_script_build.8cb445ef-cgu.8.rcgu.o" "/target/debug/build/libc-98210b609d8e5a26/build_script_build-98210b609d8e5a26.build_script_build.8cb445ef-cgu.9.rcgu.o" "/target/debug/build/libc-98210b609d8e5a26/build_script_build-98210b609d8e5a26.32sykodykbcu9la2.rcgu.o" "-Wl,--as-needed" "-L" "/target/debug/deps" "-L" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/libstd-c44788b657ddddd5.rlib" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/libpanic_unwind-2becdccda730ce42.rlib" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/libminiz_oxide-3a7898da562cf313.rlib" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/libadler-fc70ddb33855e2e8.rlib" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/libobject-5fb8217618711e88.rlib" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/libmemchr-c061be432db3e13d.rlib" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/libaddr2line-5a6d99ea33f6ceae.rlib" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/libgimli-6db2c8017781e41d.rlib" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/libstd_detect-7d0d2f13c64acb61.rlib" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/librustc_demangle-77c2cc6c5af8536c.rlib" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/libhashbrown-8ca99a806b6c7500.rlib" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/librustc_std_workspace_alloc-eced44336e84fd45.rlib" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/libunwind-ec4fe46000190b79.rlib" "-lunwind" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/libcfg_if-692ed2e2b4273428.rlib" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/liblibc-72b57ab90668a509.rlib" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/liballoc-7aed2b0a9d39bb09.rlib" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/librustc_std_workspace_core-e0db88e40d9c7e0b.rlib" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/libcore-fcedc0d4b8cb02ca.rlib" "-Wl,--end-group" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/libcompiler_builtins-cbf6a032efba8222.rlib" "-Wl,-Bdynamic" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-nostartfiles" "-L" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib" "-L" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained" "-o" "/target/debug/build/libc-98210b609d8e5a26/build_script_build-98210b609d8e5a26" "-Wl,--gc-sections" "-static" "-no-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "/usr/lib/libc.a" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crtend.o" "/usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crtn.o"
  = note: /usr/lib/gcc/aarch64-alpine-linux-musl/10.3.1/../../../../aarch64-alpine-linux-musl/bin/ld: /usr/lib/libc.a(__init_tls.lo): in function `__init_tp':
          /home/buildozer/aports/main/musl/src/v1.2.2/src/env/__init_tls.c:15: multiple definition of `__init_tp'; /usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/liblibc-72b57ab90668a509.rlib(__init_tls.lo):__init_tls.c:(.text.__init_tp+0x0): first defined here
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.3.1/../../../../aarch64-alpine-linux-musl/bin/ld: /usr/lib/libc.a(__init_tls.lo): in function `__copy_tls':
          /home/buildozer/aports/main/musl/src/v1.2.2/src/env/__init_tls.c:40: multiple definition of `__copy_tls'; /usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/liblibc-72b57ab90668a509.rlib(__init_tls.lo):__init_tls.c:(.text.__copy_tls+0x0): first defined here
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.3.1/../../../../aarch64-alpine-linux-musl/bin/ld: /usr/lib/libc.a(libc.lo):/home/buildozer/aports/main/musl/src/v1.2.2/src/internal/libc.c:6: multiple definition of `__progname_full'; /usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/liblibc-72b57ab90668a509.rlib(libc.lo):(.bss.__progname_full+0x0): first defined here
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.3.1/../../../../aarch64-alpine-linux-musl/bin/ld: /usr/lib/libc.a(libc.lo):/home/buildozer/aports/main/musl/src/v1.2.2/src/internal/libc.c:6: multiple definition of `__progname'; /usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/liblibc-72b57ab90668a509.rlib(libc.lo):(.bss.__progname+0x0): first defined here
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.3.1/../../../../aarch64-alpine-linux-musl/bin/ld: warning: size of symbol `__libc' changed from 112 in /usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/liblibc-72b57ab90668a509.rlib(libc.lo) to 104 in /usr/lib/libc.a(libc.lo)
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.3.1/../../../../aarch64-alpine-linux-musl/bin/ld: /usr/lib/libc.a(sigaction.lo): in function `__get_handler_set':
          /home/buildozer/aports/main/musl/src/v1.2.2/src/signal/sigaction.c:15: multiple definition of `__get_handler_set'; /usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/liblibc-72b57ab90668a509.rlib(sigaction.lo):sigaction.c:(.text.__get_handler_set+0x0): first defined here
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.3.1/../../../../aarch64-alpine-linux-musl/bin/ld: /usr/lib/libc.a(sigaction.lo): in function `__libc_sigaction':
          /home/buildozer/aports/main/musl/src/v1.2.2/src/signal/sigaction.c:21: multiple definition of `__libc_sigaction'; /usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/liblibc-72b57ab90668a509.rlib(sigaction.lo):sigaction.c:(.text.__libc_sigaction+0x0): first defined here
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.3.1/../../../../aarch64-alpine-linux-musl/bin/ld: /usr/lib/libc.a(sigaction.lo): in function `__sigaction':
          /home/buildozer/aports/main/musl/src/v1.2.2/src/signal/sigaction.c:61: multiple definition of `__sigaction'; /usr/local/rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/liblibc-72b57ab90668a509.rlib(sigaction.lo):sigaction.c:(.text.__sigaction+0x0): first defined here
          collect2: error: ld returned 1 exit status
          
error: could not compile `libc` due to previous error

/usr/lib/libc.a is from the musl-dev Alpine package. Since this is Alpine, musl is the system libc. I don't have any other libc.a and the only other libc.a in the Alpine repositories are for other targets. Note that I'm not cross-compiling.

@hkratz
Copy link
Contributor

hkratz commented Oct 18, 2021

Probably related to #83655.

@hkratz
Copy link
Contributor

hkratz commented Oct 18, 2021

Actually even helloworld fails to compile with --target aarch64-unknown-linux-musl right now due to this issue while it compiles and runs fine with stable.

@tonyg
Copy link

tonyg commented Oct 18, 2021

Probably related to #83655.

Great catch! The timing looks just about right - it must have been about 12-13 days ago I noticed the problem that I subsequently reported in cross-rs/cross#598, and it looks like #83655 was merged into master about 14 days ago.

even helloworld fails to compile with --target aarch64-unknown-linux-musl

This matches what I saw with cross-rs/cross#598, where a cargo init foo fails to compile with nightly.

@jbg
Copy link

jbg commented Oct 18, 2021

Yes, very likely. I've hit similar issues with outline atomics with C/C++ code on aarch64-unknown-linux-musl, which are fixed with CFLAGS=-mno-outline-atomics. See for example rust-lang/git2-rs#706

@jbg
Copy link

jbg commented Oct 19, 2021

I tried to use this workaround: RUSTFLAGS="-C target-feature=-outline-atomics"

But it doesn't change anything. Is it because +outline-atomics is added after -C target-feature is processed here?

@hkratz
Copy link
Contributor

hkratz commented Oct 19, 2021

Hmm. getauxval is aliased to __getauxval in liblibc-[...].rlib. The problem likely manifests because of #76992 (see above).

What works for me as a workaround with helloworld is using lld for linking like this:

RUSTFLAGS="-Zgcc-ld=lld" cargo +nightly build --target aarch64-unknown-linux-musl

cc @joshtriplett

@ehuss
Copy link
Contributor

ehuss commented Jul 19, 2023

FWIW, I'm still running into issues with getauxval missing on aarch64 when linking with C code. I'm not sure what the issue is exactly, though this issue seems to be the most likely related that I can find. I'm not sure how to minimize, but here's a dockerfile that reproduces it:

FROM alpine:3.18.2

RUN apk add pkgconfig build-base curl openssl-dev openssl-libs-static
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh
RUN sh ./rustup.sh --profile minimal --default-toolchain nightly -y
ENV PATH=/root/.cargo/bin:${PATH}
WORKDIR /tmp
RUN cargo new foo
WORKDIR /tmp/foo
RUN cargo add git2
RUN echo 'use git2::*; fn main() { git2::Repository::init("x").unwrap(); }' > src/main.rs
# This also fails with -F git2/vendored-openssl.
RUN cargo run

This fails with:

= note: /usr/lib/gcc/aarch64-alpine-linux-musl/12.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: /root/.rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/libcompiler_builtins-d1519a8aba827abf.rlib(45c91108d938afe8-cpu_model.o): in function `init_have_lse_atomics':
        /cargo/registry/src/index.crates.io-6f17d22bba15001f/compiler_builtins-0.1.91/./lib/builtins/cpu_model.c:1051: undefined reference to `getauxval'
        /usr/lib/gcc/aarch64-alpine-linux-musl/12.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: /root/.rustup/toolchains/nightly-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/libcompiler_builtins-d1519a8aba827abf.rlib(45c91108d938afe8-cpu_model.o): in function `init_cpu_features':
        /cargo/registry/src/index.crates.io-6f17d22bba15001f/compiler_builtins-0.1.91/./lib/builtins/cpu_model.c:1344: undefined reference to `getauxval'
        /usr/lib/gcc/aarch64-alpine-linux-musl/12.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: /cargo/registry/src/index.crates.io-6f17d22bba15001f/compiler_builtins-0.1.91/./lib/builtins/cpu_model.c:1345: undefined reference to `getauxval'
        collect2: error: ld returned 1 exit status

Above are noted several workarounds:
-Clinker=rust-lld or -Zgcc-ld=lld or CFLAGS=-mno-outline-atomics

I'm not sure were the problem lies, though #76992 seems suspicious.

rustc 1.73.0-nightly (903e279f4 2023-07-18)
binary: rustc
commit-hash: 903e279f468590fa3425f8aff7f3d61a5a873dbb
commit-date: 2023-07-18
host: aarch64-unknown-linux-musl
release: 1.73.0-nightly
LLVM version: 16.0.5

@peterwaller-arm
Copy link

Please can this issue be reopened. It still manifests on stable rust today, but only under limited circumstances.

As others have noted, the issue is caused by -lc appearing before libcompiler_builtins.rlib. Using LLD fixes the issue because LLD has a different behaviour to bfd/gold ld; argument order of libraries does not matter there. It looks as though the issue can be worked around with -C link-arg=-lc in rustflags, (which I assume makes -lc appear at the end).

Oddly, I have two different uses of cargo test within a build system, one of which gives an undefined reference to getauxval, and the other does not. So I suspect the underlying issue is there but not always manifesting.

I can see that the fix of using --start-group and --end-group considered in #76992 has been dropped for lack of bandwidth and a performance impact concern. A potential simpler fix could be to repeat -lc at the end of the link arguments to protect against this case.

@jacobbramley
Copy link
Contributor

jacobbramley commented Sep 20, 2023

It's possible to trigger this by building the default "hello world" application with RUSTFLAGS="-C target-feature=+crt-static". I'm using a Debian 10 x86_64 host with the OS-packaged g++-aarch64-linux-gnu toolchain. Some other linkers and environments seem to have slightly different behaviours (as noted by others).

This isn't limited to MUSL; I'm actually using aarch64-unknown-linux-gnu.

Finally: -C link-arg=-lc isn't quite a complete workaround for static builds because there's a trailling -Wl,-Bdynamic, so appending -lc to the command line causes it to be dynamically linked. Instead, -C link-args=-Wl,-Bstatic -C link-args=-lc does the right thing (and file now reports that the result is statically linked).

@apiraino
Copy link
Contributor

I'm going to reopen this issue, we'll probably need to figure out a few regressions when linking for musl filed recently

@apiraino apiraino reopened this Sep 20, 2023
@apiraino apiraino added regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. labels Sep 20, 2023
@wesleywiser
Copy link
Member

@bjorn3 noticed that

the -lc linker arg does come right after liblibc.rlib rather than at the end

@pnkfelix has volunteered to investigate why that is happening.

@AlexTMjugador
Copy link

For anyone stumbling upon this issue today, the equivalent of the stated -Zgcc-ld=lld workaround since #116514 was merged is -Zunstable-options -Clinker-flavor=gnu-lld-cc.

@alyssais
Copy link
Contributor

This doesn't seem to be a problem for me any more since 9ed0d11.

@jieyouxu jieyouxu added A-linkage Area: linking into static, shared libraries and binaries A-linkers Area: linkers... you gotta love linkers labels Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries A-linkers Area: linkers... you gotta love linkers C-bug Category: This is a bug. O-Arm Target: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 state O-musl Target: The musl libc P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. 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