Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lld/COFF
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2015-07-02 06:15:15 +0300
committerRui Ueyama <ruiu@google.com>2015-07-02 06:15:15 +0300
commit85225b0a367a488df4920caf3d11c6b04754891b (patch)
treec5d7a2a3fb7489d776324cee5213095cdb706437 /lld/COFF
parentbbb2e8234c4521da4e939943bca0e0d9c7c34791 (diff)
COFF: Infer entry point as early as possible, but not too early.
On Windows, we have four different main functions, {w,}{main,WinMain}. The linker has to choose a corresponding entry point function among {w,}{main,WinMain}CRTStartup. These entry point functions are defined in the standard library. The linker resolves one of them by looking at which main function is defined and adding a corresponding undefined symbol to the symbol table. Object files containing entry point functions conflicts each other. For example, we cannot resolve both mainCRTStartup and WinMainCRTStartup because other symbols defined in the files conflict. Previously, we inferred CRT function name at the very end of name resolution. I found that that is sometimes too late. If the linker already linked one of these four archive member objects, it's too late to change the decision. The right thing to do here is to infer entry point name after adding all symbols from command line files and before adding any other files (which are specified by directive sections). This patch does that. llvm-svn: 241236
Diffstat (limited to 'lld/COFF')
-rw-r--r--lld/COFF/Driver.cpp20
-rw-r--r--lld/COFF/SymbolTable.cpp17
-rw-r--r--lld/COFF/SymbolTable.h6
3 files changed, 28 insertions, 15 deletions
diff --git a/lld/COFF/Driver.cpp b/lld/COFF/Driver.cpp
index 6db8f01f30d2..8c51030a7d55 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 627c9a22f55e..ca4c6fa835bf 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 37075bdf57b7..188b2382fb4b 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);