LDC lto generate wrong dll export table
Test123
test123 at gmail.com
Sun May 22 17:06:46 UTC 2022
The problem is when link with LDC generate lto object, there is
no export table name.
ldmd2 -mtriple=x86_64-w64-mingw32 -betterC -flto=full -c ./test.d
```d
import ldc.attributes : assumeUsed;
import core.sys.windows.windows;
@nogc nothrow extern(C):
export int test() @assumeUsed {
return 0;
}
export extern(Windows) BOOL DllMain(HINSTANCE hInstance, ULONG
ulReason, LPVOID pvReserved) @assumeUsed {
return true;
}
```
x86_64-w64-mingw32-clang -flto=full ./test.c -c
```c
#include <windows.h>
BOOL WINAPI DllMain(HINSTANCE hinst,DWORD reason,LPVOID
lpReserved)
{
return TRUE;
}
__declspec(dllexport) int test(){
return 0;
}
```
to link with lld (or use clang -L/dll -shared)
```sh
lld -flavor ld -lmsvcrt -m i386pep --shared -Bdynamic -e
DllMainCRTStartup --enable-auto-image-base -o test.dll
mingw/x86_64-w64-mingw32/lib/dllcrt2.o
mingw/x86_64-w64-mingw32/lib/crtbegin.o
-Lmingw/x86_64-w64-mingw32/lib -Lmingw/lib
-Lmingw/x86_64-w64-mingw32/sys-root/mingw/lib
-Lmingw/lib/clang/14.0.0/lib/windows test.o -ldnsapi -lbcrypt
-lpsapi -lole32 -liphlpapi -luserenv /dll -lws2_32
-lssp_nonshared -lmingw32
mingw/lib/clang/14.0.0/lib/windows/libclang_rt.builtins-x86_64.a
-lmoldname -lmingwex -ladvapi32 -lshell32 -luser32 -lkernel32
mingw/x86_64-w64-mingw32/lib/crtend.o -Bdynamic
```
As you can see, c and d code are same, and use same link
argument. (I replace the test.o with link script to test)
If I build D code without LTO, I get the correct binary like
clang dose.
Only when I build code with LDC and LTO, the problem exists:
Verify with x86_64-w64-mingw32-objdump --private-headers
test.dll, you will see random symbol name for LDC & LDC
bianry(some time empty).
More information about the digitalmars-d-ldc
mailing list