Issue 171441
Summary [LLD][MinGW] wrong implicit entry point for shared libraries
Labels lld
Assignees
Reporter mati865
    Forwarding https://github.com/rust-lang/rust/issues/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: https://github.com/llvm/llvm-project/blob/870aa89fbc07956f8672740a5243d422dbf43b87/lld/COFF/Driver.cpp#L2412
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to