summaryrefslogtreecommitdiffstats
path: root/lld/ELF/Driver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lld/ELF/Driver.cpp')
-rw-r--r--lld/ELF/Driver.cpp31
1 files changed, 19 insertions, 12 deletions
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 22482eb237e..9e5d77aa606 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -575,11 +575,6 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
Config->Mips64EL =
(Config->EMachine == EM_MIPS && Config->EKind == ELF64LEKind);
- // Add entry symbol. Note that AMDGPU binaries have no entry points.
- if (Config->Entry.empty() && !Config->Shared && !Config->Relocatable &&
- Config->EMachine != EM_AMDGPU)
- Config->Entry = (Config->EMachine == EM_MIPS) ? "__start" : "_start";
-
// Default output filename is "a.out" by the Unix tradition.
if (Config->OutputFile.empty())
Config->OutputFile = "a.out";
@@ -588,13 +583,6 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
for (auto *Arg : Args.filtered(OPT_trace_symbol))
Symtab.trace(Arg->getValue());
- // Set either EntryAddr (if S is a number) or EntrySym (otherwise).
- if (!Config->Entry.empty()) {
- StringRef S = Config->Entry;
- if (S.getAsInteger(0, Config->EntryAddr))
- Config->EntrySym = Symtab.addUndefined(S);
- }
-
// Initialize Config->ImageBase.
if (auto *Arg = Args.getLastArg(OPT_image_base)) {
StringRef S = Arg->getValue();
@@ -606,8 +594,27 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
Config->ImageBase = Config->Pic ? 0 : Target->DefaultImageBase;
}
+ // Add all files to the symbol table. After this, the symbol table
+ // contains all known names except a few linker-synthesized symbols.
for (std::unique_ptr<InputFile> &F : Files)
Symtab.addFile(std::move(F));
+
+ // Add the start symbol.
+ // It initializes either Config->Entry or Config->EntryAddr.
+ // Note that AMDGPU binaries have no entries.
+ if (!Config->Entry.empty()) {
+ // It is either "-e <addr>" or "-e <symbol>".
+ if (Config->Entry.getAsInteger(0, Config->EntryAddr))
+ Config->EntrySym = Symtab.addUndefined(Config->Entry);
+ } else if (!Config->Shared && !Config->Relocatable &&
+ Config->EMachine != EM_AMDGPU) {
+ // -e was not specified. Use the default start symbol name
+ // if it is resolvable.
+ Config->Entry = (Config->EMachine == EM_MIPS) ? "__start" : "_start";
+ if (Symtab.find(Config->Entry))
+ Config->EntrySym = Symtab.addUndefined(Config->Entry);
+ }
+
if (HasError)
return; // There were duplicate symbols or incompatible files
OpenPOWER on IntegriCloud