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
This commit is contained in:
Rui Ueyama 2015-06-18 00:40:33 +00:00
parent 92b0b02e29
commit ae36985af7
3 changed files with 21 additions and 0 deletions

View File

@ -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<Lazy>(It->second->Body))
return addMemberFile(B);
return std::error_code();
}
// Windows specific -- Link default entry point name.
ErrorOr<StringRef> SymbolTable::findDefaultEntry() {
// If it's DLL, the rule is easy.
@ -205,6 +213,7 @@ ErrorOr<StringRef> SymbolTable::findDefaultEntry() {
{"wWinMain", "wWinMainCRTStartup"},
};
for (auto E : Entries) {
resolveIfPossible(E[1]);
if (find(E[1]))
return StringRef(E[1]);
if (!find(E[0]))

View File

@ -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<ObjectFile *> createLTOObject(llvm::LTOCodeGenerator *CG);

11
lld/test/COFF/entrylib.ll Normal file
View File

@ -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
}