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

Musl linker regression: undefined reference to X #61328

Open
jesskfullwood opened this issue May 29, 2019 · 8 comments
Open

Musl linker regression: undefined reference to X #61328

jesskfullwood opened this issue May 29, 2019 · 8 comments
Labels
A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. O-musl Target: The musl libc T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jesskfullwood
Copy link

... where X is things like 'printf', i.e. symbols that clearly should exist.

This looks similar to other reported bugs, particularly #58163, but this one a) used to work until Rust 1.32 and b) is not embedded/no-std.

Using my nlopt library to reproduce. You will need musl installed. I am running linux/ubuntu 18.04. Disclaimer: I am no expert and I may have completely messed up how linking etc is supposed to be done.

uname -srv
> Linux 4.15.0-47-generic #50-Ubuntu SMP Wed Mar 13 10:44:52 UTC 2019

git clone https://github.com/jesskfullwood/rust-nlopt
cd rust-nlopt
git checkout 33867

It works on this nightly:

rustup default nightly-2018-11-09
rustup target add x86_64-unknown-linux-musl
cargo clean && cargo test --target=x86_64-unknown-linux-musl
<tests pass>

But barfs on the next nightly:

rustup default nightly-2018-11-10
rustup target add x86_64-unknown-linux-musl
cargo clean && cargo test --target=x86_64-unknown-linux-musl

with the following:

error: aborting due to previous error

error: Could not compile `nlopt`.
warning: build failed, waiting for other jobs to finish...
error: build failed

   Compiling autocfg v0.1.4
   Compiling cc v1.0.37
   Compiling num-traits v0.2.8
   Compiling num-integer v0.1.41
   Compiling num-iter v0.1.39
   Compiling cmake v0.1.40
   Compiling nlopt v0.5.1 (/tmp/rust-nlopt)
error: linking with `cc` failed: exit code: 1
  |
  = note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-Wl,--eh-frame-hdr" "-m64" "-nostdlib" "/home/jess/.rustup/toolchains/nightly-2018-11-10-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/crt1.o" "/home/jess/.rustup/toolchains/nightly-2018-11-10-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/crti.o" "-L" "/home/jess/.rustup/toolchains/nightly-2018-11-10-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.14s2lheoldkje1zl.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.1bfyca7a66fh03ff.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.1ejxjx9qzw1ofj02.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.1n0ti6hpbbgtpp4z.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.1ukutu1unhj01np4.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.208cfp4j1odm6m.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.2745i3y0bgggfjwk.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.2grpigfweo3wxdu8.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.2ih6i921axz5pgnz.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.2n4ylmz66rkoudwl.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.30azlphyz0kybejb.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.38qu6bor0nolqc2r.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.3eyi8it1pjw27v13.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.3w85went8cld85o6.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.3ytbt54x8n96t06f.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.48notlrrz2lbiurk.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.4bfnimi5qjjtua8c.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.4hm8svgbs5b1kyrk.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.4kjuqsgnulx4m1ie.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.4mmlshz1v32xcre1.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.4sdp19mllypu8ug8.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.4taymo7lm3kum6xn.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.558jj00qf16ji6df.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.5cjzludnbcp9nfqs.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.9nud5ngp9ki3eh1.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.ar2if93dwawmlri.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.h9wf4l9h2p8bbr5.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.n1q5b6do3g3diad.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.qn1upqn7sme4b1a.rcgu.o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.v3owoque0qy03dw.rcgu.o" "-o" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/examples/bobyqa-0682eb7b948640a5.1ty8hmhu2u3mgb5a.rcgu.o" "-Wl,--gc-sections" "-no-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" "-L" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/deps" "-L" "/tmp/rust-nlopt/target/debug/deps" "-L" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/build/nlopt-c7a0f04735c5c50a/out/lib" "-L" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/build/nlopt-c7a0f04735c5c50a/out/lib64" "-L" "/home/jess/.rustup/toolchains/nightly-2018-11-10-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib" "-Wl,-Bstatic" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/deps/libnum_iter-2954ee9e83fb6868.rlib" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/deps/libnum_integer-93226606e5fd3689.rlib" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/deps/libnum_traits-139d05e55d3b65d2.rlib" "/tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/deps/libnlopt-e7f258d63c4f98ca.rlib" "/home/jess/.rustup/toolchains/nightly-2018-11-10-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd-4e91f42d53bc51fa.rlib" "/home/jess/.rustup/toolchains/nightly-2018-11-10-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libpanic_unwind-df141ca967efcefb.rlib" "/home/jess/.rustup/toolchains/nightly-2018-11-10-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libunwind-196b7ce4dc743d20.rlib" "/home/jess/.rustup/toolchains/nightly-2018-11-10-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/liballoc_system-803b7984275cae77.rlib" "/home/jess/.rustup/toolchains/nightly-2018-11-10-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/liblibc-93b2e38ef7f09e53.rlib" "/home/jess/.rustup/toolchains/nightly-2018-11-10-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/liballoc-13730a716946b8e6.rlib" "/home/jess/.rustup/toolchains/nightly-2018-11-10-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libcore-1ac500a2d5e8ab22.rlib" "/home/jess/.rustup/toolchains/nightly-2018-11-10-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libcompiler_builtins-b4f8b059041e6a22.rlib" "-Wl,-Bdynamic" "-lnlopt" "-lnlopt" "-static" "/home/jess/.rustup/toolchains/nightly-2018-11-10-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/crtn.o"
  = note: /tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/build/nlopt-c7a0f04735c5c50a/out/lib/libnlopt.a(timer.c.o): In function `nlopt_seconds':
          /tmp/rust-nlopt/nlopt-2.5.0/src/util/timer.c:49: undefined reference to `gettimeofday'
          /tmp/rust-nlopt/nlopt-2.5.0/src/util/timer.c:51: undefined reference to `gettimeofday'
          /tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/build/nlopt-c7a0f04735c5c50a/out/lib/libnlopt.a(timer.c.o): In function `nlopt_time_seed':
          /tmp/rust-nlopt/nlopt-2.5.0/src/util/timer.c:82: undefined reference to `gettimeofday'
          /tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/build/nlopt-c7a0f04735c5c50a/out/lib/libnlopt.a(stop.c.o): In function `nlopt_istiny':
          /tmp/rust-nlopt/nlopt-2.5.0/src/util/stop.c:194: undefined reference to `__fpclassify'
          /tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/build/nlopt-c7a0f04735c5c50a/out/lib/libnlopt.a(pssubs.c.o): In function `luksan_pulvp3__':
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/luksan/pssubs.c:747: undefined reference to `copysign'
          /tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/build/nlopt-c7a0f04735c5c50a/out/lib/libnlopt.a(mlsl.c.o): In function `mlsl_minimize':
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/mlsl/mlsl.c:378: undefined reference to `log'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/mlsl/mlsl.c:382: undefined reference to `ceil'
          /tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/build/nlopt-c7a0f04735c5c50a/out/lib/libnlopt.a(mma.c.o): In function `mma_minimize':
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/mma/mma.c:282: undefined reference to `printf'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/mma/mma.c:285: undefined reference to `printf'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/mma/mma.c:322: undefined reference to `puts'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/mma/mma.c:364: undefined reference to `printf'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/mma/mma.c:366: undefined reference to `printf'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/mma/mma.c:378: undefined reference to `printf'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/mma/mma.c:382: undefined reference to `printf'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/mma/mma.c:394: undefined reference to `printf'
          /tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/build/nlopt-c7a0f04735c5c50a/out/lib/libnlopt.a(ccsa_quadratic.c.o): In function `dual_func':
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/mma/ccsa_quadratic.c:126: undefined reference to `copysign'
          /tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/build/nlopt-c7a0f04735c5c50a/out/lib/libnlopt.a(ccsa_quadratic.c.o): In function `ccsa_quadratic_minimize':
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/mma/ccsa_quadratic.c:436: undefined reference to `printf'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/mma/ccsa_quadratic.c:439: undefined reference to `printf'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/mma/ccsa_quadratic.c:471: undefined reference to `puts'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/mma/ccsa_quadratic.c:512: undefined reference to `printf'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/mma/ccsa_quadratic.c:514: undefined reference to `printf'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/mma/ccsa_quadratic.c:526: undefined reference to `printf'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/mma/ccsa_quadratic.c:530: undefined reference to `printf'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/mma/ccsa_quadratic.c:544: undefined reference to `printf'
          /tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/build/nlopt-c7a0f04735c5c50a/out/lib/libnlopt.a(cobyla.c.o): In function `cobylb':
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/cobyla/cobyla.c:621: undefined reference to `fputc'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/cobyla/cobyla.c:1197: undefined reference to `fputc'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/cobyla/cobyla.c:1237: undefined reference to `fputc'
          /tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/build/nlopt-c7a0f04735c5c50a/out/lib/libnlopt.a(newuoa.c.o): In function `bigden_':
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/newuoa/newuoa.c:573: undefined reference to `atan'
          /tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/build/nlopt-c7a0f04735c5c50a/out/lib/libnlopt.a(newuoa.c.o): In function `biglag_':
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/newuoa/newuoa.c:1117: undefined reference to `atan'
          /tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/build/nlopt-c7a0f04735c5c50a/out/lib/libnlopt.a(sbplx.c.o): In function `sbplx_minimize':
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/neldermead/sbplx.c:161: undefined reference to `printf'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/neldermead/sbplx.c:182: undefined reference to `printf'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/neldermead/sbplx.c:228: undefined reference to `printf'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/neldermead/sbplx.c:231: undefined reference to `copysign'
          /tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/build/nlopt-c7a0f04735c5c50a/out/lib/libnlopt.a(auglag.c.o): In function `auglag_minimize':
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/auglag/auglag.c:183: undefined reference to `printf'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/auglag/auglag.c:184: undefined reference to `printf'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/auglag/auglag.c:185: undefined reference to `printf'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/auglag/auglag.c:186: undefined reference to `printf'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/auglag/auglag.c:187: undefined reference to `putchar'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/auglag/auglag.c:198: undefined reference to `printf'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/auglag/auglag.c:206: undefined reference to `printf'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/auglag/auglag.c:244: undefined reference to `printf'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/auglag/auglag.c:246: undefined reference to `printf'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/auglag/auglag.c:247: undefined reference to `printf'
          /tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/build/nlopt-c7a0f04735c5c50a/out/lib/libnlopt.a(auglag.c.o):/tmp/rust-nlopt/nlopt-2.5.0/src/algs/auglag/auglag.c:248: more undefined references to `printf' follow
          /tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/build/nlopt-c7a0f04735c5c50a/out/lib/libnlopt.a(auglag.c.o): In function `auglag_minimize':
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/auglag/auglag.c:249: undefined reference to `putchar'
          /tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/build/nlopt-c7a0f04735c5c50a/out/lib/libnlopt.a(isres.c.o): In function `isres_minimize':
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/isres/isres.c:93: undefined reference to `ceil'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/isres/isres.c:242: undefined reference to `exp'
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/isres/isres.c:268: undefined reference to `exp'
          /tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/build/nlopt-c7a0f04735c5c50a/out/lib/libnlopt.a(esch.c.o): In function `randcauchy':
          /tmp/rust-nlopt/nlopt-2.5.0/src/algs/esch/esch.c:39: undefined reference to `tan'
          /tmp/rust-nlopt/target/x86_64-unknown-linux-musl/debug/build/nlopt-c7a0f04735c5c50a/out/lib/libnlopt.a(mt19937ar.c.o): In function `nlopt_nrand':
          /tmp/rust-nlopt/nlopt-2.5.0/src/util/mt19937ar.c:230: undefined reference to `log'
          collect2: error: ld returned 1 exit status
          

error: aborting due to previous error

error: Could not compile `nlopt`.
warning: build failed, waiting for other jobs to finish...
error: build failed
@Centril Centril added O-musl Target: The musl libc A-linkage Area: linking into static, shared libraries and binaries C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 30, 2019
@Diggsey
Copy link
Contributor

Diggsey commented Jun 2, 2019

I have this issue too - I believe the issue is that liblibc appears on the linker command line before any C libraries, which means that any parts of libc which are used by a C library, but not by the rust code will be missing.

@jesskfullwood
Copy link
Author

Ah, that will be it! The breakage is due to changes in the grouping rules in PR #55659

@mati865
Copy link
Contributor

mati865 commented Jun 3, 2019

cc @alexcrichton

@Diggsey
Copy link
Contributor

Diggsey commented Jun 3, 2019

Another casualty of rustc's bundling behaviour...

@rrichardson
Copy link

Is there a workaround for this? I guess manually build link-args in .cargo/config?

@jesskfullwood
Copy link
Author

My 'workaround' is to use the last working version, 1.31.0. Would be interested in a proper workaround.

@mathstuf
Copy link
Contributor

Note that this is affecting native aarch64 compilation on Alpine:

  = note: /usr/lib/gcc/aarch64-alpine-linux-musl/10.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: /root/sccache/src/target/aarch64-unknown-linux-musl/release/deps/libopenssl_sys-fcc8125410f43229.rlib(ssl_cert.o): in function `ssl_cert_free':
          ssl_cert.c:(.text.ssl_cert_free+0x1c): undefined reference to `__aarch64_ldadd4_relax'
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: /root/sccache/src/target/aarch64-unknown-linux-musl/release/deps/libopenssl_sys-fcc8125410f43229.rlib(ssl_lib.o): in function `SSL_CTX_up_ref':
          ssl_lib.c:(.text.SSL_CTX_up_ref+0x14): undefined reference to `__aarch64_ldadd4_relax'
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: /root/sccache/src/target/aarch64-unknown-linux-musl/release/deps/libopenssl_sys-fcc8125410f43229.rlib(ssl_lib.o): in function `SSL_CTX_free':
          ssl_lib.c:(.text.SSL_CTX_free+0x1c): undefined reference to `__aarch64_ldadd4_relax'
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: /root/sccache/src/target/aarch64-unknown-linux-musl/release/deps/libopenssl_sys-fcc8125410f43229.rlib(ssl_lib.o): in function `SSL_free':
          ssl_lib.c:(.text.SSL_free+0x1c): undefined reference to `__aarch64_ldadd4_relax'
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: /root/sccache/src/target/aarch64-unknown-linux-musl/release/deps/libopenssl_sys-fcc8125410f43229.rlib(ssl_sess.o): in function `SSL_SESSION_free':
          ssl_sess.c:(.text.SSL_SESSION_free+0x1c): undefined reference to `__aarch64_ldadd4_relax'
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: /root/sccache/src/target/aarch64-unknown-linux-musl/release/deps/libopenssl_sys-fcc8125410f43229.rlib(ssl_sess.o):ssl_sess.c:(.text.SSL_SESSION_up_ref+0x14): more undefined references to `__aarch64_ldadd4_relax' follow
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: /root/sccache/src/target/aarch64-unknown-linux-musl/release/deps/libopenssl_sys-fcc8125410f43229.rlib(lhash.o): in function `getrn':
          lhash.c:(.text.getrn+0x3c): undefined reference to `__aarch64_ldadd8_relax'
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: lhash.c:(.text.getrn+0x94): undefined reference to `__aarch64_ldadd8_relax'
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: lhash.c:(.text.getrn+0xac): undefined reference to `__aarch64_ldadd8_relax'
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: /root/sccache/src/target/aarch64-unknown-linux-musl/release/deps/libopenssl_sys-fcc8125410f43229.rlib(lhash.o): in function `OPENSSL_LH_retrieve':
          lhash.c:(.text.OPENSSL_LH_retrieve+0x48): undefined reference to `__aarch64_ldadd8_relax'
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: lhash.c:(.text.OPENSSL_LH_retrieve+0x80): undefined reference to `__aarch64_ldadd8_relax'
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: /root/sccache/src/target/aarch64-unknown-linux-musl/release/deps/libopenssl_sys-fcc8125410f43229.rlib(drbg_lib.o): in function `RAND_DRBG_instantiate':
          drbg_lib.c:(.text.RAND_DRBG_instantiate+0x2d8): undefined reference to `__aarch64_ldadd4_relax'
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: /root/sccache/src/target/aarch64-unknown-linux-musl/release/deps/libopenssl_sys-fcc8125410f43229.rlib(drbg_lib.o): in function `RAND_DRBG_reseed':
          drbg_lib.c:(.text.RAND_DRBG_reseed+0x20c): undefined reference to `__aarch64_ldadd4_relax'
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: /root/sccache/src/target/aarch64-unknown-linux-musl/release/deps/libopenssl_sys-fcc8125410f43229.rlib(rsa_lib.o): in function `RSA_free':
          rsa_lib.c:(.text.RSA_free+0x1c): undefined reference to `__aarch64_ldadd4_relax'
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: /root/sccache/src/target/aarch64-unknown-linux-musl/release/deps/libopenssl_sys-fcc8125410f43229.rlib(threads_pthread.o): in function `CRYPTO_atomic_add':
          threads_pthread.c:(.text.CRYPTO_atomic_add+0x1c): undefined reference to `__aarch64_ldadd4_acq_rel'
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: /root/sccache/src/target/aarch64-unknown-linux-musl/release/deps/libopenssl_sys-fcc8125410f43229.rlib(x509_lu.o): in function `X509_STORE_free':
          x509_lu.c:(.text.X509_STORE_free+0x1c): undefined reference to `__aarch64_ldadd4_relax'
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: /root/sccache/src/target/aarch64-unknown-linux-musl/release/deps/libopenssl_sys-fcc8125410f43229.rlib(x509_lu.o): in function `X509_STORE_up_ref':
          x509_lu.c:(.text.X509_STORE_up_ref+0x14): undefined reference to `__aarch64_ldadd4_relax'
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: /root/sccache/src/target/aarch64-unknown-linux-musl/release/deps/libopenssl_sys-fcc8125410f43229.rlib(x509_set.o): in function `X509_up_ref':
          x509_set.c:(.text.X509_up_ref+0x14): undefined reference to `__aarch64_ldadd4_relax'
          /usr/lib/gcc/aarch64-alpine-linux-musl/10.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: /root/sccache/src/target/aarch64-unknown-linux-musl/release/deps/libopenssl_sys-fcc8125410f43229.rlib(x509cset.o): in function `X509_CRL_up_ref':
          x509cset.c:(.text.X509_CRL_up_ref+0x14): undefined reference to `__aarch64_ldadd4_relax'
          collect2: error: ld returned 1 exit status

@zachs18
Copy link
Contributor

zachs18 commented Feb 17, 2023

Unsure if this is a duplicate issue, so I'll post it here: cc: @Nilstrieb (talked about it on discord)

I tried this code: (host: x86_64-unknown-linux-gnu)

# .cargo/config.coml
[build]
target = "x86_64-unknown-linux-musl"
[target.x86_64-unknown-linux-musl]
rustflags = ["-C", "target-feature=-crt-static"]
// main.rs
fn main() {
  println!("{}", std::hint::black_box(45.0f64).exp());
}

$ cargo run

I expected to see this happen: Compiles, prints a large number, and exits successfully.

Instead, this happened: A linker error:

in function `std::f64::<impl f64>::exp': <path elided>: undefined reference to `exp'

The error only happens with -C target-feature=-crt-static. I do not get the error with no flags, or with -C target-feature=+crt-static.

Full `cargo b` output
   Compiling mwe v0.1.0 (/tmp/mwe)
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m64" "/tmp/rustcanItBR/symbols.o" "/tmp/mwe/target/x86_64-unknown-linux-musl/debug/deps/mwe-7ab7d34b782c4984.1jbdl9ewmgou3qss.rcgu.o" "/tmp/mwe/target/x86_64-unknown-linux-musl/debug/deps/mwe-7ab7d34b782c4984.3bkufp5ayoovmsjz.rcgu.o" "/tmp/mwe/target/x86_64-unknown-linux-musl/debug/deps/mwe-7ab7d34b782c4984.3s3ui762bb8v5k6h.rcgu.o" "/tmp/mwe/target/x86_64-unknown-linux-musl/debug/deps/mwe-7ab7d34b782c4984.3yech3ri0qsd0we0.rcgu.o" "/tmp/mwe/target/x86_64-unknown-linux-musl/debug/deps/mwe-7ab7d34b782c4984.42u6h7rmhbj77ecb.rcgu.o" "/tmp/mwe/target/x86_64-unknown-linux-musl/debug/deps/mwe-7ab7d34b782c4984.4idiabkpjrzxfapz.rcgu.o" "/tmp/mwe/target/x86_64-unknown-linux-musl/debug/deps/mwe-7ab7d34b782c4984.4pyszlzsp165olrz.rcgu.o" "/tmp/mwe/target/x86_64-unknown-linux-musl/debug/deps/mwe-7ab7d34b782c4984.52q67tczlqsj17n4.rcgu.o" "/tmp/mwe/target/x86_64-unknown-linux-musl/debug/deps/mwe-7ab7d34b782c4984.7ml3j3v72z4fl6i.rcgu.o" "/tmp/mwe/target/x86_64-unknown-linux-musl/debug/deps/mwe-7ab7d34b782c4984.1dbjfjb9jx96u6xn.rcgu.o" "-Wl,--as-needed" "-L" "/tmp/mwe/target/x86_64-unknown-linux-musl/debug/deps" "-L" "/tmp/mwe/target/debug/deps" "-L" "/<redacted>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib" "-Wl,-Bstatic" "/<redacted>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd-86aefecbddda356d.rlib" "/<redacted>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libpanic_unwind-3d55d9622a2f5140.rlib" "/<redacted>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libobject-7aa31308145aea0a.rlib" "/<redacted>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libmemchr-8c385129ceceaff7.rlib" "/<redacted>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libaddr2line-3a9d0b46a4afc5ce.rlib" "/<redacted>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libgimli-5c4e1c7dd1c36634.rlib" "/<redacted>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_demangle-85de0c518ec91e8f.rlib" "/<redacted>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd_detect-2eeeecc93705146d.rlib" "/<redacted>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libhashbrown-990303a257faf081.rlib" "/<redacted>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libminiz_oxide-3639a8245c3cc653.rlib" "/<redacted>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libadler-8dbe6ab28e534b48.rlib" "/<redacted>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_alloc-dd6269f764aa51a6.rlib" "/<redacted>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libunwind-53c0377c886910ca.rlib" "/<redacted>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libcfg_if-68da8aade85f8514.rlib" "/<redacted>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/liblibc-f8cfdefff46a260d.rlib" "/<redacted>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/liballoc-d2c87b1633315b15.rlib" "/<redacted>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_core-37886685c2c3c64f.rlib" "/<redacted>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libcore-5c96c3c09cedb260.rlib" "/<redacted>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib/libcompiler_builtins-8917dd2a6ba09b28.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/<redacted>/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-musl/lib" "-o" "/tmp/mwe/target/x86_64-unknown-linux-musl/debug/deps/mwe-7ab7d34b782c4984" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
  = note: /usr/bin/ld: /tmp/mwe/target/x86_64-unknown-linux-musl/debug/deps/mwe-7ab7d34b782c4984.52q67tczlqsj17n4.rcgu.o: in function `std::f64::<impl f64>::exp':
          /rustc/d5a82bbd26e1ad8b7401f6a718a9c57c96905483/library/std/src/f64.rs:386: undefined reference to `exp'
          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#cargorustc-link-libkindname)

error: could not compile `mwe` due to previous error

Meta

rustc --version --verbose:

rustc 1.67.1 (d5a82bbd2 2023-02-07)
binary: rustc
commit-hash: d5a82bbd26e1ad8b7401f6a718a9c57c96905483
commit-date: 2023-02-07
host: x86_64-unknown-linux-gnu
release: 1.67.1
LLVM version: 15.0.6

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 C-bug Category: This is a bug. O-musl Target: The musl libc 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

7 participants