Repository: rust
Issue: Missing linker symbols with incremental build 
Labels: T-compiler,A-incr-comp,C-bug

I'm compiling a project of mine with both --release and incremental. And after a certain code change i'm getting linker errors:

```
PS D:\work\my\albion\sniffer> cargo run --release
   Compiling sniffer v0.1.0 (D:\work\my\albion\sniffer)
error: linking with `link.exe` failed: exit code: 1120
  |
  = note: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\BuildTools\\VC\\Tools\\MSVC\\14.26.28801\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "/NXCOMPAT" "/LIBPATH:D:\\home\\moxian\\rust\\.rustup\\toolchains\\beta-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib"  <... snip ...>
  = note: libsniffer-1f897fa40e892028.rlib(sniffer-1f897fa40e892028.ri0tzytpav84n1w.rcgu.o) : error LNK2019: unresolved external symbol anon.6332b924f15aa3d6e5bef19c35c54ec9.10.llvm.1829802709914840201 referenced in function _ZN7sniffer7packets4main17h3121e6c4a4169b77E
          libsniffer-1f897fa40e892028.rlib(sniffer-1f897fa40e892028.ri0tzytpav84n1w.rcgu.o) : error LNK2019: unresolved external symbol _ZN5alloc5alloc8box_free17hf4dd4181cdb3fd91E.llvm.6496271291016794642 referenced in function "?dtor$81@?0?_ZN7sniffer7packets4main17h3121e6c4a4169b77E@4HA" (?dtor$81@?0?_ZN7sniffer7packets4main17h3121e6c4a4169b77E@4HA)
          libsniffer-1f897fa40e892028.rlib(sniffer-1f897fa40e892028.1o5cshk94pnqtlbw.rcgu.o) : error LNK2019: unresolved external symbol _ZN4core3ptr102drop_in_place$LT$core..cell..UnsafeCell$LT$core..option..Option$LT$ureq..agent..AgentState$GT$$GT$$GT$17hc9fc39f466bd12f2E.llvm.6496271291016794642 referenced in function _ZN5alloc4sync12Arc$LT$T$GT$9drop_slow17haa27bece84a3b036E
          libsniffer-1f897fa40e892028.rlib(sniffer-1f897fa40e892028.1ulx0gd4gpg6ped4.rcgu.o) : error LNK2019: unresolved external symbol _ZN5alloc5alloc8box_free17h96e4bccad33a7f47E.llvm.6496271291016794642 referenced in function "?dtor$22@?0?_ZN3std2io5Write9write_all17h835503b886efd9aaE@4HA" (?dtor$22@?0?_ZN3std2io5Write9write_all17h835503b886efd9aaE@4HA)
          libsniffer-1f897fa40e892028.rlib(sniffer-1f897fa40e892028.47hnchh97h3d91cv.rcgu.o) : error LNK2001: unresolved external symbol _ZN5alloc5alloc8box_free17h96e4bccad33a7f47E.llvm.6496271291016794642
          libsniffer-1f897fa40e892028.rlib(sniffer-1f897fa40e892028.1ulx0gd4gpg6ped4.rcgu.o) : error LNK2019: unresolved external symbol _ZN5alloc5alloc8box_free17ha9abda466de5afb4E.llvm.6496271291016794642 referenced in function "?dtor$23@?0?_ZN3std2io5Write9write_all17h835503b886efd9aaE@4HA" (?dtor$23@?0?_ZN3std2io5Write9write_all17h835503b886efd9aaE@4HA)
          libsniffer-1f897fa40e892028.rlib(sniffer-1f897fa40e892028.47hnchh97h3d91cv.rcgu.o) : error LNK2001: unresolved external symbol _ZN5alloc5alloc8box_free17ha9abda466de5afb4E.llvm.6496271291016794642
          libsniffer-1f897fa40e892028.rlib(sniffer-1f897fa40e892028.4bnh2h6cfq27ljgy.rcgu.o) : error LNK2019: unresolved external symbol _ZN5alloc5alloc8box_free17hdb705d5ba99e436cE.llvm.6496271291016794642 referenced in function "?dtor$4@?0?_ZN6anyhow5error11object_drop17h67921f8718882a26E@4HA" (?dtor$4@?0?_ZN6anyhow5error11object_drop17h67921f8718882a26E@4HA)
          libsniffer-1f897fa40e892028.rlib(sniffer-1f897fa40e892028.4bnh2h6cfq27ljgy.rcgu.o) : error LNK2019: unresolved external symbol _ZN5alloc5alloc8box_free17h39327b260da2ce17E.llvm.6496271291016794642 referenced in function "?dtor$6@?0?_ZN6anyhow5error23context_chain_drop_rest17h5082e4e95cf28ce0E@4HA" (?dtor$6@?0?_ZN6anyhow5error23context_chain_drop_rest17h5082e4e95cf28ce0E@4HA)
          D:\work\my\albion\sniffer\target\release\deps\main.exe : fatal error LNK1120: 7 unresolved externals


error: aborting due to previous error

error: could not compile `sniffer`

Caused by:
  process didn't exit successfully: `rustc --crate-name main --edition=2018 bin/main.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=3 -C embed-bitcode=no -C metadata=481f72205232162d --out-dir D:\work\my\albion\sniffer-state-b\target\release\deps -C incremental=D:\work\my\albion\sniffer-state-b\target\release\incremental -L dependency=D:\work\my\albion\sniffer-state-b\target\release\deps --extern anyhow=D:\work\my\albion\sniffer-state-b\target\release\deps\libanyhow-eca7a5f3975a9d04.rlib --extern enum_as_inner=D:\work\my\albion\sniffer-state-b\target\release\deps\enum_as_inner-8cf11b20e96c53bf.dll --extern env_logger=D:\work\my\albion\sniffer-state-b\target\release\deps\libenv_logger-f0b19786a0d98d05.rlib --extern json5=D:\work\my\albion\sniffer-state-b\target\release\deps\libjson5-a5841645ceac8868.rlib --extern log=D:\work\my\albion\sniffer-state-b\target\release\deps\liblog-d2f488341450ced2.rlib --extern num_derive=D:\work\my\albion\sniffer-state-b\target\release\deps\num_derive-0808bd5872920a76.dll --extern num_traits=D:\work\my\albion\sniffer-state-b\target\release\deps\libnum_traits-ee03325cc16da619.rlib --extern photon=D:\work\my\albion\sniffer-state-b\target\release\deps\libphoton-d89dfd2c34616de6.rlib --extern photon_decode=D:\work\my\albion\sniffer-state-b\target\release\deps\libphoton_decode-3fbd1567b434b7ff.rlib --extern pnet=D:\work\my\albion\sniffer-state-b\target\release\deps\libpnet-98aa8ced3ddefaf8.rlib --extern serde=D:\work\my\albion\sniffer-state-b\target\release\deps\libserde-d02024527f0d7966.rlib --extern serde_json=D:\work\my\albion\sniffer-state-b\target\release\deps\libserde_json-9c68e50b5dd891e2.rlib --extern sniffer=D:\work\my\albion\sniffer-state-b\target\release\deps\libsniffer-1f897fa40e892028.rlib --extern sysinfo=D:\work\my\albion\sniffer-state-b\target\release\deps\libsysinfo-d9eabe187f81dd3a.rlib --extern ureq=D:\work\my\albion\sniffer-state-b\target\release\deps\libureq-b44783c8d3be070d.rlib -L native=D:\home\moxian\rust\.cargo\registry\src\github.com-1ecc6299db9ec823\pnet-0.28.0/lib/x64 -L native=D:\work\my\albion\sniffer-state-b\target\release\build\ring-3873cf38b560348c\out` (exit code: 1)
```

This is extremely fragile, and almost any attempt to minimize the issue, or even really preserve for posterity is unsuccessful. (as a specific example: this binary depends on another rust project on local filesystem. Trying to move them both to a dedicated place triggers a recompilation in a way that makes the bug disappear) (but raw `rustc` invocation on the copy of the `sniffer` itself seems to result in linkage errors, as desired).

Potentially related: #61917 , #45929

`-Ccodegen-units=9999` doesn't seem to do anything.

Let me know if there's anything i can do to get meaningful diagnostics. 

I'm not comfortable sharing the repro (i.e. the full source folder + target/ directory) publicly, but I'm happy to do so in private for whoever is willing to minimize/debug this (figuring out the exact logistics of this seem to be easiest if you @ me on Discord - `moxian#8121`)

### Meta
`rustc --version --verbose`:
```
rustc 1.53.0-beta.3 (82b862164 2021-05-22)
binary: rustc
commit-hash: 82b86216422e1ee696e20511180fada7a7a87949
commit-date: 2021-05-22
host: x86_64-pc-windows-msvc
release: 1.53.0-beta.3
LLVM version: 12.0.1
```