`*-windows-gnullvm` does not link crt2.o when cross-compiling from not-Windows
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I tried this code (from an ARM64 macOS system):
RUSTFLAGS="-Clinker=rust-lld -L <path>/aarch64-w64-mingw32/lib" cargo build --target aarch64-pc-windows-gnullvm
I expected to see this happen: a successful link of a basic "hello world" Rust binary (which does not depend on any extra C code)
Instead, this happened:
error: linking with `rust-lld` failed: exit status: 1
|
= note: "rust-lld" "-flavor" "gnu" "-m" "arm64pe" "<snip>/target/aarch64-pc-windows-gnullvm/debug/deps/rustcwUIa68/symbols.o" "<7 object files omitted>" "-Bstatic" "<sysroot>/lib/rustlib/aarch64-pc-windows-gnullvm/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" "-lunwind" "-lmingw32" "-lmingwex" "-lmsvcrt" "-lkernel32" "-luser32" "--nxcompat" "-L" "<snip>/aarch64-w64-mingw32/lib" "-o" "<snip>/target/aarch64-pc-windows-gnullvm/debug/deps/rust_standalone_test-fd7a544ad3631211.exe" "--gc-sections"
= note: some arguments are omitted. use `--verbose` to show all linker arguments
= note: rust-lld: error: <root>: undefined symbol: mainCRTStartup
rust-lld: error: undefined symbol: atexit
>>> referenced by /build/mingw-w64/mingw-w64-crt/gdtoa/misc.c:84
>>> libmingwex.a(libarm64_libmingwex_a-misc.o):(dtoa_lock)
For some reason, a path to crt2.o isn't being passed, and manually adding -Clink-arg=<path>/aarch64-w64-mingw32/lib/crt2.o to RUSTFLAGS is needed to work around this link error. (Adding such a flag successfully works around the issue and links a working binary.)
This seems to happen for both x86_64-pc-windows-gnullvm and aarch64-pc-windows-gnullvm
Related: #146634, where fixing this issue will probably be required to get this target working out-of-the-box.
Meta
rustc --version --verbose:
rustc 1.94.1 (e408947bf 2026-03-25)
binary: rustc
commit-hash: e408947bfd200af42db322daf0fadfe7e26d3bd1
commit-date: 2026-03-25
host: aarch64-apple-darwin
release: 1.94.1
LLVM version: 21.1.8
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the cargo build command with rust-lld for aarch64-pc-windows-gnullvm or x86_64-pc-windows-gnullvm, then inspect rustc's target linker-argument generation for these gnullvm targets. Done means a basic Rust binary links without manually adding crt2.o, including when cross-compiling from macOS.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- build-system, compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100