[lld] r261822 - [ELF][MIPS] Enumerate absolute MIPS relocations in the isRelRelative

Simon Atanasyan via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 24 21:03:52 PST 2016


Author: atanasyan
Date: Wed Feb 24 23:03:52 2016
New Revision: 261822

URL: http://llvm.org/viewvc/llvm-project?rev=261822&view=rev
Log:
[ELF][MIPS] Enumerate absolute MIPS relocations in the isRelRelative

This commit does two related thing. At first, it enumerates supported
absolute MIPS relocations in the `MipsTargetInfo<ELFT>::isRelRelative`
method. In that case the code is shorter and the case switch does not
tend to grow. At second, it prevents R_MIPS_COPY and PLT creation for
relative relocations. For almost all relative MIPS relocations like
R_MIPS_PC19_S2, R_MIPS_PCHI16 etc it does not have a sence. The only
exception is R_MIPS_PC32. GNU linker creates a copy relocation or PLT
entry for it. But I could not find any real test case uses R_MIPS_PC32
with DSO defined symbol as a target. So for now I prefer to skip this
case to simplify the LLD code.

Modified:
    lld/trunk/ELF/Target.cpp
    lld/trunk/test/ELF/mips-plt-copy.s

Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=261822&r1=261821&r2=261822&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Wed Feb 24 23:03:52 2016
@@ -1700,7 +1700,7 @@ void MipsTargetInfo<ELFT>::writePlt(uint
 
 template <class ELFT>
 bool MipsTargetInfo<ELFT>::needsCopyRelImpl(uint32_t Type) const {
-  return Type == R_MIPS_HI16 || Type == R_MIPS_LO16 || isRelRelative(Type);
+  return !isRelRelative(Type);
 }
 
 template <class ELFT>
@@ -1716,9 +1716,8 @@ bool MipsTargetInfo<ELFT>::needsPltImpl(
     return false;
   if (Type == R_MIPS_26 && canBePreempted(&S, false))
     return true;
-  if (Type == R_MIPS_HI16 || Type == R_MIPS_LO16 || isRelRelative(Type))
-    if (S.isShared())
-      return true;
+  if (!isRelRelative(Type) && S.isShared())
+    return true;
   return false;
 }
 
@@ -1826,15 +1825,13 @@ template <class ELFT>
 bool MipsTargetInfo<ELFT>::isRelRelative(uint32_t Type) const {
   switch (Type) {
   default:
-    return false;
-  case R_MIPS_PC16:
-  case R_MIPS_PC19_S2:
-  case R_MIPS_PC21_S2:
-  case R_MIPS_PC26_S2:
-  case R_MIPS_PC32:
-  case R_MIPS_PCHI16:
-  case R_MIPS_PCLO16:
     return true;
+  case R_MIPS_26:
+  case R_MIPS_32:
+  case R_MIPS_64:
+  case R_MIPS_HI16:
+  case R_MIPS_LO16:
+    return false;
   }
 }
 

Modified: lld/trunk/test/ELF/mips-plt-copy.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-plt-copy.s?rev=261822&r1=261821&r2=261822&view=diff
==============================================================================
--- lld/trunk/test/ELF/mips-plt-copy.s (original)
+++ lld/trunk/test/ELF/mips-plt-copy.s Wed Feb 24 23:03:52 2016
@@ -80,6 +80,6 @@ loc:
 gd:
   .word 0
 ld:
-  .word data1+8-.          # R_MIPS_PC32 requires COPY rel for DSO defined data.
-  .word foo1+8-.           # R_MIPS_PC32 requires JUMP_SLOT/PLT entry
-                           # for DSO defined func.
+  .word data1+8            # R_MIPS_32 requires REL32 dnamic relocation
+                           # for DSO defined data. For now we generate COPY one.
+  .word foo1+8             # R_MIPS_32 requires PLT entry for DSO defined func.




More information about the llvm-commits mailing list