struct Configuration {
SymbolBody *EntrySym = nullptr;
SymbolBody *MipsGpDisp = nullptr;
+ SymbolBody *MipsLocalGp = nullptr;
InputFile *FirstElf = nullptr;
llvm::StringRef DynamicLinker;
llvm::StringRef Entry;
// 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.
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,
// 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.
--- /dev/null
+# 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)