summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/COFF/Driver.cpp20
-rw-r--r--lld/COFF/SymbolTable.cpp17
-rw-r--r--lld/COFF/SymbolTable.h6
-rw-r--r--lld/test/COFF/entry-inference2.test39
4 files changed, 67 insertions, 15 deletions
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 6db8f01f30d..8c51030a7d5 100644
--- a/lld/COFF/Driver.cpp
+++ b/lld/COFF/Driver.cpp
@@ -526,15 +526,11 @@ bool LinkerDriver::link(llvm::ArrayRef<const char *> ArgsArr) {
OwningMBs.push_back(std::move(MB)); // take ownership
}
- // Parse all input files and put all symbols to the symbol table.
- // The symbol table will take care of name resolution.
+ // Read all input files given via the command line. Note that step()
+ // doesn't read files that are specified by directive sections.
for (MemoryBufferRef MB : Inputs)
Symtab.addFile(createFile(MB));
- if (auto EC = Symtab.readObjects()) {
- llvm::errs() << EC.message() << "\n";
- return false;
- }
- if (auto EC = Symtab.run()) {
+ if (auto EC = Symtab.step()) {
llvm::errs() << EC.message() << "\n";
return false;
}
@@ -548,9 +544,17 @@ bool LinkerDriver::link(llvm::ArrayRef<const char *> ArgsArr) {
return false;
}
Config->Entry = addUndefined(S);
+ if (Config->Verbose)
+ llvm::outs() << "Entry name inferred: " << S << "\n";
+ }
+
+ // Read as much files as we can.
+ if (auto EC = Symtab.run()) {
+ llvm::errs() << EC.message() << "\n";
+ return false;
}
- // Resolve auxiliary symbols until converge.
+ // Resolve auxiliary symbols until we get a convergence.
// (Trying to resolve a symbol may trigger a Lazy symbol to load a new file.
// A new file may contain a directive section to add new command line options.
// That's why we have to repeat until converge.)
diff --git a/lld/COFF/SymbolTable.cpp b/lld/COFF/SymbolTable.cpp
index 627c9a22f55..ca4c6fa835b 100644
--- a/lld/COFF/SymbolTable.cpp
+++ b/lld/COFF/SymbolTable.cpp
@@ -44,13 +44,20 @@ void SymbolTable::addFile(std::unique_ptr<InputFile> FileP) {
}
}
+std::error_code SymbolTable::step() {
+ if (queueEmpty())
+ return std::error_code();
+ if (auto EC = readObjects())
+ return EC;
+ if (auto EC = readArchives())
+ return EC;
+ return std::error_code();
+}
+
std::error_code SymbolTable::run() {
- while (!queueEmpty()) {
- if (auto EC = readArchives())
+ while (!queueEmpty())
+ if (auto EC = step())
return EC;
- if (auto EC = readObjects())
- return EC;
- }
return std::error_code();
}
diff --git a/lld/COFF/SymbolTable.h b/lld/COFF/SymbolTable.h
index 37075bdf57b..188b2382fb4 100644
--- a/lld/COFF/SymbolTable.h
+++ b/lld/COFF/SymbolTable.h
@@ -43,9 +43,8 @@ class SymbolTable {
public:
SymbolTable();
void addFile(std::unique_ptr<InputFile> File);
+ std::error_code step();
std::error_code run();
- std::error_code readArchives();
- std::error_code readObjects();
bool queueEmpty();
// Print an error message on undefined symbols.
@@ -89,6 +88,9 @@ public:
std::vector<Chunk *> LocalImportChunks;
private:
+ std::error_code readArchives();
+ std::error_code readObjects();
+
std::error_code addSymbol(SymbolBody *New);
void addLazy(Lazy *New, std::vector<Symbol *> *Accum);
diff --git a/lld/test/COFF/entry-inference2.test b/lld/test/COFF/entry-inference2.test
new file mode 100644
index 00000000000..1b3fd3ea156
--- /dev/null
+++ b/lld/test/COFF/entry-inference2.test
@@ -0,0 +1,39 @@
+# RUN: yaml2obj < %s > %t.obj
+# RUN: not lld -flavor link2 /out:%t.exe %t.obj /verbose > %t.log 2>&1
+# RUN: FileCheck %s < %t.log
+
+# CHECK: Entry name inferred: WinMainCRTStartup
+
+---
+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
+ - Name: .drectve
+ Characteristics: [ IMAGE_SCN_LNK_INFO, IMAGE_SCN_LNK_REMOVE ]
+ Alignment: 2147483648
+ SectionData: 2f616c7465726e6174656e616d653a6d61696e3d57696e4d61696e00 # /alternatename:main=WinMain
+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: WinMain
+ Value: 0
+ SectionNumber: 1
+ SimpleType: IMAGE_SYM_TYPE_NULL
+ ComplexType: IMAGE_SYM_DTYPE_NULL
+ StorageClass: IMAGE_SYM_CLASS_EXTERNAL
+...
OpenPOWER on IntegriCloud