[LLD] [COFF] Fix implicit DLL entry point for MinGW (#171680)
Previously, LLD would always set the implicit entry point for DLLs to the symbol that is prefixed with an underscore. However, mingw-w64 defines it without that underscore. This change fixes that by adding a special branch for MinGW. Also, it simplifies tests that use MinGW style DLL entry symbol by skipping the entry point argument. Note, tests that use MSVC style DLL entry symbol and LLD in MinGW mode, will now require using explicit entry point. I believe this is sensible. When an explicit entry point is passed, i.e. LLD is called by Clang or GCC, there will be no observable difference. Fixes https://github.com/llvm/llvm-project/issues/171441
This commit is contained in:
parent
21fd8cc2a5
commit
2824225d27
@ -1489,6 +1489,14 @@ getVFS(COFFLinkerContext &ctx, const opt::InputArgList &args) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static StringRef DllDefaultEntryPoint(MachineTypes machine, bool mingw) {
|
||||
if (mingw) {
|
||||
return (machine == I386) ? "_DllMainCRTStartup@12" : "DllMainCRTStartup";
|
||||
} else {
|
||||
return (machine == I386) ? "__DllMainCRTStartup@12" : "_DllMainCRTStartup";
|
||||
}
|
||||
}
|
||||
|
||||
constexpr const char *lldsaveTempsValues[] = {
|
||||
"resolution", "preopt", "promote", "internalize", "import",
|
||||
"opt", "precodegen", "prelink", "combinedindex"};
|
||||
@ -2408,8 +2416,7 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
|
||||
symtab.entry = symtab.addGCRoot(symtab.mangle(arg->getValue()), true);
|
||||
} else if (!symtab.entry && !config->noEntry) {
|
||||
if (args.hasArg(OPT_dll)) {
|
||||
StringRef s = (config->machine == I386) ? "__DllMainCRTStartup@12"
|
||||
: "_DllMainCRTStartup";
|
||||
StringRef s = DllDefaultEntryPoint(config->machine, config->mingw);
|
||||
symtab.entry = symtab.addGCRoot(s, true);
|
||||
} else if (config->driverWdm) {
|
||||
// /driver:wdm implies /entry:_NtProcessStartup
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
# RUN: echo -e ".global variable\n.global DllMainCRTStartup\n.thumb\n.text\nDllMainCRTStartup:\nbx lr\n.data\nvariable:\n.long 42" > %t-lib.s
|
||||
# RUN: llvm-mc -triple=armv7-windows-gnu %t-lib.s -filetype=obj -o %t-lib.obj
|
||||
# RUN: lld-link -out:%t-lib.dll -dll -entry:DllMainCRTStartup %t-lib.obj -lldmingw -implib:%t-lib.lib
|
||||
# RUN: lld-link -out:%t-lib.dll -dll %t-lib.obj -lldmingw -implib:%t-lib.lib
|
||||
|
||||
# RUN: llvm-mc -triple=armv7-windows-gnu %s -filetype=obj -o %t.obj
|
||||
# RUN: not lld-link -lldmingw -out:%t.exe -entry:main %t.obj %t-lib.lib 2>&1 | FileCheck %s
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
# RUN: echo -e ".global variable\n.global DllMainCRTStartup\n.thumb\n.text\nDllMainCRTStartup:\nbx lr\n.data\nvariable:\n.long 42" > %t-lib.s
|
||||
# RUN: llvm-mc -triple=armv7-windows-gnu %t-lib.s -filetype=obj -o %t-lib.obj
|
||||
# RUN: lld-link -out:%t-lib.dll -dll -entry:DllMainCRTStartup %t-lib.obj -lldmingw -implib:%t-lib.lib
|
||||
# RUN: lld-link -out:%t-lib.dll -dll %t-lib.obj -lldmingw -implib:%t-lib.lib
|
||||
|
||||
# RUN: llvm-mc -triple=armv7-windows-gnu %s -filetype=obj -o %t.obj
|
||||
# RUN: lld-link -lldmingw -out:%t.exe -entry:main %t.obj %t-lib.lib -verbose
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
# RUN: echo -e ".global variable\n.global DllMainCRTStartup\n.text\nDllMainCRTStartup:\nret\n.data\nvariable:\n.long 42" > %t-lib.s
|
||||
# RUN: llvm-mc -triple=aarch64-windows-gnu %t-lib.s -filetype=obj -o %t-lib.obj
|
||||
# RUN: lld-link -out:%t-lib.dll -dll -entry:DllMainCRTStartup %t-lib.obj -lldmingw -implib:%t-lib.lib
|
||||
# RUN: lld-link -out:%t-lib.dll -dll %t-lib.obj -lldmingw -implib:%t-lib.lib
|
||||
|
||||
# RUN: llvm-mc -triple=aarch64-windows-gnu %s -filetype=obj -o %t.obj
|
||||
# RUN: not lld-link -lldmingw -out:%t.exe -entry:main %t.obj %t-lib.lib 2>&1 | FileCheck %s
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
# RUN: echo -e ".global variable\n.global DllMainCRTStartup\n.text\nDllMainCRTStartup:\nret\n.data\nvariable:\n.long 42" > %t-lib.s
|
||||
# RUN: llvm-mc -triple=aarch64-windows-gnu %t-lib.s -filetype=obj -o %t-lib.obj
|
||||
# RUN: lld-link -out:%t-lib.dll -dll -entry:DllMainCRTStartup %t-lib.obj -lldmingw -implib:%t-lib.lib
|
||||
# RUN: lld-link -out:%t-lib.dll -dll %t-lib.obj -lldmingw -implib:%t-lib.lib
|
||||
|
||||
# RUN: llvm-mc -triple=aarch64-windows-gnu %s -filetype=obj -o %t.obj
|
||||
# RUN: lld-link -lldmingw -out:%t.exe -entry:main %t.obj %t-lib.lib -verbose
|
||||
|
||||
@ -10,7 +10,7 @@
|
||||
## debug info.
|
||||
|
||||
# RUN: llvm-mc -triple=x86_64-windows-gnu %t.dir/lib.s -filetype=obj -o %t.dir/lib.obj
|
||||
# RUN: lld-link -out:%t.dir/lib.dll -dll -entry:DllMainCRTStartup %t.dir/lib.obj -lldmingw -implib:%t.dir/lib.lib
|
||||
# RUN: lld-link -out:%t.dir/lib.dll -dll %t.dir/lib.obj -lldmingw -implib:%t.dir/lib.lib
|
||||
|
||||
# RUN: llvm-mc -triple=x86_64-windows-gnu %t.dir/main.s -filetype=obj -o %t.dir/main.obj
|
||||
# RUN: lld-link -lldmingw -out:%t.dir/main.exe -entry:main %t.dir/main.obj %t.dir/lib.lib -opt:noref -debug:dwarf -runtime-pseudo-reloc:no
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
# RUN: split-file %s %t.dir
|
||||
|
||||
# RUN: llvm-mc -triple=x86_64-windows-gnu %t.dir/lib.s -filetype=obj -o %t.dir/lib.obj
|
||||
# RUN: lld-link -out:%t.dir/lib.dll -dll -entry:DllMainCRTStartup %t.dir/lib.obj -lldmingw -implib:%t.dir/lib.lib
|
||||
# RUN: lld-link -out:%t.dir/lib.dll -dll %t.dir/lib.obj -lldmingw -implib:%t.dir/lib.lib
|
||||
|
||||
# RUN: llvm-mc -triple=x86_64-windows-gnu %t.dir/main.s -filetype=obj -o %t.dir/main.obj
|
||||
# RUN: lld-link -lldmingw -out:%t.dir/main.exe -entry:main %t.dir/main.obj %t.dir/lib.lib -opt:ref -debug:dwarf
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
; RUN: echo -e ".global variable\n.global DllMainCRTStartup\n.text\nDllMainCRTStartup:\nret\n.data\nvariable:\n.long 42" > %t-lib.s
|
||||
; RUN: llvm-mc -triple=x86_64-windows-gnu %t-lib.s -filetype=obj -o %t-lib.obj
|
||||
; RUN: lld-link -out:%t-lib.dll -dll -entry:DllMainCRTStartup %t-lib.obj -lldmingw -implib:%t-lib.lib
|
||||
; RUN: lld-link -out:%t-lib.dll -dll %t-lib.obj -lldmingw -implib:%t-lib.lib
|
||||
|
||||
; RUN: llvm-as -o %t.obj %s
|
||||
; RUN: lld-link -lldmingw -out:%t.exe -entry:entry %t.obj %t-lib.lib
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
# RUN: echo -e ".global variable\n.global DllMainCRTStartup\n.text\nDllMainCRTStartup:\nret\n.data\nvariable:\n.long 42" > %t-lib.s
|
||||
# RUN: llvm-mc -triple=x86_64-windows-gnu %t-lib.s -filetype=obj -o %t-lib.obj
|
||||
# RUN: lld-link -out:%t-lib.dll -dll -entry:DllMainCRTStartup %t-lib.obj -lldmingw -implib:%t-lib.lib
|
||||
# RUN: lld-link -out:%t-lib.dll -dll %t-lib.obj -lldmingw -implib:%t-lib.lib
|
||||
|
||||
# RUN: llvm-mc -triple=x86_64-windows-gnu %s -defsym listptrs=1 -filetype=obj -o %t.obj
|
||||
# RUN: lld-link -lldmingw -out:%t.exe -entry:main %t.obj %t-lib.lib -verbose
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
# RUN: echo -e ".global variable\n.global DllMainCRTStartup\n.text\nDllMainCRTStartup:\nret\n.data\nvariable:\n.long 42" > %t-lib.s
|
||||
# RUN: llvm-mc -triple=x86_64-windows-gnu %t-lib.s -filetype=obj -o %t-lib.obj
|
||||
# RUN: lld-link -out:%t-lib.dll -dll -entry:DllMainCRTStartup %t-lib.obj -lldmingw -implib:%t-lib.lib
|
||||
# RUN: lld-link -out:%t-lib.dll -dll %t-lib.obj -lldmingw -implib:%t-lib.lib
|
||||
|
||||
# RUN: llvm-mc -triple=x86_64-windows-gnu -defsym listptrs=1 %s -filetype=obj -o %t.obj
|
||||
# RUN: lld-link -lldmingw -debug:symtab -out:%t.exe -entry:main %t.obj %t-lib.lib -verbose
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
# RUN: llvm-mc -triple=i686-windows-gnu %s -filetype=obj -o %t.obj
|
||||
|
||||
# RUN: lld-link -lldmingw -exclude-all-symbols -dll -out:%t.dll -entry:DllMainCRTStartup@12 %t.obj
|
||||
# RUN: lld-link -lldmingw -exclude-all-symbols -dll -out:%t.dll %t.obj
|
||||
# RUN: llvm-readobj --coff-exports %t.dll | FileCheck %s -check-prefix=NO-EXPORTS
|
||||
|
||||
# NO-EXPORTS-NOT: Name:
|
||||
@ -25,7 +25,7 @@ _dataSym:
|
||||
|
||||
# RUN: yaml2obj %p/Inputs/export.yaml -o %t.obj
|
||||
#
|
||||
# RUN: lld-link -safeseh:no -out:%t.dll -dll %t.obj -lldmingw -exclude-all-symbols -output-def:%t.def
|
||||
# RUN: lld-link -safeseh:no -out:%t.dll -dll %t.obj -lldmingw -exclude-all-symbols -entry:_DllMainCRTStartup -output-def:%t.def
|
||||
# RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix=DLLEXPORT %s
|
||||
|
||||
# DLLEXPORT: Name: exportfn3
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
# RUN: llvm-mc -triple=i686-windows-gnu %s -filetype=obj -o %t.obj
|
||||
|
||||
# RUN: lld-link -lldmingw -dll -out:%t.dll -entry:DllMainCRTStartup@12 %t.obj -implib:%t.lib
|
||||
# RUN: lld-link -lldmingw -dll -out:%t.dll %t.obj -implib:%t.lib
|
||||
# RUN: llvm-readobj --coff-exports %t.dll | grep Name: | FileCheck %s
|
||||
# RUN: llvm-readobj --coff-exports %t.dll | FileCheck %s --check-prefix=CHECK-RVA
|
||||
# RUN: llvm-readobj %t.lib | FileCheck -check-prefix=IMPLIB %s
|
||||
@ -57,7 +57,7 @@ __imp__unexported:
|
||||
|
||||
# RUN: yaml2obj %p/Inputs/export.yaml -o %t.obj
|
||||
#
|
||||
# RUN: lld-link -safeseh:no -out:%t.dll -dll %t.obj -lldmingw -export-all-symbols -output-def:%t.def
|
||||
# RUN: lld-link -safeseh:no -out:%t.dll -dll %t.obj -lldmingw -export-all-symbols -entry:_DllMainCRTStartup -output-def:%t.def
|
||||
# RUN: llvm-readobj --coff-exports %t.dll | FileCheck -check-prefix=CHECK2 %s
|
||||
# RUN: cat %t.def | FileCheck -check-prefix=CHECK2-DEF %s
|
||||
|
||||
@ -88,7 +88,7 @@ __imp__unexported:
|
||||
# RUN: llvm-ar rcs %t.dir/libs/libmingwex.a %t.dir/libs/mingwfunc.o
|
||||
# RUN: echo -e ".global crtfunc\n.text\ncrtfunc:\nret\n" > %t.dir/libs/crtfunc.s
|
||||
# RUN: llvm-mc -triple=x86_64-windows-gnu %t.dir/libs/crtfunc.s -filetype=obj -o %t.dir/libs/crt2.o
|
||||
# RUN: lld-link -safeseh:no -out:%t.dll -dll -entry:DllMainCRTStartup %t.main.obj -lldmingw %t.dir/libs/crt2.o %t.dir/libs/libmingwex.a -output-def:%t.def
|
||||
# RUN: lld-link -safeseh:no -out:%t.dll -dll %t.main.obj -lldmingw %t.dir/libs/crt2.o %t.dir/libs/libmingwex.a -output-def:%t.def
|
||||
# RUN: echo "EOF" >> %t.def
|
||||
# RUN: cat %t.def | FileCheck -check-prefix=CHECK-EXCLUDE %s
|
||||
|
||||
@ -99,7 +99,7 @@ __imp__unexported:
|
||||
# Test that libraries included with -wholearchive: are autoexported, even if
|
||||
# they are in a library that otherwise normally would be excluded.
|
||||
|
||||
# RUN: lld-link -safeseh:no -out:%t.dll -dll -entry:DllMainCRTStartup %t.main.obj -lldmingw %t.dir/libs/crt2.o -wholearchive:%t.dir/libs/libmingwex.a -output-def:%t.def
|
||||
# RUN: lld-link -safeseh:no -out:%t.dll -dll %t.main.obj -lldmingw %t.dir/libs/crt2.o -wholearchive:%t.dir/libs/libmingwex.a -output-def:%t.def
|
||||
# RUN: echo "EOF" >> %t.def
|
||||
# RUN: cat %t.def | FileCheck -check-prefix=CHECK-WHOLEARCHIVE %s
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user