<div dir="ltr">Is there a documentation about __gnu_local_gp? If so, please describe it briefly and add a link to there. If not, it is still better to write a brief description and mention that it is an unofficial (undocumented?) feature that the GNU linker has and what it is used for.</div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Feb 4, 2016 at 4:09 AM, Simon Atanasyan 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: atanasyan<br>
Date: Thu Feb  4 06:09:49 2016<br>
New Revision: 259781<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=259781&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=259781&view=rev</a><br>
Log:<br>
[ELF][MIPS] Add handling for __gnu_local_gp symbol<br>
<br>
This symbol is a "fake" symbol like "_gp_disp" and denotes<br>
the GOT + 0x7FF0 value.<br>
<br>
Added:<br>
    lld/trunk/test/ELF/mips-gp-local.s<br>
Modified:<br>
    lld/trunk/ELF/Config.h<br>
    lld/trunk/ELF/Driver.cpp<br>
    lld/trunk/ELF/InputSection.cpp<br>
    lld/trunk/ELF/Writer.cpp<br>
<br>
Modified: lld/trunk/ELF/Config.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=259781&r1=259780&r2=259781&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=259781&r1=259780&r2=259781&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Config.h (original)<br>
+++ lld/trunk/ELF/Config.h Thu Feb  4 06:09:49 2016<br>
@@ -37,6 +37,7 @@ enum ELFKind {<br>
 struct Configuration {<br>
   SymbolBody *EntrySym = nullptr;<br>
   SymbolBody *MipsGpDisp = nullptr;<br>
+  SymbolBody *MipsLocalGp = nullptr;<br>
   InputFile *FirstElf = nullptr;<br>
   llvm::StringRef DynamicLinker;<br>
   llvm::StringRef Entry;<br>
<br>
Modified: lld/trunk/ELF/Driver.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=259781&r1=259780&r2=259781&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=259781&r1=259780&r2=259781&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Driver.cpp (original)<br>
+++ lld/trunk/ELF/Driver.cpp Thu Feb  4 06:09:49 2016<br>
@@ -328,6 +328,7 @@ template <class ELFT> void LinkerDriver:<br>
     // start of function and gp pointer into GOT. Use 'strong' variant of<br>
     // the addIgnored to prevent '_gp_disp' substitution.<br>
     Config->MipsGpDisp = Symtab.addIgnored("_gp_disp");<br>
+    Config->MipsLocalGp = Symtab.addIgnored("__gnu_local_gp");<br>
<br>
     // Define _gp for MIPS. st_value of _gp symbol will be updated by Writer<br>
     // so that it points to an absolute address which is relative to GOT.<br>
<br>
Modified: lld/trunk/ELF/InputSection.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=259781&r1=259780&r2=259781&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=259781&r1=259780&r2=259781&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/InputSection.cpp (original)<br>
+++ lld/trunk/ELF/InputSection.cpp Thu Feb  4 06:09:49 2016<br>
@@ -234,6 +234,8 @@ void InputSectionBase<ELFT>::relocate(ui<br>
         SymVA = getMipsGpAddr<ELFT>() - AddrLoc;<br>
       else if (Type == R_MIPS_LO16 && Body == Config->MipsGpDisp)<br>
         SymVA = getMipsGpAddr<ELFT>() - AddrLoc + 4;<br>
+      else if (Body == Config->MipsLocalGp)<br>
+        SymVA = getMipsGpAddr<ELFT>();<br>
     }<br>
     uintX_t Size = Body->getSize<ELFT>();<br>
     Target->relocateOne(BufLoc, BufEnd, Type, AddrLoc, SymVA + A, Size + A,<br>
<br>
Modified: lld/trunk/ELF/Writer.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=259781&r1=259780&r2=259781&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=259781&r1=259780&r2=259781&view=diff</a><br>
==============================================================================<br>
--- lld/trunk/ELF/Writer.cpp (original)<br>
+++ lld/trunk/ELF/Writer.cpp Thu Feb  4 06:09:49 2016<br>
@@ -388,7 +388,7 @@ void Writer<ELFT>::scanRelocs(<br>
         // relocation too because that case is possible for executable file<br>
         // linking only.<br>
         continue;<br>
-      if (Body == Config->MipsGpDisp)<br>
+      if (Body == Config->MipsGpDisp || Body == Config->MipsLocalGp)<br>
         // MIPS _gp_disp designates offset between start of function and gp<br>
         // pointer into GOT therefore any relocations against it do not require<br>
         // dynamic relocation.<br>
<br>
Added: lld/trunk/test/ELF/mips-gp-local.s<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-gp-local.s?rev=259781&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-gp-local.s?rev=259781&view=auto</a><br>
==============================================================================<br>
--- lld/trunk/test/ELF/mips-gp-local.s (added)<br>
+++ lld/trunk/test/ELF/mips-gp-local.s Thu Feb  4 06:09:49 2016<br>
@@ -0,0 +1,20 @@<br>
+# Check handling of relocations against __gnu_local_gp symbol.<br>
+<br>
+# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o<br>
+# RUN: ld.lld -o %t.exe %t.o<br>
+# RUN: llvm-objdump -d -t %t.exe | FileCheck %s<br>
+<br>
+# REQUIRES: mips<br>
+<br>
+# CHECK:      Disassembly of section .text:<br>
+# CHECK-NEXT: __start:<br>
+# CHECK-NEXT:    20000:  3c 08 00 00  lui   $8, 0<br>
+# CHECK-NEXT:    20004:  21 08 00 00  addi  $8, $8, 0<br>
+<br>
+# CHECK: 00000000  *ABS*  00000000 _gp<br>
+<br>
+  .text<br>
+  .globl  __start<br>
+__start:<br>
+  lui    $t0,%hi(__gnu_local_gp)<br>
+  addi   $t0,$t0,%lo(__gnu_local_gp)<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>