[lld] r265986 - Simplify handling of mips gp* symbols.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 11 13:34:30 PDT 2016


Author: rafael
Date: Mon Apr 11 15:34:27 2016
New Revision: 265986

URL: http://llvm.org/viewvc/llvm-project?rev=265986&view=rev
Log:
Simplify handling of mips gp* symbols.

Give them values instead of computing it during relocation.

Modified:
    lld/trunk/ELF/Config.h
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/Symbols.h
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=265986&r1=265985&r2=265986&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Mon Apr 11 15:34:27 2016
@@ -38,8 +38,6 @@ enum class BuildIdKind { None, Fnv1, Md5
 // Most fields are initialized by the driver.
 struct Configuration {
   SymbolBody *EntrySym = nullptr;
-  SymbolBody *MipsGpDisp = nullptr;
-  SymbolBody *MipsLocalGp = nullptr;
   InputFile *FirstElf = nullptr;
   llvm::StringRef DynamicLinker;
   llvm::StringRef Entry;

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=265986&r1=265985&r2=265986&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Mon Apr 11 15:34:27 2016
@@ -206,12 +206,10 @@ template <class ELFT, class uintX_t>
 static uintX_t adjustMipsSymVA(uint32_t Type, const elf::ObjectFile<ELFT> &File,
                                const SymbolBody &Body, uintX_t AddrLoc,
                                uintX_t SymVA) {
-  if (Type == R_MIPS_HI16 && &Body == Config->MipsGpDisp)
-    return getMipsGpAddr<ELFT>() - AddrLoc;
-  if (Type == R_MIPS_LO16 && &Body == Config->MipsGpDisp)
-    return getMipsGpAddr<ELFT>() - AddrLoc + 4;
-  if (&Body == Config->MipsLocalGp)
-    return getMipsGpAddr<ELFT>();
+  if (Type == R_MIPS_HI16 && &Body == ElfSym<ELFT>::MipsGpDisp)
+    return SymVA - AddrLoc;
+  if (Type == R_MIPS_LO16 && &Body == ElfSym<ELFT>::MipsGpDisp)
+    return SymVA - AddrLoc + 4;
   if (Body.isLocal() && (Type == R_MIPS_GPREL16 || Type == R_MIPS_GPREL32))
     // We need to adjust SymVA value in case of R_MIPS_GPREL16/32
     // relocations because they use the following expression to calculate

Modified: lld/trunk/ELF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Symbols.h?rev=265986&r1=265985&r2=265986&view=diff
==============================================================================
--- lld/trunk/ELF/Symbols.h (original)
+++ lld/trunk/ELF/Symbols.h Mon Apr 11 15:34:27 2016
@@ -405,6 +405,9 @@ template <class ELFT> struct ElfSym {
   // The content for _gp symbol for MIPS target.
   static DefinedRegular<ELFT> *MipsGp;
 
+  static DefinedRegular<ELFT> *MipsLocalGp;
+  static DefinedRegular<ELFT> *MipsGpDisp;
+
   // __rel_iplt_start/__rel_iplt_end for signaling
   // where R_[*]_IRELATIVE relocations do live.
   static SymbolBody *RelaIpltStart;
@@ -418,6 +421,8 @@ template <class ELFT> DefinedRegular<ELF
 template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::End;
 template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::End2;
 template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::MipsGp;
+template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::MipsLocalGp;
+template <class ELFT> DefinedRegular<ELFT> *ElfSym<ELFT>::MipsGpDisp;
 template <class ELFT> SymbolBody *ElfSym<ELFT>::RelaIpltStart;
 template <class ELFT> SymbolBody *ElfSym<ELFT>::RelaIpltEnd;
 

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=265986&r1=265985&r2=265986&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Apr 11 15:34:27 2016
@@ -454,8 +454,8 @@ void Writer<ELFT>::scanRelocs(InputSecti
     // pointer into GOT. __gnu_local_gp is equal to the current value of
     // the 'gp'. Therefore any relocations against them do not require
     // dynamic relocation.
-    if (Config->EMachine == EM_MIPS &&
-        (&Body == Config->MipsGpDisp || &Body == Config->MipsLocalGp))
+    if (Config->EMachine == EM_MIPS && (&Body == ElfSym<ELFT>::MipsGpDisp ||
+                                        &Body == ElfSym<ELFT>::MipsLocalGp))
       continue;
 
     if (Preemptible) {
@@ -930,12 +930,12 @@ template <class ELFT> void Writer<ELFT>:
   if (Config->EMachine == EM_MIPS) {
     // On MIPS O32 ABI, _gp_disp is a magic symbol designates offset between
     // start of function and 'gp' pointer into GOT.
-    Config->MipsGpDisp = Symtab.addIgnored("_gp_disp");
+    ElfSym<ELFT>::MipsGpDisp = Symtab.addIgnored("_gp_disp");
     // The __gnu_local_gp is a magic symbol equal to the current value of 'gp'
     // pointer. This symbol is used in the code generated by .cpload pseudo-op
     // in case of using -mno-shared option.
     // https://sourceware.org/ml/binutils/2004-12/msg00094.html
-    Config->MipsLocalGp = Symtab.addIgnored("__gnu_local_gp");
+    ElfSym<ELFT>::MipsLocalGp = Symtab.addIgnored("__gnu_local_gp");
   }
 
   // In the assembly for 32 bit x86 the _GLOBAL_OFFSET_TABLE_ symbol
@@ -1510,8 +1510,14 @@ static uint16_t getELFType() {
 // symbol values that depend on section address and size.
 template <class ELFT> void Writer<ELFT>::fixAbsoluteSymbols() {
   // Update MIPS _gp absolute symbol so that it points to the static data.
-  if (Config->EMachine == EM_MIPS)
+
+  if (Config->EMachine == EM_MIPS) {
     ElfSym<ELFT>::MipsGp->Value = getMipsGpAddr<ELFT>();
+    if (ElfSym<ELFT>::MipsLocalGp)
+      ElfSym<ELFT>::MipsLocalGp->Value = getMipsGpAddr<ELFT>();
+    if (ElfSym<ELFT>::MipsGpDisp)
+      ElfSym<ELFT>::MipsGpDisp->Value = getMipsGpAddr<ELFT>();
+  }
 
   // _etext is the first location after the last read-only loadable segment.
   // _edata is the first location after the last read-write loadable segment.




More information about the llvm-commits mailing list