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