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

Unresolved symbol linker error when running cargo test with an #[used] static variable on Windows #127132

Closed
GabeRealB opened this issue Jun 29, 2024 · 2 comments
Labels
C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.

Comments

@GabeRealB
Copy link

Compiling the following code with cargo test on the x86_64-pc-windows-msvc toolchain results in linker errors.

This compiles, if I remove the #[used] attribute.

Code

#![crate_type = "lib"]

#[used]
static STATIC: usize = 0;

Version it worked on

It most recently worked on: rustc 1.81.0-nightly (fda509e 2024-06-25)

Version with regression

rustc --version --verbose:

rustc 1.81.0-nightly (4bc39f028 2024-06-26)
binary: rustc
commit-hash: 4bc39f028d14c24b04dd17dc425432c6ec354536
commit-date: 2024-06-26
host: x86_64-pc-windows-msvc
release: 1.81.0-nightly
LLVM version: 18.1.7

Error output

cargo +nightly-2024-06-27 test
   Compiling test_used v0.1.0 (C:\Users\borre\Projects\test_used)
error: linking with `link.exe` failed: exit code: 1120
  |
  = note: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Preview\\VC\\Tools\\MSVC\\14.41.33923\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "C:\\Users\\borre\\AppData\\Local\\Temp\\rustcVv8M8T\\symbols.o" "C:\\Users\\borre\\Projects\\test_used\\target\\debug\\deps\\test_used-c1d5ca8573ace82e.3pi38yqbvlr9am6dbbz5352mf.rcgu.o" "C:\\Users\\borre\\Projects\\test_used\\target\\debug\\deps\\test_used-c1d5ca8573ace82e.7aqy2o8d4xuoqwac9i42m4wri.rcgu.o" "C:\\Users\\borre\\Projects\\test_used\\target\\debug\\deps\\test_used-c1d5ca8573ace82e.8gwc9cd16aio4dxx1kxr4jifi.rcgu.o" "C:\\Users\\borre\\Projects\\test_used\\target\\debug\\deps\\test_used-c1d5ca8573ace82e.bbox2czukkncahd1umkcqauig.rcgu.o" "C:\\Users\\borre\\Projects\\test_used\\target\\debug\\deps\\test_used-c1d5ca8573ace82e.dozidi37r8cqetuj81knplkdp.rcgu.o" "C:\\Users\\borre\\Projects\\test_used\\target\\debug\\deps\\test_used-c1d5ca8573ace82e.6fnjt5tgs4wtkwgvovigbtf6n.rcgu.o" "/LIBPATH:C:\\Users\\borre\\Projects\\test_used\\target\\debug\\deps" "/LIBPATH:C:\\Users\\borre\\.rustup\\toolchains\\nightly-2024-06-27-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "C:\\Users\\borre\\.rustup\\toolchains\\nightly-2024-06-27-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libtest-a8bfdeafbeaa6d1a.rlib" "C:\\Users\\borre\\.rustup\\toolchains\\nightly-2024-06-27-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libgetopts-1070a0bb8d33b27b.rlib" "C:\\Users\\borre\\.rustup\\toolchains\\nightly-2024-06-27-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunicode_width-c8ef73cb9681873c.rlib" "C:\\Users\\borre\\.rustup\\toolchains\\nightly-2024-06-27-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_std-cbefe9950d472de3.rlib" "C:\\Users\\borre\\.rustup\\toolchains\\nightly-2024-06-27-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd-cef76c2685dfb4ca.rlib" "C:\\Users\\borre\\.rustup\\toolchains\\nightly-2024-06-27-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libpanic_unwind-03fd356be7a76b95.rlib" "C:\\Users\\borre\\.rustup\\toolchains\\nightly-2024-06-27-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_demangle-9ca224f74f6cdb39.rlib" "C:\\Users\\borre\\.rustup\\toolchains\\nightly-2024-06-27-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libstd_detect-85233c80bb492019.rlib" "C:\\Users\\borre\\.rustup\\toolchains\\nightly-2024-06-27-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libhashbrown-30b8f0749c333bea.rlib" "C:\\Users\\borre\\.rustup\\toolchains\\nightly-2024-06-27-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_alloc-cd139eb78ab0a78e.rlib" "C:\\Users\\borre\\.rustup\\toolchains\\nightly-2024-06-27-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libunwind-d887285092c89c96.rlib" "C:\\Users\\borre\\.rustup\\toolchains\\nightly-2024-06-27-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcfg_if-df97a862ba982737.rlib" "C:\\Users\\borre\\.rustup\\toolchains\\nightly-2024-06-27-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\liballoc-3ef5c3ee98d94810.rlib" "C:\\Users\\borre\\.rustup\\toolchains\\nightly-2024-06-27-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\librustc_std_workspace_core-cca5aeb939a92213.rlib" "C:\\Users\\borre\\.rustup\\toolchains\\nightly-2024-06-27-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcore-0a7d9524c210bd3d.rlib" "C:\\Users\\borre\\.rustup\\toolchains\\nightly-2024-06-27-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib\\libcompiler_builtins-a6954cc40265b962.rlib" "kernel32.lib" "kernel32.lib" "advapi32.lib" "kernel32.lib" "ntdll.lib" "userenv.lib" "ws2_32.lib" "kernel32.lib" "ws2_32.lib" "kernel32.lib" "/defaultlib:msvcrt" "/NXCOMPAT" "/LIBPATH:C:\\Users\\borre\\.rustup\\toolchains\\nightly-2024-06-27-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib" "/OUT:C:\\Users\\borre\\Projects\\test_used\\target\\debug\\deps\\test_used-c1d5ca8573ace82e.exe" "/OPT:REF,NOICF" "/DEBUG" "/PDBALTPATH:%_PDB%" "/NATVIS:C:\\Users\\borre\\.rustup\\toolchains\\nightly-2024-06-27-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:C:\\Users\\borre\\.rustup\\toolchains\\nightly-2024-06-27-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:C:\\Users\\borre\\.rustup\\toolchains\\nightly-2024-06-27-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libcore.natvis" "/NATVIS:C:\\Users\\borre\\.rustup\\toolchains\\nightly-2024-06-27-x86_64-pc-windows-msvc\\lib\\rustlib\\etc\\libstd.natvis"
  = note: symbols.o : error LNK2001: unresolved external symbol _ZN9test_used6STATIC17h1ae0e71c81bcc7b1E
          C:\Users\borre\Projects\test_used\target\debug\deps\test_used-c1d5ca8573ace82e.exe : fatal error LNK1120: 1 unresolved externals

@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged

@GabeRealB GabeRealB added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Jun 29, 2024
@rustbot rustbot added I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. and removed regression-untriaged Untriaged performance or correctness regression. labels Jun 29, 2024
@matthiaskrgr
Copy link
Member

isn't this #127052 ?

@ehuss
Copy link
Contributor

ehuss commented Jun 29, 2024

Thanks for the report! Yea, this appears to be a duplicate of #127052, so closing in favor of that. This should be fixed in the latest nightly (2024-06-29 I believe).

@ehuss ehuss closed this as not planned Won't fix, can't repro, duplicate, stale Jun 29, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 30, 2024
@apiraino apiraino removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.
Projects
None yet
Development

No branches or pull requests

6 participants