Repository: rust
Issue: rlib -> cdylib -> rlib+cydylib crate dependency graph causes pain
Labels: A-linkage,T-compiler,C-bug

<!--
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
along with any information you feel relevant to replicating the bug.
-->

I tried this code:

[repro.zip](https://github.com/rust-lang/rust/files/9446523/repro.zip)

I expected to see this happen: It compiles fine

Instead, this happened:

```
error: linking with `cc` failed: exit status: 1
  |
  = note: "cc" "-m64" "/tmp/rustctEbsbD/symbols.o" "/home/bjorn/Projects/fyrox_dylib_linker_error_repro/target/debug/deps/fyrox_dylib_linker_error_repro-4ed01b7abb82a550.1abx1df6m92bi1db.rcgu.o" "/home/bjorn/Projects/fyrox_dylib_linker_error_repro/target/debug/deps/fyrox_dylib_linker_error_repro-4ed01b7abb82a550.1j29z93v70i7bjcp.rcgu.o" "/home/bjorn/Projects/fyrox_dylib_linker_error_repro/target/debug/deps/fyrox_dylib_linker_error_repro-4ed01b7abb82a550.2i0s8ns9zvk8rtm3.rcgu.o" "/home/bjorn/Projects/fyrox_dylib_linker_error_repro/target/debug/deps/fyrox_dylib_linker_error_repro-4ed01b7abb82a550.2r3sttgq70dy445l.rcgu.o" "/home/bjorn/Projects/fyrox_dylib_linker_error_repro/target/debug/deps/fyrox_dylib_linker_error_repro-4ed01b7abb82a550.32rhsco2u177cdbz.rcgu.o" "/home/bjorn/Projects/fyrox_dylib_linker_error_repro/target/debug/deps/fyrox_dylib_linker_error_repro-4ed01b7abb82a550.33jgn96fsanc6p4r.rcgu.o" "-Wl,--as-needed" "-L" "/home/bjorn/Projects/fyrox_dylib_linker_error_repro/target/debug/deps" "-L" "/home/bjorn/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-L" "/home/bjorn/Projects/fyrox_dylib_linker_error_repro/target/debug/deps" "-lfyrox_dylib" "-L" "/home/bjorn/Projects/fyrox_dylib_linker_error_repro/target/debug/deps" "-lsysinfo-5034accfd102eed6" "-Wl,--start-group" "-L" "/home/bjorn/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-lstd-69edc9ac8de4d39c" "-Wl,--end-group" "-Wl,-Bstatic" "/home/bjorn/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-d1bd89f2a607e488.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/bjorn/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/bjorn/Projects/fyrox_dylib_linker_error_repro/target/debug/deps/fyrox_dylib_linker_error_repro-4ed01b7abb82a550" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
  = note: /usr/bin/ld: /home/bjorn/Projects/fyrox_dylib_linker_error_repro/target/debug/deps/libfyrox_dylib.so: undefined reference to `<alloc::vec::Vec<T,A> as core::ops::deref::DerefMut>::deref_mut'
          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)

warning: `fyrox_dylib_linker_error_repro` (bin "fyrox_dylib_linker_error_repro") generated 1 warning
error: could not compile `fyrox_dylib_linker_error_repro` due to previous error; 1 warning emitted
```

### 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 1.62.1 (e092d0b6b 2022-07-16)
binary: rustc
commit-hash: e092d0b6b43f2de967af0887873151bb1c0b18d3
commit-date: 2022-07-16
host: x86_64-unknown-linux-gnu
release: 1.62.1
LLVM version: 14.0.5
```

Minimized from https://old.reddit.com/r/rust/comments/wz245y/how_to_link_a_library_dynamically_running_into/