Repository: rust
Issue: Musl linker regression: undefined reference to X
Labels: A-linkage,T-compiler,O-musl,C-bug

... where X is things like 'printf', i.e. symbols that clearly should exist.

This looks similar to other reported bugs, particularly https://github.com/rust-lang/rust/issues/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
```