<div dir="ltr">Nice. Thanks!</div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 15, 2016 at 12:14 PM, Rafael Espindola via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: rafael<br>
Date: Fri Apr 15 14:14:18 2016<br>
New Revision: 266466<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=266466&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=266466&view=rev</a><br>
Log:<br>
Simplify got handling.<br>
<br>
Each getRelExpr is now expected to return the correct got expression<br>
instead of having Writer patch it up with needsGot.<br>
<br>
Modified:<br>
    lld/trunk/ELF/Target.cpp<br>
    lld/trunk/ELF/Target.h<br>
    lld/trunk/ELF/Writer.cpp<br>
<br>
Modified: lld/trunk/ELF/Target.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=266466&r1=266465&r2=266466&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=266466&r1=266465&r2=266466&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Target.cpp (original)<br>
+++ lld/trunk/ELF/Target.cpp Fri Apr 15 14:14:18 2016<br>
@@ -86,7 +86,6 @@ public:<br>
   bool isRelRelative(uint32_t Type) const override;<br>
   bool needsCopyRelImpl(uint32_t Type) const override;<br>
   bool needsDynRelative(uint32_t Type) const override;<br>
-  bool needsGot(uint32_t Type, const SymbolBody &S) const override;<br>
   bool needsPltImpl(uint32_t Type) const override;<br>
   void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override;<br>
<br>
@@ -115,7 +114,6 @@ public:<br>
   void writePlt(uint8_t *Buf, uint64_t GotEntryAddr, uint64_t PltEntryAddr,<br>
                 int32_t Index, unsigned RelOff) const override;<br>
   bool needsCopyRelImpl(uint32_t Type) const override;<br>
-  bool needsGot(uint32_t Type, const SymbolBody &S) const override;<br>
   bool refersToGotEntry(uint32_t Type) const override;<br>
   bool needsPltImpl(uint32_t Type) const override;<br>
   void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override;<br>
@@ -141,7 +139,6 @@ public:<br>
   RelExpr getRelExpr(uint32_t Type, const SymbolBody &S) const override;<br>
   void writePlt(uint8_t *Buf, uint64_t GotEntryAddr, uint64_t PltEntryAddr,<br>
                 int32_t Index, unsigned RelOff) const override;<br>
-  bool needsGot(uint32_t Type, const SymbolBody &S) const override;<br>
   bool needsPltImpl(uint32_t Type) const override;<br>
   void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override;<br>
   bool isRelRelative(uint32_t Type) const override;<br>
@@ -161,7 +158,6 @@ public:<br>
   uint32_t getTlsGotRel(uint32_t Type) const override;<br>
   bool isRelRelative(uint32_t Type) const override;<br>
   bool needsCopyRelImpl(uint32_t Type) const override;<br>
-  bool needsGot(uint32_t Type, const SymbolBody &S) const override;<br>
   bool refersToGotEntry(uint32_t Type) const override;<br>
   bool needsPltImpl(uint32_t Type) const override;<br>
   void relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const override;<br>
@@ -192,7 +188,6 @@ public:<br>
   void writeGotHeader(uint8_t *Buf) const override;<br>
   void writeThunk(uint8_t *Buf, uint64_t S) const override;<br>
   bool needsCopyRelImpl(uint32_t Type) const override;<br>
-  bool needsGot(uint32_t Type, const SymbolBody &S) const override;<br>
   bool needsPltImpl(uint32_t Type) const override;<br>
   bool needsThunk(uint32_t Type, const InputFile &File,<br>
                   const SymbolBody &S) const override;<br>
@@ -282,10 +277,6 @@ bool TargetInfo::isGotRelative(uint32_t<br>
 bool TargetInfo::isHintRel(uint32_t Type) const { return false; }<br>
 bool TargetInfo::isRelRelative(uint32_t Type) const { return true; }<br>
<br>
-bool TargetInfo::needsGot(uint32_t Type, const SymbolBody &S) const {<br>
-  return false;<br>
-}<br>
-<br>
 bool TargetInfo::needsPltImpl(uint32_t Type) const { return false; }<br>
<br>
 bool TargetInfo::refersToGotEntry(uint32_t Type) const { return false; }<br>
@@ -385,6 +376,10 @@ RelExpr X86TargetInfo::getRelExpr(uint32<br>
   case R_386_PC32:<br>
   case R_386_GOTPC:<br>
     return R_PC;<br>
+  case R_386_GOT32:<br>
+  case R_386_TLS_GOTIE:<br>
+  case R_386_TLS_IE:<br>
+    return R_GOT;<br>
   }<br>
 }<br>
<br>
@@ -486,14 +481,6 @@ bool X86TargetInfo::needsCopyRelImpl(uin<br>
   return Type == R_386_32 || Type == R_386_16 || Type == R_386_8;<br>
 }<br>
<br>
-bool X86TargetInfo::needsGot(uint32_t Type, const SymbolBody &S) const {<br>
-  if (S.isTls() && Type == R_386_TLS_GD)<br>
-    return Target->canRelaxTls(Type, &S) && S.isPreemptible();<br>
-  if (Type == R_386_TLS_GOTIE || Type == R_386_TLS_IE)<br>
-    return !canRelaxTls(Type, &S);<br>
-  return Type == R_386_GOT32 || needsPlt(Type, S);<br>
-}<br>
-<br>
 bool X86TargetInfo::needsPltImpl(uint32_t Type) const {<br>
   return Type == R_386_PLT32;<br>
 }<br>
@@ -689,13 +676,16 @@ RelExpr X86_64TargetInfo::getRelExpr(uin<br>
   case R_X86_64_SIZE32:<br>
   case R_X86_64_SIZE64:<br>
     return R_SIZE;<br>
-  case R_X86_64_GOTPCREL:<br>
   case R_X86_64_PLT32:<br>
   case R_X86_64_PC32:<br>
   case R_X86_64_TLSLD:<br>
-  case R_X86_64_GOTTPOFF:<br>
   case R_X86_64_TLSGD:<br>
     return R_PC;<br>
+  case R_X86_64_GOT32:<br>
+    return R_GOT;<br>
+  case R_X86_64_GOTPCREL:<br>
+  case R_X86_64_GOTTPOFF:<br>
+    return R_GOT_PC;<br>
   }<br>
 }<br>
<br>
@@ -746,14 +736,6 @@ bool X86_64TargetInfo::refersToGotEntry(<br>
          Type == R_X86_64_REX_GOTPCRELX;<br>
 }<br>
<br>
-bool X86_64TargetInfo::needsGot(uint32_t Type, const SymbolBody &S) const {<br>
-  if (Type == R_X86_64_TLSGD)<br>
-    return Target->canRelaxTls(Type, &S) && S.isPreemptible();<br>
-  if (Type == R_X86_64_GOTTPOFF)<br>
-    return !canRelaxTls(Type, &S);<br>
-  return refersToGotEntry(Type) || needsPlt(Type, S);<br>
-}<br>
-<br>
 uint32_t X86_64TargetInfo::getDynRel(uint32_t Type) const {<br>
   if (Type == R_X86_64_PC32 || Type == R_X86_64_32)<br>
     if (Config->Shared)<br>
@@ -1058,22 +1040,6 @@ void PPC64TargetInfo::writePlt(uint8_t *<br>
   write32be(Buf + 28, 0x4e800420);                   // bctr<br>
 }<br>
<br>
-bool PPC64TargetInfo::needsGot(uint32_t Type, const SymbolBody &S) const {<br>
-  if (needsPlt(Type, S))<br>
-    return true;<br>
-<br>
-  switch (Type) {<br>
-  default: return false;<br>
-  case R_PPC64_GOT16:<br>
-  case R_PPC64_GOT16_DS:<br>
-  case R_PPC64_GOT16_HA:<br>
-  case R_PPC64_GOT16_HI:<br>
-  case R_PPC64_GOT16_LO:<br>
-  case R_PPC64_GOT16_LO_DS:<br>
-    return true;<br>
-  }<br>
-}<br>
-<br>
 bool PPC64TargetInfo::needsPltImpl(uint32_t Type) const {<br>
   // These are function calls that need to be redirected through a PLT stub.<br>
   return Type == R_PPC64_REL24;<br>
@@ -1210,10 +1176,14 @@ RelExpr AArch64TargetInfo::getRelExpr(ui<br>
   case R_AARCH64_ADR_PREL_LO21:<br>
   case R_AARCH64_TSTBR14:<br>
     return R_PC;<br>
-  case R_AARCH64_ADR_GOT_PAGE:<br>
   case R_AARCH64_ADR_PREL_PG_HI21:<br>
-  case R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:<br>
     return R_PAGE_PC;<br>
+  case R_AARCH64_LD64_GOT_LO12_NC:<br>
+  case R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:<br>
+    return R_GOT;<br>
+  case R_AARCH64_ADR_GOT_PAGE:<br>
+  case R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:<br>
+    return R_GOT_PAGE_PC;<br>
   }<br>
 }<br>
<br>
@@ -1337,19 +1307,6 @@ bool AArch64TargetInfo::needsCopyRelImpl<br>
   }<br>
 }<br>
<br>
-bool AArch64TargetInfo::needsGot(uint32_t Type, const SymbolBody &S) const {<br>
-  switch (Type) {<br>
-  case R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:<br>
-  case R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:<br>
-    return !canRelaxTls(Type, &S);<br>
-  case R_AARCH64_ADR_GOT_PAGE:<br>
-  case R_AARCH64_LD64_GOT_LO12_NC:<br>
-    return true;<br>
-  default:<br>
-    return needsPlt(Type, S);<br>
-  }<br>
-}<br>
-<br>
 bool AArch64TargetInfo::refersToGotEntry(uint32_t Type) const {<br>
   return Type == R_AARCH64_ADR_GOT_PAGE || Type == R_AARCH64_LD64_GOT_LO12_NC;<br>
 }<br>
@@ -1591,6 +1548,13 @@ RelExpr MipsTargetInfo<ELFT>::getRelExpr<br>
   case R_MIPS_PCHI16:<br>
   case R_MIPS_PCLO16:<br>
     return R_PC;<br>
+  case R_MIPS_GOT16:<br>
+  case R_MIPS_CALL16:<br>
+    if (S.isLocal())<br>
+      return R_MIPS_GOT_LOCAL;<br>
+    if (!S.isPreemptible())<br>
+      return R_MIPS_GOT;<br>
+    return R_GOT;<br>
   }<br>
 }<br>
<br>
@@ -1719,11 +1683,6 @@ bool MipsTargetInfo<ELFT>::needsCopyRelI<br>
 }<br>
<br>
 template <class ELFT><br>
-bool MipsTargetInfo<ELFT>::needsGot(uint32_t Type, const SymbolBody &S) const {<br>
-  return needsPlt(Type, S) || refersToGotEntry(Type);<br>
-}<br>
-<br>
-template <class ELFT><br>
 bool MipsTargetInfo<ELFT>::refersToGotEntry(uint32_t Type) const {<br>
   return Type == R_MIPS_GOT16 || Type == R_MIPS_CALL16;<br>
 }<br>
<br>
Modified: lld/trunk/ELF/Target.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=266466&r1=266465&r2=266466&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=266466&r1=266465&r2=266466&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Target.h (original)<br>
+++ lld/trunk/ELF/Target.h Fri Apr 15 14:14:18 2016<br>
@@ -57,7 +57,6 @@ public:<br>
   virtual bool isRelRelative(uint32_t Type) const;<br>
<br>
   virtual bool needsDynRelative(uint32_t Type) const { return false; }<br>
-  virtual bool needsGot(uint32_t Type, const SymbolBody &S) const;<br>
   virtual bool refersToGotEntry(uint32_t Type) const;<br>
<br>
   enum PltNeed { Plt_No, Plt_Explicit, Plt_Implicit };<br>
<br>
Modified: lld/trunk/ELF/Writer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=266466&r1=266465&r2=266466&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=266466&r1=266465&r2=266466&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Writer.cpp (original)<br>
+++ lld/trunk/ELF/Writer.cpp Fri Apr 15 14:14:18 2016<br>
@@ -563,23 +563,10 @@ void Writer<ELFT>::scanRelocs(InputSecti<br>
     }<br>
<br>
     // If a relocation needs GOT, we create a GOT slot for the symbol.<br>
-    if (Target->needsGot(Type, Body)) {<br>
+    if (Expr == R_GOT || Expr == R_MIPS_GOT || Expr == R_MIPS_GOT_LOCAL ||<br>
+        Expr == R_GOT_PAGE_PC || Expr == R_GOT_PC) {<br>
       uint32_t T = Body.isTls() ? Target->getTlsGotRel(Type) : Type;<br>
-      RelExpr E;<br>
-      if (Expr == R_PC)<br>
-        E = R_GOT_PC;<br>
-      else if (Expr == R_PAGE_PC)<br>
-        E = R_GOT_PAGE_PC;<br>
-      else if (Config->EMachine == EM_MIPS) {<br>
-        if (Body.isLocal())<br>
-          E = R_MIPS_GOT_LOCAL;<br>
-        else if (!Body.isPreemptible())<br>
-          E = R_MIPS_GOT;<br>
-        else<br>
-          E = R_GOT;<br>
-      } else<br>
-        E = R_GOT;<br>
-      C.Relocations.push_back({E, T, Offset, Addend, &Body});<br>
+      C.Relocations.push_back({Expr, T, Offset, Addend, &Body});<br>
       if (Body.isInGot())<br>
         continue;<br>
       Out<ELFT>::Got->addEntry(Body);<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>