Skip to content

Fix linking on i686 MSVC when using bare linkers#242

Merged
Shnatsel merged 1 commit intorust-secure-code:masterfrom
zanieb:zb/i686-win
Mar 4, 2026
Merged

Fix linking on i686 MSVC when using bare linkers#242
Shnatsel merged 1 commit intorust-secure-code:masterfrom
zanieb:zb/i686-win

Conversation

@zanieb
Copy link
Contributor

@zanieb zanieb commented Mar 4, 2026

I encountered the following failure downstream here when building for i686-pc-windows-msvc

error: linking with `link.exe` failed: exit code: 1120
  |
  = note: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Tools\\MSVC\\14.44.35207\\bin\\HostX64\\x86\\link.exe" "/NOLOGO" "/LARGEADDRESSAWARE" "/SAFESEH" "<1 object files omitted>" "C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\rustcxUdZNX/{libsys_info-727445bcec1484dc,libgetrandom-03f1af69d8bb0dc3,libring-20e9f9b6bddfbf32,libzstd_sys-6f820048658e0218,liblzma_sys-5727454a96f1fe21,libbzip2_sys-042215639539600b,libwindows_registry-94186f962003b7ef,libwindows-b747ecf4d9ea130e,libwindows_core-c078246ff8b6d0f5,libwindows_strings-382cf632e8571ac4,libwindows_result-15d6e169fb672ecb,libgetrandom-80cc23cc52d9d4d6,libwindows_sys-8c7aed12b52cda18,liblibmimalloc_sys-9802f8e7d536448a,libstd-3c12ab3e8905162f}.rlib" "<sysroot>\\lib\\rustlib\\i686-pc-windows-msvc\\lib/libcompiler_builtins-*.rlib" "psapi.lib" "powrprof.lib" "advapi32.lib" "kernel32.lib" "ktmw32.lib" "user32.lib" "kernel32.lib" "bcrypt.lib" "advapi32.lib" "C:\\Users\\runneradmin\\.cargo\\registry\\src\\index.crates.io-1949cf8c6b5b557f\\windows_i686_msvc-0.52.6\\lib\\windows.0.52.0.lib" "C:\\Users\\runneradmin\\.cargo\\registry\\src\\index.crates.io-1949cf8c6b5b557f\\windows_i686_msvc-0.52.6\\lib\\windows.0.52.0.lib" "C:\\Users\\runneradmin\\.cargo\\registry\\src\\index.crates.io-1949cf8c6b5b557f\\windows_i686_msvc-0.52.6\\lib\\windows.0.52.0.lib" "psapi.lib" "shell32.lib" "user32.lib" "advapi32.lib" "bcrypt.lib" "legacy_stdio_definitions.lib" "kernel32.lib" "kernel32.lib" "kernel32.lib" "ntdll.lib" "userenv.lib" "ws2_32.lib" "dbghelp.lib" "/defaultlib:libcmt" "/NXCOMPAT" "/LIBPATH:C:\\a\\uv\\uv\\target\\i686-pc-windows-msvc\\release\\build\\bzip2-sys-5709dc9588ef4005\\out\\lib" "/LIBPATH:C:\\a\\uv\\uv\\target\\i686-pc-windows-msvc\\release\\build\\lzma-sys-47800abec4e5590e\\out" "/LIBPATH:C:\\a\\uv\\uv\\target\\i686-pc-windows-msvc\\release\\build\\zstd-sys-10b325c91fd2e25d\\out" "/LIBPATH:C:\\a\\uv\\uv\\target\\i686-pc-windows-msvc\\release\\build\\ring-2252f86e5b76bd21\\out" "/LIBPATH:C:\\a\\uv\\uv\\target\\i686-pc-windows-msvc\\release\\build\\sys-info-0c2f03090b39a83a\\out" "/LIBPATH:C:\\a\\uv\\uv\\target\\i686-pc-windows-msvc\\release\\build\\libmimalloc-sys-988de48ff381680c\\out" "/LIBPATH:C:\\Users\\runneradmin\\.cargo\\registry\\src\\index.crates.io-1949cf8c6b5b557f\\windows_i686_msvc-0.52.6\\lib" "/LIBPATH:C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Tools\\MSVC\\14.44.35207\\atlmfc\\lib\\x86" "/OUT:C:\\a\\uv\\uv\\target\\i686-pc-windows-msvc\\release\\deps\\uv.exe" "/OPT:REF,ICF" "/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" "/NATVIS:C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\rustcxUdZNX\\uv-0.natvis" "/NATVIS:C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\rustcxUdZNX\\uv-1.natvis" "/NATVIS:C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\rustcxUdZNX\\uv-2.natvis" "/MANIFEST:EMBED" "/MANIFESTINPUT:\\\\?\\C:\\a\\uv\\uv\\target\\i686-pc-windows-msvc\\release\\build\\uv-020ed9adf36b91fe\\out\\manifest.xml" "/MANIFESTUAC:NO" "C:\\a\\uv\\uv\\target\\i686-pc-windows-msvc\\release\\deps\\uv_audit_data.o" "/INCLUDE:AUDITABLE_VERSION_INFO"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: LINK : error LNK2001: unresolved external symbol AUDITABLE_VERSION_INFO␍
          C:\a\uv\uv\target\i686-pc-windows-msvc\release\deps\uv.exe : fatal error LNK1120: 1 unresolved externals␍

I then used an LLM to debug this as I frankly don't know anything about symbol mangling on 32-bit Windows. The diagnosis seems plausible however, and this resolved the build failure.

Edit:

The specific error above was resolved by #245

This now fixes

error: could not compile `bare_linker` (bin "bare_linker") due to 1 previous error
{"reason":"compiler-message","package_id":"path+file:///D:/a/cargo-auditable/cargo-auditable/cargo-auditable/tests/fixtures/bare_linker#0.1.0","manifest_path":"D:\\a\\cargo-auditable\\cargo-auditable\\cargo-auditable\\tests\\fixtures\\bare_linker\\Cargo.toml","target":{"kind":["bin"],"crate_types":["bin"],"name":"bare_linker","src_path":"D:\\a\\cargo-auditable\\cargo-auditable\\cargo-auditable\\tests\\fixtures\\bare_linker\\src\\main.rs","edition":"2024","doc":true,"doctest":false,"test":true},"message":{"rendered":"error: linking with `rust-lld` failed: exit code: 1\n  |\n  = note: \"rust-lld\" \"-flavor\" \"gnu\" \"--dynamicbase\" \"--disable-auto-image-base\" \"-m\" \"i386pep\" \"--high-entropy-va\" \"C:\\\\Users\\\\RUNNER~1\\\\AppData\\\\Local\\\\Temp\\\\rustcOHQo9S\\\\symbols.o\" \"<2 object files omitted>\" \"-Bstatic\" \"<sysroot>\\\\lib\\\\rustlib\\\\x86_64-pc-windows-gnu\\\\lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,libcfg_if-*,libwindows_targets-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,liblibc-*,librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib\" \"-Bdynamic\" \"-lkernel32\" \"-lkernel32\" \"-lkernel32\" \"-lntdll\" \"-luserenv\" \"-lws2_32\" \"-ldbghelp\" \"-lgcc_eh\" \"-l:libpthread.a\" \"-lmsvcrt\" \"-lmingwex\" \"-lmingw32\" \"-lgcc\" \"-lmsvcrt\" \"-lmingwex\" \"-luser32\" \"-lkernel32\" \"--nxcompat\" \"-o\" \"D:\\\\a\\\\cargo-auditable\\\\cargo-auditable\\\\cargo-auditable\\\\tests\\\\fixtures\\\\bare_linker\\\\target\\\\x86_64-pc-windows-gnu\\\\release\\\\deps\\\\bare_linker-c1af179e99ffbe38.exe\" \"--gc-sections\" \"-O1\" \"--strip-debug\" \"D:\\\\a\\\\cargo-auditable\\\\cargo-auditable\\\\cargo-auditable\\\\tests\\\\fixtures\\\\bare_linker\\\\target\\\\x86_64-pc-windows-gnu\\\\release\\\\deps\\\\bare_linker_audit_data.o\" \"-u\" \"AUDITABLE_VERSION_INFO\"\n  = note: some arguments are omitted. use `--verbose` to show all linker arguments\n  = note: lld: error: unable to find library -lkernel32␍\n          lld: error: unable to find library -lkernel32␍\n          lld: error: unable to find library -lkernel32␍\n          lld: error: unable to find library -lntdll␍\n          lld: error: unable to find library -luserenv␍\n          lld: error: unable to find library -lws2_32␍\n          lld: error: unable to find library -ldbghelp␍\n          lld: error: unable to find library -lgcc_eh␍\n          lld: error: unable to find library -l:libpthread.a␍\n          lld: error: unable to find library -lmsvcrt␍\n          lld: error: unable to find library -lmingwex␍\n          lld: error: unable to find library -lmingw32␍\n          lld: error: unable to find library -lgcc␍\n          lld: error: unable to find library -lmsvcrt␍\n          lld: error: unable to find library -lmingwex␍\n          lld: error: unable to find library -luser32␍\n          lld: error: unable to find library -lkernel32␍\n          \n\n","$message_type":"diagnostic","children":[{"children":[],"code":null,"level":"note","message":"\"rust-lld\" \"-flavor\" \"gnu\" \"--dynamicbase\" \"--disable-auto-image-base\" \"-m\" \"i386pep\" \"--high-entropy-va\" \"C:\\\\Users\\\\RUNNER~1\\\\AppData\\\\Local\\\\Temp\\\\rustcOHQo9S\\\\symbols.o\" \"<2 object files omitted>\" \"-Bstatic\" \"<sysroot>\\\\lib\\\\rustlib\\\\x86_64-pc-windows-gnu\\\\lib/{libstd-*,libpanic_unwind-*,libobject-*,libmemchr-*,libaddr2line-*,libgimli-*,libcfg_if-*,libwindows_targets-*,librustc_demangle-*,libstd_detect-*,libhashbrown-*,librustc_std_workspace_alloc-*,libminiz_oxide-*,libadler2-*,libunwind-*,liblibc-*,librustc_std_workspace_core-*,liballoc-*,libcore-*,libcompiler_builtins-*}.rlib\" \"-Bdynamic\" \"-lkernel32\" \"-lkernel32\" \"-lkernel32\" \"-lntdll\" \"-luserenv\" \"-lws2_32\" \"-ldbghelp\" \"-lgcc_eh\" \"-l:libpthread.a\" \"-lmsvcrt\" \"-lmingwex\" \"-lmingw32\" \"-lgcc\" \"-lmsvcrt\" \"-lmingwex\" \"-luser32\" \"-lkernel32\" \"--nxcompat\" \"-o\" \"D:\\\\a\\\\cargo-auditable\\\\cargo-auditable\\\\cargo-auditable\\\\tests\\\\fixtures\\\\bare_linker\\\\target\\\\x86_64-pc-windows-gnu\\\\release\\\\deps\\\\bare_linker-c1af179e99ffbe38.exe\" \"--gc-sections\" \"-O1\" \"--strip-debug\" \"D:\\\\a\\\\cargo-auditable\\\\cargo-auditable\\\\cargo-auditable\\\\tests\\\\fixtures\\\\bare_linker\\\\target\\\\x86_64-pc-windows-gnu\\\\release\\\\deps\\\\bare_linker_audit_data.o\" \"-u\" \"AUDITABLE_VERSION_INFO\"","rendered":null,"spans":[]},{"children":[],"code":null,"level":"note","message":"some arguments are omitted. use `--verbose` to show all linker arguments","rendered":null,"spans":[]},{"children":[],"code":null,"level":"note","message":"lld: error: unable to find library -lkernel32\r\nlld: error: unable to find library -lkernel32\r\nlld: error: unable to find library -lkernel32\r\nlld: error: unable to find library -lntdll\r\nlld: error: unable to find library -luserenv\r\nlld: error: unable to find library -lws2_32\r\nlld: error: unable to find library -ldbghelp\r\nlld: error: unable to find library -lgcc_eh\r\nlld: error: unable to find library -l:libpthread.a\r\nlld: error: unable to find library -lmsvcrt\r\nlld: error: unable to find library -lmingwex\r\nlld: error: unable to find library -lmingw32\r\nlld: error: unable to find library -lgcc\r\nlld: error: unable to find library -lmsvcrt\r\nlld: error: unable to find library -lmingwex\r\nlld: error: unable to find library -luser32\r\nlld: error: unable to find library -lkernel32\r\n","rendered":null,"spans":[]}],"level":"error","message":"linking with `rust-lld` failed: exit code: 1","spans":[],"code":null}}

from https://github.com/rust-secure-code/cargo-auditable/actions/runs/22680924943/job/65750878044

@zanieb zanieb changed the title Fix 32-bit MSVC linking Fix i686 MSVC linking Mar 4, 2026
Copy link
Member

@Shnatsel Shnatsel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add 32-bit Windows CI job in a separate PR. Hopefully I can verify that it fails and that this PR fixes it. I don't really want to repeat #240 even though nobody complained.

Comment on lines +198 to +211
let mut feature: u64 = 0;
if architecture == Architecture::I386 {
feature |= 1; // IMAGE_FILE_SAFE_EXCEPTION_HANDLER
}
file.add_symbol(Symbol {
name: b"@feat.00".to_vec(),
value: feature,
size: 0,
kind: SymbolKind::Data,
scope: SymbolScope::Compilation,
weak: false,
section: SymbolSection::Absolute,
flags: SymbolFlags::None,
});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really know much about the implications of some fields, such as the file.add_symbol call and all its arguments. Is this referenced from somewhere? It would be nice to have a comment explaining this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Shnatsel
Copy link
Member

Shnatsel commented Mar 4, 2026

This did make bare linker work on Windows while #245 does not. CI on #243 shows it clearly.

So I'm happy to merge the remaining changes.

@zanieb zanieb changed the title Fix i686 MSVC linking Fix linking on i686 MSVC when using bare linkers Mar 4, 2026
@zanieb
Copy link
Contributor Author

zanieb commented Mar 4, 2026

I'm happy to make more changes but also feel free to push any further tweaks to the commentary directly.

@Shnatsel
Copy link
Member

Shnatsel commented Mar 4, 2026

Thanks! I'll take another look later today and hopefully publish a release with the fix by tomorrow.

@Shnatsel Shnatsel merged commit 66bb33f into rust-secure-code:master Mar 4, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants