Skip to content

Regression: linker error 1120 on Windows / Beta #140555

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

Closed
SWilson4 opened this issue May 1, 2025 · 5 comments
Closed

Regression: linker error 1120 on Windows / Beta #140555

SWilson4 opened this issue May 1, 2025 · 5 comments
Labels
C-bug Category: This is a bug. regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Milestone

Comments

@SWilson4
Copy link

SWilson4 commented May 1, 2025

I'm one of the maintainers of liboqs, an open-source C library for post-quantum cryptography. One of our other projects is a Rust wrapper for the library. We run tests in CI on Linux / Mac / Windows with Stable / Beta / Nightly Rust.

Some time ago, our Windows / Nightly builds started failing with what appears to be a linker error. I am fairly certain that this is due to a change in Rust, as CI had previously passed on the same commit, and I don't believe there were any GitHub runner updates. The same error is now causing our Beta Rust builds to fail. These had previously passed, which seems to confirm that it is indeed a change in Rust triggering the failure.

I am unfortunately out of my depth when dealing with the intricacies of Rust and Windows, but I thought it best to report it here.

Code

Here is a failing GitHub Actions run. I've also copied the relevant portion of the logs below in the backtrace section.

I expected the build to pass, as it had previously on the same commit.

Version it worked on

It most recently worked on: beta-x86_64-pc-windows-msvc - rustc 1.86.0-beta.7 (7824ede 2025-03-22)

Version with regression

beta-x86_64-pc-windows-msvc - rustc 1.87.0-beta.4 (a594829 2025-04-12)

Backtrace

Backtrace

cargo test
  shell: C:\Program Files\PowerShell\7\pwsh.EXE -command ". '{0}'"
  env:
    RUST_MIN_STACK: 20971520
    RUSTFLAGS: -C link-arg=/STACK:20971520
    LLVM_PATH: D:\a\_temp\llvm
    LD_LIBRARY_PATH: D:\a\_temp\llvm\lib;
    DYLD_LIBRARY_PATH: D:\a\_temp\llvm\lib;undefined
    LIBCLANG_PATH: D:\a\_temp\llvm\bin\
    OPENSSL_ROOT_DIR: C:/Program Files/OpenSSL
    CARGO_TERM_COLOR: always
    CARGO_INCREMENTAL: 0
    RUST_BACKTRACE: 1
    CACHE_ON_FAILURE: false
   Compiling oqs-sys v0.10.1+liboqs-0.12.0 (D:\a\liboqs-rust\liboqs-rust\oqs-sys)
   Compiling oqs v0.10.1 (D:\a\liboqs-rust\liboqs-rust\oqs)
error: linking with `link.exe` failed: exit code: 1120
  |
  = note: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Tools\\MSVC\\14.43.34808\\bin\\HostX64\\x64\\link.exe" "/NOLOGO" "C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\rustchMnDTj\\symbols.o" "<9 object files omitted>" "<sysroot>\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib/{libtest-*,libgetopts-*,libunicode_width-*,librustc_std_workspace_std-*}.rlib" "D:\\a\\liboqs-rust\\liboqs-rust\\target\\debug\\deps/{liboqs_sys-332d94876817d713.rlib,liblibc-124eb4bee469bbec.rlib}.rlib" "<sysroot>\\lib\\rustlib\\x86_64-pc-windows-msvc\\lib/{libstd-*,libpanic_unwind-*,libwindows_targets-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libunwind-*,libcfg_if-*,liballoc-*,librustc_std_workspace_core-*,libcore-*,libcompiler_builtins-*}.rlib" "kernel32.lib" "C:/Program Files/OpenSSL\\lib\\libcrypto.lib" "D:\\a\\liboqs-rust\\liboqs-rust\\target\\debug\\build\\oqs-sys-c82817a9d50dfd24\\out\\lib\\oqs.lib" "legacy_stdio_definitions.lib" "kernel32.lib" "kernel32.lib" "ntdll.lib" "userenv.lib" "ws2_32.lib" "dbghelp.lib" "/defaultlib:msvcrt" "/NXCOMPAT" "/LIBPATH:C:/Program Files/OpenSSL\\lib" "/LIBPATH:D:\\a\\liboqs-rust\\liboqs-rust\\target\\debug\\build\\oqs-sys-c82817a9d50dfd24\\out\\lib" "/LIBPATH:D:\\a\\liboqs-rust\\liboqs-rust\\target\\debug\\build\\oqs-sys-c82817a9d50dfd24\\out\\lib64" "/OUT:D:\\a\\liboqs-rust\\liboqs-rust\\target\\debug\\deps\\oqs-5ff10ce6b35c7119.exe" "/OPT:REF,NOICF" "/DEBUG" "/PDBALTPATH:%_PDB%" "/NATVIS:<sysroot>\\lib\\rustlib\\etc\\intrinsic.natvis" "/NATVIS:<sysroot>\\lib\\rustlib\\etc\\liballoc.natvis" "/NATVIS:<sysroot>\\lib\\rustlib\\etc\\libcore.natvis" "/NATVIS:<sysroot>\\lib\\rustlib\\etc\\libstd.natvis" "/STACK:20971520"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note:    Creating library D:\a\liboqs-rust\liboqs-rust\target\debug\deps\oqs-5ff10ce6b35c7119.lib and object D:\a\liboqs-rust\liboqs-rust\target\debug\deps\oqs-5ff10ce6b35c7119.exp␍
          LINK : warning LNK4098: defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library␍
          oqs.lib(rand.obj) : error LNK2019: unresolved external symbol __imp_CryptAcquireContextA referenced in function OQS_randombytes_system␍
          oqs.lib(rand.obj) : error LNK2019: unresolved external symbol __imp_CryptReleaseContext referenced in function OQS_randombytes_system␍
          oqs.lib(rand.obj) : error LNK2019: unresolved external symbol __imp_CryptGenRandom referenced in function OQS_randombytes_system␍
          D:\a\liboqs-rust\liboqs-rust\target\debug\deps\oqs-5ff10ce6b35c7119.exe : fatal error LNK1120: 3 unresolved externals␍
          

error: could not compile `oqs` (lib test) due to 1 previous error
Error: Process completed with exit code 1.

@SWilson4 SWilson4 added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels May 1, 2025
@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. labels May 1, 2025
@cuviper
Copy link
Member

cuviper commented May 1, 2025

I believe this is due to #138233, tracked for release notes in #138621.

libstd on windows does not link against advapi32 anymore. Previously some crates relied on this crate being linked, and now need to link it themselves explicitly. If you have a dependency that breaks because of this, it likely has already been fixed, so you may need to update to a newer version.

@cuviper cuviper added regression-from-stable-to-beta Performance or correctness regression from stable to beta. T-libs Relevant to the library team, which will review and decide on the PR/issue. and removed regression-untriaged Untriaged performance or correctness regression. labels May 1, 2025
@cuviper cuviper added this to the 1.87.0 milestone May 1, 2025
@cuviper cuviper added the O-windows Operating system: Windows label May 1, 2025
@jieyouxu
Copy link
Member

jieyouxu commented May 1, 2025

Yeah, I believe this is a duplicate of #139352 which was already considered accepted breakage by the library team -- std no longer links advapi32, so user code will have to explicitly link it.

@jieyouxu jieyouxu closed this as completed May 1, 2025
@jieyouxu jieyouxu removed O-windows Operating system: Windows 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. labels May 1, 2025
@ChrisDenton
Copy link
Member

To be clear, it is always expected for C/C++ libraries to declare their dependencies. Relying on implementation details of the standard library for linking is inherently unstable.

@SWilson4
Copy link
Author

SWilson4 commented May 1, 2025

Thank you all for the responses. I will go update our build script to link against advapi32.

@jieyouxu
Copy link
Member

jieyouxu commented May 1, 2025

Your build scripts are probably missing sth like (untested)

println!("cargo:rustc-link-lib=advapi32");

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-beta Performance or correctness regression from stable to beta. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants