[lld] r357194 - Create an instance of Target after reading all input files. NFC.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 28 10:38:53 PDT 2019


Author: ruiu
Date: Thu Mar 28 10:38:53 2019
New Revision: 357194

URL: http://llvm.org/viewvc/llvm-project?rev=357194&view=rev
Log:
Create an instance of Target after reading all input files. NFC.

This change itself doesn't mean anything, but it helps D59780 because
in patch, we don't know whether we need to create a CET-aware PLT or
not until we read all input files.

Modified:
    lld/trunk/ELF/Arch/PPC.cpp
    lld/trunk/ELF/Arch/PPC64.cpp
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/Target.h
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Arch/PPC.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/PPC.cpp?rev=357194&r1=357193&r2=357194&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/PPC.cpp (original)
+++ lld/trunk/ELF/Arch/PPC.cpp Thu Mar 28 10:38:53 2019
@@ -29,7 +29,6 @@ public:
 
 PPC::PPC() {
   NoneRel = R_PPC_NONE;
-  GotBaseSymOff = 0x8000;
   GotBaseSymInGotPlt = false;
 }
 

Modified: lld/trunk/ELF/Arch/PPC64.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/PPC64.cpp?rev=357194&r1=357193&r2=357194&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/PPC64.cpp (original)
+++ lld/trunk/ELF/Arch/PPC64.cpp Thu Mar 28 10:38:53 2019
@@ -208,7 +208,6 @@ PPC64::PPC64() {
   PltEntrySize = 4;
   GotPltEntrySize = 8;
   GotBaseSymInGotPlt = false;
-  GotBaseSymOff = 0x8000;
   GotHeaderEntriesNum = 1;
   GotPltHeaderEntriesNum = 2;
   PltHeaderSize = 60;

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=357194&r1=357193&r2=357194&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Thu Mar 28 10:38:53 2019
@@ -1454,11 +1454,6 @@ static const char *LibcallRoutineNames[]
 // Do actual linking. Note that when this function is called,
 // all linker scripts have already been parsed.
 template <class ELFT> void LinkerDriver::link(opt::InputArgList &Args) {
-  Target = getTarget();
-
-  Config->MaxPageSize = getMaxPageSize(Args);
-  Config->ImageBase = getImageBase(Args);
-
   // If a -hash-style option was not given, set to a default value,
   // which varies depending on the target.
   if (!Args.hasArg(OPT_hash_style)) {
@@ -1616,12 +1611,21 @@ template <class ELFT> void LinkerDriver:
 
   // We do not want to emit debug sections if --strip-all
   // or -strip-debug are given.
-  if (Config->Strip != StripPolicy::None)
+  if (Config->Strip != StripPolicy::None) {
     llvm::erase_if(InputSections, [](InputSectionBase *S) {
       return S->Name.startswith(".debug") || S->Name.startswith(".zdebug");
     });
+  }
 
+  // The Target instance handles target-specific stuff, such as applying
+  // relocations or writing a PLT section. It also contains target-dependent
+  // values such as a default image base address.
+  Target = getTarget();
+
+  Config->EFlags = Target->calcEFlags();
   Config->EFlags = Target->calcEFlags();
+  Config->MaxPageSize = getMaxPageSize(Args);
+  Config->ImageBase = getImageBase(Args);
 
   if (Config->EMachine == EM_ARM) {
     // FIXME: These warnings can be removed when lld only uses these features

Modified: lld/trunk/ELF/Target.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=357194&r1=357193&r2=357194&view=diff
==============================================================================
--- lld/trunk/ELF/Target.h (original)
+++ lld/trunk/ELF/Target.h Thu Mar 28 10:38:53 2019
@@ -86,8 +86,6 @@ public:
 
   uint64_t getImageBase() const;
 
-  // Offset of _GLOBAL_OFFSET_TABLE_ from base of .got or .got.plt section.
-  uint64_t GotBaseSymOff = 0;
   // True if _GLOBAL_OFFSET_TABLE_ is relative to .got.plt, false if .got.
   bool GotBaseSymInGotPlt = true;
 

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=357194&r1=357193&r2=357194&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Thu Mar 28 10:38:53 2019
@@ -214,17 +214,24 @@ void elf::addReservedSymbols() {
   // the .got section.
   // We do not allow _GLOBAL_OFFSET_TABLE_ to be defined by input objects as the
   // correctness of some relocations depends on its value.
-  StringRef GotTableSymName =
+  StringRef GotSymName =
       (Config->EMachine == EM_PPC64) ? ".TOC." : "_GLOBAL_OFFSET_TABLE_";
-  if (Symbol *S = Symtab->find(GotTableSymName)) {
-    if (S->isDefined())
+
+  if (Symbol *S = Symtab->find(GotSymName)) {
+    if (S->isDefined()) {
       error(toString(S->File) + " cannot redefine linker defined symbol '" +
-            GotTableSymName + "'");
-    else
-      ElfSym::GlobalOffsetTable = Symtab->addDefined(
-          GotTableSymName, STV_HIDDEN, STT_NOTYPE, Target->GotBaseSymOff,
-          /*Size=*/0, STB_GLOBAL, Out::ElfHeader,
-          /*File=*/nullptr);
+            GotSymName + "'");
+      return;
+    }
+
+    uint64_t GotOff = 0;
+    if (Config->EMachine == EM_PPC || Config->EMachine == EM_PPC64)
+      GotOff = 0x8000;
+
+    ElfSym::GlobalOffsetTable =
+        Symtab->addDefined(GotSymName, STV_HIDDEN, STT_NOTYPE, GotOff,
+                           /*Size=*/0, STB_GLOBAL, Out::ElfHeader,
+                           /*File=*/nullptr);
   }
 
   // __ehdr_start is the location of ELF file headers. Note that we define




More information about the llvm-commits mailing list