[lld] r268501 - Simplify handling of hint relocations.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed May 4 07:44:23 PDT 2016


Author: rafael
Date: Wed May  4 09:44:22 2016
New Revision: 268501

URL: http://llvm.org/viewvc/llvm-project?rev=268501&view=rev
Log:
Simplify handling of hint relocations.

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

Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=268501&r1=268500&r2=268501&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Wed May  4 09:44:22 2016
@@ -142,6 +142,8 @@ getSymVA(uint32_t Type, typename ELFT::u
          const elf::ObjectFile<ELFT> &File, RelExpr Expr) {
   typedef typename ELFT::uint uintX_t;
   switch (Expr) {
+  case R_HINT:
+    llvm_unreachable("cannot relocate hint relocs");
   case R_TLSLD:
     return Out<ELFT>::Got->getTlsIndexOff() + A -
            Out<ELFT>::Got->getNumEntries() * sizeof(uintX_t);

Modified: lld/trunk/ELF/InputSection.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.h?rev=268501&r1=268500&r2=268501&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.h (original)
+++ lld/trunk/ELF/InputSection.h Wed May  4 09:44:22 2016
@@ -35,6 +35,7 @@ enum RelExpr {
   R_GOT_OFF,
   R_GOT_PAGE_PC,
   R_GOT_PC,
+  R_HINT,
   R_MIPS_GOT,
   R_MIPS_GOT_LOCAL,
   R_NEG_TLS,

Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=268501&r1=268500&r2=268501&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Wed May  4 09:44:22 2016
@@ -179,7 +179,6 @@ public:
   bool needsThunk(uint32_t Type, const InputFile &File,
                   const SymbolBody &S) const override;
   void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override;
-  bool isHintRel(uint32_t Type) const override;
   bool usesOnlyLowPageBits(uint32_t Type) const override;
 };
 } // anonymous namespace
@@ -224,7 +223,6 @@ uint64_t TargetInfo::getImplicitAddend(c
 
 uint64_t TargetInfo::getVAStart() const { return Config->Pic ? 0 : VAStart; }
 
-bool TargetInfo::isHintRel(uint32_t Type) const { return false; }
 bool TargetInfo::usesOnlyLowPageBits(uint32_t Type) const { return false; }
 
 bool TargetInfo::needsThunk(uint32_t Type, const InputFile &File,
@@ -1266,6 +1264,8 @@ RelExpr MipsTargetInfo<ELFT>::getRelExpr
   switch (Type) {
   default:
     return R_ABS;
+  case R_MIPS_JALR:
+    return R_HINT;
   case R_MIPS_GPREL16:
   case R_MIPS_GPREL32:
     return R_GOTREL;
@@ -1535,11 +1535,6 @@ void MipsTargetInfo<ELFT>::relocateOne(u
 }
 
 template <class ELFT>
-bool MipsTargetInfo<ELFT>::isHintRel(uint32_t Type) const {
-  return Type == R_MIPS_JALR;
-}
-
-template <class ELFT>
 bool MipsTargetInfo<ELFT>::usesOnlyLowPageBits(uint32_t Type) const {
   return Type == R_MIPS_LO16;
 }

Modified: lld/trunk/ELF/Target.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=268501&r1=268500&r2=268501&view=diff
==============================================================================
--- lld/trunk/ELF/Target.h (original)
+++ lld/trunk/ELF/Target.h Wed May  4 09:44:22 2016
@@ -42,11 +42,6 @@ public:
                         uint64_t PltEntryAddr, int32_t Index,
                         unsigned RelOff) const {}
 
-  // Returns true if a relocation is just a hint for linker to make for example
-  // some code optimization. Such relocations should not be handled as a regular
-  // ones and lead to dynamic relocation creation etc.
-  virtual bool isHintRel(uint32_t Type) const;
-
   // Returns true if a relocation only uses the low bits of a value such that
   // all those bits are in in the same page. For example, if the relocation
   // only uses the low 12 bits in a system with 4k pages. If this is true, the

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=268501&r1=268500&r2=268501&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed May  4 09:44:22 2016
@@ -587,16 +587,15 @@ void Writer<ELFT>::scanRelocs(InputSecti
     SymbolBody &Body = File.getRelocTargetSym(RI);
     uint32_t Type = RI.getType(Config->Mips64EL);
 
+    RelExpr Expr = Target->getRelExpr(Type, Body);
     // Ignore "hint" relocation because it is for optional code optimization.
-    if (Target->isHintRel(Type))
+    if (Expr == R_HINT)
       continue;
 
     uintX_t Offset = C.getOffset(RI.r_offset);
     if (Offset == (uintX_t)-1)
       continue;
 
-    RelExpr Expr = Target->getRelExpr(Type, Body);
-
     Expr = adjustExpr(Body, IsWrite, Expr, Type);
     if (HasError)
       continue;




More information about the llvm-commits mailing list