summaryrefslogtreecommitdiffstats
path: root/lld
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2018-07-18 17:48:14 +0000
committerRui Ueyama <ruiu@google.com>2018-07-18 17:48:14 +0000
commitc93530d873de4c0e713942a021bf622ca59c5593 (patch)
tree61a289a275523b6c22a95d103cbe790818bdc629 /lld
parentda77fe4a77485f5f4c4eb7f460554fc14e88d3b6 (diff)
downloadbcm5719-llvm-c93530d873de4c0e713942a021bf622ca59c5593.tar.gz
bcm5719-llvm-c93530d873de4c0e713942a021bf622ca59c5593.zip
Look for an entry point function if /nodefaultlib is given.
Summary: Fixes https://bugs.llvm.org/show_bug.cgi?id=38018 Reviewers: thakis Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D48990 llvm-svn: 337407
Diffstat (limited to 'lld')
-rw-r--r--lld/COFF/Driver.cpp17
-rw-r--r--lld/test/COFF/entry-inference3.test35
2 files changed, 52 insertions, 0 deletions
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index cba89a83cd7..30792f989ce 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -414,7 +414,24 @@ StringRef LinkerDriver::mangle(StringRef Sym) {
}
// Windows specific -- find default entry point name.
+//
+// There are four different entry point functions for Windows executables,
+// each of which corresponds to a user-defined "main" function. This function
+// infers an entry point from a user-defined "main" function.
StringRef LinkerDriver::findDefaultEntry() {
+ // As a special case, if /nodefaultlib is given, we directly look for an
+ // entry point. This is because, if no default library is linked, users
+ // need to define an entry point instead of a "main".
+ if (Config->NoDefaultLibAll) {
+ for (StringRef S : {"mainCRTStartup", "wmainCRTStartup",
+ "WinMainCRTStartup", "wWinMainCRTStartup"}) {
+ StringRef Entry = Symtab->findMangle(S);
+ if (!Entry.empty() && !isa<Undefined>(Symtab->find(Entry)))
+ return mangle(S);
+ }
+ return "";
+ }
+
// User-defined main functions and their corresponding entry points.
static const char *Entries[][2] = {
{"main", "mainCRTStartup"},
diff --git a/lld/test/COFF/entry-inference3.test b/lld/test/COFF/entry-inference3.test
new file mode 100644
index 00000000000..7de14e10fe8
--- /dev/null
+++ b/lld/test/COFF/entry-inference3.test
@@ -0,0 +1,35 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: not lld-link /out:%t.exe %t.obj /verbose /nodefaultlib > %t.log 2>&1
+# RUN: FileCheck %s < %t.log
+
+# CHECK: Entry name inferred: mainCRTStartup
+
+--- !COFF
+header:
+ Machine: IMAGE_FILE_MACHINE_AMD64
+ Characteristics: []
+sections:
+ - Name: .text
+ Characteristics: [ IMAGE_SCN_CNT_CODE, IMAGE_SCN_MEM_EXECUTE, IMAGE_SCN_MEM_READ ]
+ Alignment: 4
+ SectionData: B82A000000C3
+symbols:
+ - Name: .text
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_STATIC
+ SectionDefinition:
+ Length: 6
+ NumberOfRelocations: 0
+ NumberOfLinenumbers: 0
+ CheckSum: 0
+ Number: 0
+ - Name: mainCRTStartup
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
OpenPOWER on IntegriCloud