From ae36985af77996494d7f3efa6c01359f86921945 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Thu, 18 Jun 2015 00:40:33 +0000 Subject: [PATCH] COFF: Fix entry point inference bug. Previously, LLD couldn't find a default entry point if it's defined by a library. llvm-svn: 239982 --- lld/COFF/SymbolTable.cpp | 9 +++++++++ lld/COFF/SymbolTable.h | 1 + lld/test/COFF/entrylib.ll | 11 +++++++++++ 3 files changed, 21 insertions(+) create mode 100644 lld/test/COFF/entrylib.ll diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp index cf1be7d7f820..10c13be2e70c 100644 --- a/lld/COFF/SymbolTable.cpp +++ b/lld/COFF/SymbolTable.cpp @@ -187,6 +187,14 @@ Defined *SymbolTable::find(StringRef Name) { return nullptr; } +std::error_code SymbolTable::resolveIfPossible(StringRef Name) { + auto It = Symtab.find(Name); + if (It != Symtab.end()) + if (auto *B = dyn_cast(It->second->Body)) + return addMemberFile(B); + return std::error_code(); +} + // Windows specific -- Link default entry point name. ErrorOr SymbolTable::findDefaultEntry() { // If it's DLL, the rule is easy. @@ -205,6 +213,7 @@ ErrorOr SymbolTable::findDefaultEntry() { {"wWinMain", "wWinMainCRTStartup"}, }; for (auto E : Entries) { + resolveIfPossible(E[1]); if (find(E[1])) return StringRef(E[1]); if (!find(E[0])) diff --git a/lld/COFF/SymbolTable.h b/lld/COFF/SymbolTable.h index df529828410b..0817fb364a42 100644 --- a/lld/COFF/SymbolTable.h +++ b/lld/COFF/SymbolTable.h @@ -88,6 +88,7 @@ private: std::error_code addBitcode(BitcodeFile *File); std::error_code resolve(SymbolBody *Body); + std::error_code resolveIfPossible(StringRef Name); std::error_code addMemberFile(Lazy *Body); ErrorOr createLTOObject(llvm::LTOCodeGenerator *CG); diff --git a/lld/test/COFF/entrylib.ll b/lld/test/COFF/entrylib.ll new file mode 100644 index 000000000000..bc189a17dd6a --- /dev/null +++ b/lld/test/COFF/entrylib.ll @@ -0,0 +1,11 @@ +; RUN: llvm-as -o %t.obj %s +; RUN: rm -f %t.lib +; RUN: llvm-ar cru %t.lib %t.obj +; RUN: lld -flavor link2 /out:%t.exe %t.lib + +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-windows-msvc" + +define i32 @mainCRTStartup() { + ret i32 0 +}