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

Missing linker symbols with incremental build #86049

Open
moxian opened this issue Jun 6, 2021 · 5 comments
Open

Missing linker symbols with incremental build #86049

moxian opened this issue Jun 6, 2021 · 5 comments
Labels
A-incr-comp Area: Incremental compilation C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@moxian
Copy link
Contributor

moxian commented Jun 6, 2021

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\jackfan.us.kg-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
@moxian moxian added the C-bug Category: This is a bug. label Jun 6, 2021
@inquisitivecrystal
Copy link
Contributor

@rustbot label +A-incr-comp +O-windows-msvc +T-compiler

@rustbot rustbot added A-incr-comp Area: Incremental compilation O-windows-msvc Toolchain: MSVC, Operating system: Windows T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 6, 2021
@jyn514
Copy link
Member

jyn514 commented Jun 6, 2021

Possibly related to #81280 (which would make it independent of windows).

@inquisitivecrystal
Copy link
Contributor

I'll yank the windows tag. I don't know why I assumed that just because it was on windows it would be windows specific. Maybe it's that I'm still figuring out how to do this tagging thing. In any case, I'm sorry for the error!

@rustbot label -O-windows-msvc

@rustbot rustbot removed the O-windows-msvc Toolchain: MSVC, Operating system: Windows label Jun 6, 2021
@petrochenkov
Copy link
Contributor

Just got this error while linking rustc_driver with incremental enabled (not for the first time).

  = note: ld.lld: error: undefined symbol: anon.91c2f56426c5022640e519f02889d07d.8.llvm.746630307250149404
          >>> referenced by C:\msys64\home\we\rust\library\core\src/option.rs:0
          >>>               librustc_resolve-fac19ceb16326411.rlib(rustc_resolve-fac19ceb16326411.1brnvk2mjzqx5b9n.rcgu.o):(rustc_resolve::macros::registered_idents)
          >>> referenced by C:\msys64\home\we\rust\library\alloc\src\vec/mod.rs:425
          >>>               librustc_resolve-fac19ceb16326411.rlib(rustc_resolve-fac19ceb16326411.2u8t3u4aqh8idzl4.rcgu.o):(<rustc_resolve::late::lifetimes::LifetimeContext>::with::<<rustc_resolve::late::lifetimes::LifetimeContext>::visit_fn_like_elision::{closure#9}>)
          >>> referenced by C:\msys64\home\we\rust\library\alloc\src\vec/mod.rs:425
          >>>               librustc_resolve-fac19ceb16326411.rlib(rustc_resolve-fac19ceb16326411.2u8t3u4aqh8idzl4.rcgu.o):(<rustc_resolve::late::lifetimes::LifetimeContext>::with::<<rustc_resolve::late::lifetimes::LifetimeContext>::visit_segment_args::{closure#6}>)
          >>> referenced 30 more times

          ld.lld: error: undefined symbol: anon.91c2f56426c5022640e519f02889d07d.9.llvm.746630307250149404
          >>> referenced by C:\msys64\home\we\rust\library\alloc\src\vec/mod.rs:425
          >>>               librustc_resolve-fac19ceb16326411.rlib(rustc_resolve-fac19ceb16326411.2u8t3u4aqh8idzl4.rcgu.o):(<rustc_resolve::late::lifetimes::LifetimeContext>::with::<<rustc_resolve::late::lifetimes::LifetimeContext>::visit_fn_like_elision::{closure#9}>)
          >>> referenced by C:\msys64\home\we\rust\library\alloc\src\vec/mod.rs:425
          >>>               librustc_resolve-fac19ceb16326411.rlib(rustc_resolve-fac19ceb16326411.2u8t3u4aqh8idzl4.rcgu.o):(<rustc_resolve::late::lifetimes::LifetimeContext>::with::<<rustc_resolve::late::lifetimes::LifetimeContext>::visit_segment_args::{closure#6}>)
          >>> referenced by C:\msys64\home\we\rust\library\alloc\src\vec/mod.rs:425
          >>>               librustc_resolve-fac19ceb16326411.rlib(rustc_resolve-fac19ceb16326411.2u8t3u4aqh8idzl4.rcgu.o):(<rustc_resolve::late::lifetimes::LifetimeContext>::with::<<rustc_resolve::late::lifetimes::LifetimeContext>::visit_segment_args::{closure#7}>)
          >>> referenced 30 more times

          ld.lld: error: undefined symbol: core::ptr::drop_in_place::<rustc_span::FileName> (.llvm.1438190246702246187)
          >>> referenced by C:\msys64\home\we\rust\library\core\src\ptr/mod.rs:188
          >>>               librustc_resolve-fac19ceb16326411.rlib(rustc_resolve-fac19ceb16326411.3bc39m1okvl6wof.rcgu.o):(<&mut <rustc_resolve::Resolver>::check_unused::{closure#0} as core::ops::function::FnMut<(&rustc_span::span_encoding::Span,)>>::call_mut)
          >>> referenced by C:\msys64\home\we\rust\library\core\src\ptr/mod.rs:0
          >>>               librustc_resolve-fac19ceb16326411.rlib(rustc_resolve-fac19ceb16326411.3bc39m1okvl6wof.rcgu.o):(<&mut <rustc_resolve::Resolver>::check_unused::{closure#0} as core::ops::function::FnMut<(&rustc_span::span_encoding::Span,)>>::call_mut)
          >>> referenced by C:\msys64\home\we\rust\library\core\src\ptr/mod.rs:188
          >>>               librustc_resolve-fac19ceb16326411.rlib(rustc_resolve-fac19ceb16326411.4391tludo7n7dv8i.rcgu.o):(core::ptr::drop_in_place::<rustc_span::SpanSnippetError>)
          >>> referenced 9 more times

          ld.lld: error: undefined symbol: core::ptr::drop_in_place::<(rustc_span::FileName, rustc_span::BytePos)> (.llvm.1438190246702246187)
          >>> referenced by C:\msys64\home\we\rust\library\core\src\ptr/mod.rs:188
          >>>               librustc_resolve-fac19ceb16326411.rlib(rustc_resolve-fac19ceb16326411.3bc39m1okvl6wof.rcgu.o):(<&mut <rustc_resolve::Resolver>::check_unused::{closure#0} as core::ops::function::FnMut<(&rustc_span::span_encoding::Span,)>>::call_mut)
          >>> referenced by C:\msys64\home\we\rust\library\core\src\ptr/mod.rs:188
          >>>               librustc_resolve-fac19ceb16326411.rlib(rustc_resolve-fac19ceb16326411.4391tludo7n7dv8i.rcgu.o):(core::ptr::drop_in_place::<rustc_span::SpanSnippetError>)
          >>> referenced by C:\msys64\home\we\rust\library\core\src\ptr/mod.rs:188
          >>>               librustc_resolve-fac19ceb16326411.rlib(rustc_resolve-fac19ceb16326411.5327cotcw21h0vj4.rcgu.o):(core::ptr::drop_in_place::<core::result::Result<alloc::string::String, rustc_span::SpanSnippetError>>)
          >>> referenced 2 more times
          collect2.exe: error: ld returned 1 exit status

@petrochenkov
Copy link
Contributor

cc #85309 #81280

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-incr-comp Area: Incremental compilation C-bug Category: This is a bug. 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

5 participants