[lld] r266831 - Simplify mips got handling.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 19 15:46:04 PDT 2016


Author: rafael
Date: Tue Apr 19 17:46:03 2016
New Revision: 266831

URL: http://llvm.org/viewvc/llvm-project?rev=266831&view=rev
Log:
Simplify mips got handling.

This avoids computing the address of a position in the got just to then
subtract got->getva().

Modified:
    lld/trunk/ELF/InputSection.cpp
    lld/trunk/ELF/InputSection.h
    lld/trunk/ELF/OutputSections.cpp
    lld/trunk/ELF/OutputSections.h
    lld/trunk/ELF/Target.cpp
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=266831&r1=266830&r2=266831&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Tue Apr 19 17:46:03 2016
@@ -211,18 +211,20 @@ getSymVA(uint32_t Type, typename ELFT::u
     // relocations because they use the following expression to calculate
     // the relocation's result for local symbol: S + A + GP0 - G.
     return Body.getVA<ELFT>(A) + File.getMipsGp0();
+  case R_GOT_OFF:
+    return Body.getGotOffset<ELFT>() + A;
   case R_MIPS_GOT_LOCAL:
     // If relocation against MIPS local symbol requires GOT entry, this entry
     // should be initialized by 'page address'. This address is high 16-bits
     // of sum the symbol's value and the addend.
-    return Out<ELFT>::Got->getMipsLocalPageAddr(Body.getVA<ELFT>(A));
+    return Out<ELFT>::Got->getMipsLocalPageOffset(Body.getVA<ELFT>(A));
   case R_MIPS_GOT:
     // For non-local symbols GOT entries should contain their full
     // addresses. But if such symbol cannot be preempted, we do not
     // have to put them into the "global" part of GOT and use dynamic
     // linker to determine their actual addresses. That is why we
     // create GOT entries for them in the "local" part of GOT.
-    return Out<ELFT>::Got->getMipsLocalEntryAddr(Body.getVA<ELFT>(A));
+    return Out<ELFT>::Got->getMipsLocalEntryOffset(Body.getVA<ELFT>(A));
   case R_PPC_OPD: {
     uint64_t SymVA = Body.getVA<ELFT>(A);
     // If we have an undefined weak symbol, we might get here with a symbol

Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=266831&r1=266830&r2=266831&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Tue Apr 19 17:46:03 2016
@@ -31,6 +31,7 @@ enum RelExpr {
   R_GOT,
   R_GOTONLY_PC,
   R_GOTREL,
+  R_GOT_OFF,
   R_GOT_FROM_END,
   R_GOT_PAGE_PC,
   R_GOT_PC,

Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=266831&r1=266830&r2=266831&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Tue Apr 19 17:46:03 2016
@@ -165,19 +165,19 @@ template <class ELFT> bool GotSection<EL
 
 template <class ELFT>
 typename GotSection<ELFT>::uintX_t
-GotSection<ELFT>::getMipsLocalPageAddr(uintX_t EntryValue) {
+GotSection<ELFT>::getMipsLocalPageOffset(uintX_t EntryValue) {
   // Initialize the entry by the %hi(EntryValue) expression
   // but without right-shifting.
-  return getMipsLocalEntryAddr((EntryValue + 0x8000) & ~0xffff);
+  return getMipsLocalEntryOffset((EntryValue + 0x8000) & ~0xffff);
 }
 
 template <class ELFT>
 typename GotSection<ELFT>::uintX_t
-GotSection<ELFT>::getMipsLocalEntryAddr(uintX_t EntryValue) {
+GotSection<ELFT>::getMipsLocalEntryOffset(uintX_t EntryValue) {
   size_t NewIndex = Target->GotHeaderEntriesNum + MipsLocalGotPos.size();
   auto P = MipsLocalGotPos.insert(std::make_pair(EntryValue, NewIndex));
   assert(!P.second || MipsLocalGotPos.size() <= MipsLocalEntries);
-  return this->getVA() + P.first->second * sizeof(uintX_t);
+  return P.first->second * sizeof(uintX_t) - MipsGPOffset;
 }
 
 template <class ELFT>

Modified: lld/trunk/ELF/OutputSections.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.h?rev=266831&r1=266830&r2=266831&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.h (original)
+++ lld/trunk/ELF/OutputSections.h Tue Apr 19 17:46:03 2016
@@ -112,8 +112,8 @@ public:
   bool addDynTlsEntry(SymbolBody &Sym);
   bool addTlsIndex();
   bool empty() const { return MipsLocalEntries == 0 && Entries.empty(); }
-  uintX_t getMipsLocalEntryAddr(uintX_t EntryValue);
-  uintX_t getMipsLocalPageAddr(uintX_t Addr);
+  uintX_t getMipsLocalEntryOffset(uintX_t EntryValue);
+  uintX_t getMipsLocalPageOffset(uintX_t Addr);
   uintX_t getGlobalDynAddr(const SymbolBody &B) const;
   uintX_t getGlobalDynOffset(const SymbolBody &B) const;
   uintX_t getNumEntries() const { return Entries.size(); }

Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=266831&r1=266830&r2=266831&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Tue Apr 19 17:46:03 2016
@@ -1510,7 +1510,7 @@ RelExpr MipsTargetInfo<ELFT>::getRelExpr
       return R_MIPS_GOT_LOCAL;
     if (!S.isPreemptible())
       return R_MIPS_GOT;
-    return R_GOT;
+    return R_GOT_OFF;
   }
 }
 
@@ -1726,14 +1726,12 @@ void MipsTargetInfo<ELFT>::relocateOne(u
     write32<E>(Loc, (Instr & ~0x3ffffff) | (Val >> 2));
     break;
   }
+  case R_MIPS_GOT16:
+    checkInt<16>(Val, Type);
+  // fallthrough
   case R_MIPS_CALL16:
-  case R_MIPS_GOT16: {
-    int64_t V = Val - getMipsGpAddr<ELFT>();
-    if (Type == R_MIPS_GOT16)
-      checkInt<16>(V, Type);
-    writeMipsLo16<E>(Loc, V);
+    writeMipsLo16<E>(Loc, Val);
     break;
-  }
   case R_MIPS_GPREL16: {
     int64_t V = Val - getMipsGpAddr<ELFT>();
     checkInt<16>(V, Type);

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=266831&r1=266830&r2=266831&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Tue Apr 19 17:46:03 2016
@@ -566,9 +566,12 @@ void Writer<ELFT>::scanRelocs(InputSecti
     }
 
     // If a relocation needs GOT, we create a GOT slot for the symbol.
-    if (Expr == R_GOT || Expr == R_MIPS_GOT || Expr == R_MIPS_GOT_LOCAL ||
-        Expr == R_GOT_PAGE_PC || Expr == R_GOT_PC || Expr == R_GOT_FROM_END) {
+    if (Expr == R_GOT || Expr == R_GOT_OFF || Expr == R_MIPS_GOT ||
+        Expr == R_MIPS_GOT_LOCAL || Expr == R_GOT_PAGE_PC || Expr == R_GOT_PC ||
+        Expr == R_GOT_FROM_END) {
       uint32_t T = Body.isTls() ? Target->getTlsGotRel(Type) : Type;
+      if (Config->EMachine == EM_MIPS && Expr == R_GOT_OFF)
+        Addend -= MipsGPOffset;
       C.Relocations.push_back({Expr, T, Offset, Addend, &Body});
       if (Body.isInGot())
         continue;




More information about the llvm-commits mailing list