[lld] r288882 - Simplify -e <number> option handling.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 6 19:23:07 PST 2016


Author: ruiu
Date: Tue Dec  6 21:23:06 2016
New Revision: 288882

URL: http://llvm.org/viewvc/llvm-project?rev=288882&view=rev
Log:
Simplify -e <number> option handling.

This patch is to parse the entry symbol name lazily.

Modified:
    lld/trunk/ELF/Config.h
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=288882&r1=288881&r2=288882&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Tue Dec  6 21:23:06 2016
@@ -148,7 +148,6 @@ struct Configuration {
   ELFKind EKind = ELFNoneKind;
   uint16_t DefaultSymbolVersion = llvm::ELF::VER_NDX_GLOBAL;
   uint16_t EMachine = llvm::ELF::EM_NONE;
-  uint64_t EntryAddr = 0;
   uint64_t ErrorLimit = 20;
   uint64_t ImageBase;
   uint64_t MaxPageSize;

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=288882&r1=288881&r2=288882&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Tue Dec  6 21:23:06 2016
@@ -780,18 +780,10 @@ template <class ELFT> void LinkerDriver:
   for (InputFile *F : Files)
     Symtab.addFile(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->Entry = "";
-  } else if (!Config->Relocatable && Config->EMachine != EM_AMDGPU) {
-    // -e was not specified. Use the default start symbol name
-    // if it is resolvable.
+  // Add the start symbol. Note that AMDGPU binaries have no entries.
+  if (Config->Entry.empty() && !Config->Relocatable &&
+      Config->EMachine != EM_AMDGPU)
     Config->Entry = (Config->EMachine == EM_MIPS) ? "__start" : "_start";
-  }
 
   // If an object file defining the entry symbol is in an archive file,
   // extract the file now.

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=288882&r1=288881&r2=288882&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Dec  6 21:23:06 2016
@@ -1402,11 +1402,13 @@ template <class ELFT> void Writer<ELFT>:
 // 4. the address of the first byte of the .text section, if present;
 // 5. the address 0.
 template <class ELFT> typename ELFT::uint Writer<ELFT>::getEntryAddr() {
-  // Case 1, 2 or 3
-  if (Config->Entry.empty())
-    return Config->EntryAddr;
+  // Case 1, 2 or 3. As a special case, if the symbol is actually
+  // a number, we'll use that number as an address.
   if (SymbolBody *B = Symtab<ELFT>::X->find(Config->Entry))
     return B->getVA<ELFT>();
+  uint64_t Addr;
+  if (!Config->Entry.getAsInteger(0, Addr))
+    return Addr;
 
   // Case 4
   if (OutputSectionBase *Sec = findSection(".text")) {




More information about the llvm-commits mailing list