diff options
author | Rui Ueyama <ruiu@google.com> | 2015-07-02 03:15:15 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2015-07-02 03:15:15 +0000 |
commit | 85225b0a367a488df4920caf3d11c6b04754891b (patch) | |
tree | c5d7a2a3fb7489d776324cee5213095cdb706437 /lld/COFF/Driver.cpp | |
parent | bbb2e8234c4521da4e939943bca0e0d9c7c34791 (diff) | |
download | bcm5719-llvm-85225b0a367a488df4920caf3d11c6b04754891b.tar.gz bcm5719-llvm-85225b0a367a488df4920caf3d11c6b04754891b.zip |
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/Driver.cpp')
-rw-r--r-- | lld/COFF/Driver.cpp | 20 |
1 files changed, 12 insertions, 8 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.) |