Repository: rust
Issue: rustc hides linker warnings
Labels: A-linkage,C-enhancement,T-compiler

I encountered an issue with the [linkme](https://github.com/dtolnay/linkme) crate on illumos (OpenSolaris/OmniOS/Helios) demonstrated with [this repo](https://github.com/ahl/linkme-test). Of note, the build executes without error or warning, but in fact the linker is emitting an error:

```
$ cargo run
   Compiling cmd v0.1.0 (/home/ahl/linkme-test/cmd)
    Finished dev [unoptimized + debuginfo] target(s) in 0.28s
     Running `target/debug/cmd`
$ cargo rustc
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
```

I can make the linker fail on warnings:

```
$ cargo rustc -- -C link-arg=-Wl,-zfatal-warnings
   Compiling cmd v0.1.0 (/home/ahl/linkme-test/cmd)
error: linking with `gcc` failed: exit code: 1
  |
  = note: "gcc" "-m64" "-std=c99" "-L" "/opt/ooce/rust/lib/rustlib/x86_64-unknown-illumos/lib" "/home/ahl/linkme-test/cmd/target/debug/deps/cmd-26e8351dc3f3fb69.1m65hci6o5zni2mr.rcgu.o" "/home/ahl/linkme-test/cmd/target/debug/deps/cmd-26e8351dc3f3fb69.1r2sofzghiioxykg.rcgu.o" "/home/ahl/linkme-test/cmd/target/debug/deps/cmd-26e8351dc3f3fb69.2i3xjlynwxgqlmzu.rcgu.o" "/home/ahl/linkme-test/cmd/target/debug/deps/cmd-26e8351dc3f3fb69.3hvsf4zj59kihrhf.rcgu.o" "/home/ahl/linkme-test/cmd/target/debug/deps/cmd-26e8351dc3f3fb69.3lsh1pzemq0xblzm.rcgu.o" "/home/ahl/linkme-test/cmd/target/debug/deps/cmd-26e8351dc3f3fb69.3zpatajw7m7uqqns.rcgu.o" "/home/ahl/linkme-test/cmd/target/debug/deps/cmd-26e8351dc3f3fb69.4yxic0y84aboqmeb.rcgu.o" "/home/ahl/linkme-test/cmd/target/debug/deps/cmd-26e8351dc3f3fb69.a1lfmxsp6lqzsbn.rcgu.o" "-o" "/home/ahl/linkme-test/cmd/target/debug/deps/cmd-26e8351dc3f3fb69" "/home/ahl/linkme-test/cmd/target/debug/deps/cmd-26e8351dc3f3fb69.3n70o9wfzqm9tbsh.rcgu.o" "-Wl,-zignore" "-nodefaultlibs" "-L" "/home/ahl/linkme-test/cmd/target/debug/deps" "-L" "/opt/ooce/rust/lib/rustlib/x86_64-unknown-illumos/lib" "-Wl,-Bstatic" "/home/ahl/linkme-test/cmd/target/debug/deps/liblib-3d689bd64c3873d5.rlib" "/home/ahl/linkme-test/cmd/target/debug/deps/liblinkme-21c998585e123796.rlib" "-Wl,--start-group" "/opt/ooce/rust/lib/rustlib/x86_64-unknown-illumos/lib/libstd-cd23cc7e75a2851c.rlib" "/opt/ooce/rust/lib/rustlib/x86_64-unknown-illumos/lib/libpanic_unwind-566bad254d0594e5.rlib" "/opt/ooce/rust/lib/rustlib/x86_64-unknown-illumos/lib/libminiz_oxide-96e54319d1590148.rlib" "/opt/ooce/rust/lib/rustlib/x86_64-unknown-illumos/lib/libadler-4dbe2335326bb316.rlib" "/opt/ooce/rust/lib/rustlib/x86_64-unknown-illumos/lib/libobject-b0fd875741b20fc0.rlib" "/opt/ooce/rust/lib/rustlib/x86_64-unknown-illumos/lib/libaddr2line-089ce7b4c263282a.rlib" "/opt/ooce/rust/lib/rustlib/x86_64-unknown-illumos/lib/libgimli-ca92a564b7883a12.rlib" "/opt/ooce/rust/lib/rustlib/x86_64-unknown-illumos/lib/librustc_demangle-ce8ee413f3ea18b6.rlib" "/opt/ooce/rust/lib/rustlib/x86_64-unknown-illumos/lib/libhashbrown-17e15682bef35ec2.rlib" "/opt/ooce/rust/lib/rustlib/x86_64-unknown-illumos/lib/librustc_std_workspace_alloc-2dc950a425ee77d8.rlib" "/opt/ooce/rust/lib/rustlib/x86_64-unknown-illumos/lib/libunwind-50867a64287c1bd2.rlib" "/opt/ooce/rust/lib/rustlib/x86_64-unknown-illumos/lib/libcfg_if-129bada4e936c5a0.rlib" "/opt/ooce/rust/lib/rustlib/x86_64-unknown-illumos/lib/liblibc-a98e4fa0f203a39a.rlib" "/opt/ooce/rust/lib/rustlib/x86_64-unknown-illumos/lib/liballoc-35c480f88f8f320a.rlib" "/opt/ooce/rust/lib/rustlib/x86_64-unknown-illumos/lib/librustc_std_workspace_core-86dc76527c7e216a.rlib" "/opt/ooce/rust/lib/rustlib/x86_64-unknown-illumos/lib/libcore-093275d7382c1a2f.rlib" "-Wl,--end-group" "/opt/ooce/rust/lib/rustlib/x86_64-unknown-illumos/lib/libcompiler_builtins-358913705748e96c.rlib" "-Wl,-Bdynamic" "-lsocket" "-lposix4" "-lpthread" "-lresolv" "-lnsl" "-lumem" "-lgcc_s" "-lc" "-lm" "-lrt" "-lpthread" "-Wl,-zfatal-warnings" "-lssp"
  = note: ld: warning: reserved symbol '__start_set_linkme_DOERS' already defined in file /home/ahl/linkme-test/cmd/target/debug/deps/liblib-3d689bd64c3873d5.rlib(lib-3d689bd64c3873d5.2vwi8dtk7ky9hvmq.rcgu.o)
          ld: warning: reserved symbol '__stop_set_linkme_DOERS' already defined in file /home/ahl/linkme-test/cmd/target/debug/deps/liblib-3d689bd64c3873d5.rlib(lib-3d689bd64c3873d5.2vwi8dtk7ky9hvmq.rcgu.o)
          collect2: error: ld returned 1 exit status
          

error: aborting due to previous error

error: could not compile `cmd`.

To learn more, run the command again with --verbose.
```

These linker warnings need not have been fatal, but I think it would be reasonable for `cargo build` / `cargo run` / `cargo rustc` to display these warnings. In this case those warnings would have helped determine the underlying issues much earlier. Indeed, it seems rare that linker warnings would truly be specious.

### Meta
<!--
If you're using the stable version of the compiler, you should also check if the
bug also exists in the beta or nightly versions.
-->

`rustc --version --verbose`:
```
$ rustc --version --verbose
rustc 1.47.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-illumos
release: 1.47.0
LLVM version: 11.0
```