-
Notifications
You must be signed in to change notification settings - Fork 15.6k
Closed
Labels
Description
Forwarding rust-lang/rust#149813
Consider this example:
❯ cat foo.c
int foo() { return 42; }
❯ x86_64-w64-mingw32-clang foo.c -c
Manually using GNU ld to create the library works fine:
❯ x86_64-w64-mingw32-ld -shared /opt/llvm-mingw/llvm-mingw-ucrt/x86_64-w64-mingw32/lib/dllcrt2.o -L /opt/llvm-mingw/llvm-mingw-ucrt/x86_64-w64-mingw32/lib/ -lmingwex -lmingw32 -lmsvcrt -lkernel32 /opt/llvm-mingw/llvm-mingw-ucrt/lib/clang/21/lib/windows/libclang_rt.builtins-x86_64.a foo.o -o libfoo.dll
❯ llvm-objdump -p libfoo.dll | rg AddressOfEn
AddressOfEntryPoint 00000000000011e0
❯ llvm-nm libfoo.dll | rg 11e0
1800011e0 T DllMainCRTStartup
The same fails with LLD:
❯ ld.lld -m i386pep -shared /opt/llvm-mingw/llvm-mingw-ucrt/x86_64-w64-mingw32/lib/dllcrt2.o -L /opt/llvm-mingw/llvm-mingw-ucrt/x86_64-w64-mingw32/lib/ -lmingwex -lmingw32 -lmsvcrt -lkernel32 /opt/llvm-mingw/llvm-mingw-ucrt/lib/clang/21/lib/windows/libclang_rt.builtins-x86_64.a foo.o -o libfoo.dll
ld.lld: error: <root>: undefined symbol: _DllMainCRTStartup
❯ ld.lld --version
LLD 21.1.6 (compatible with GNU linkers)
That's because LLD, unlike ld.bfd looks for underscored variant which isn't defined in mingw-w64:
llvm-project/lld/COFF/Driver.cpp
Line 2412 in 870aa89
| : "_DllMainCRTStartup"; |
RossSmyth and ColinFinck