[lld] r268525 - [ELF][MIPS] R_MIPS_GOT_DISP, R_MIPS_GOT_PAGE, R_MIPS_GOT_OFST relocations support
Simon Atanasyan via llvm-commits
llvm-commits at lists.llvm.org
Wed May 4 10:47:11 PDT 2016
Author: atanasyan
Date: Wed May 4 12:47:11 2016
New Revision: 268525
URL: http://llvm.org/viewvc/llvm-project?rev=268525&view=rev
Log:
[ELF][MIPS] R_MIPS_GOT_DISP, R_MIPS_GOT_PAGE, R_MIPS_GOT_OFST relocations support
These relocations introduced by MIPS N64 ABI. R_MIPS_GOT_DISP references
GOT entry with full symbol's address, R_MIPS_GOT_PAGE creates GOT entry
with address of memory page which includes symbol's address,
R_MIPS_GOT_OFST used together with R_MIPS_GOT_PAGE. This relocation
calculates offset from beginning of memory page to the symbol address.
Added:
lld/trunk/test/ELF/mips-64-got.s
Modified:
lld/trunk/ELF/Target.cpp
Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=268525&r1=268524&r2=268525&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Wed May 4 12:47:11 2016
@@ -1252,6 +1252,7 @@ RelExpr MipsTargetInfo<ELFT>::getRelExpr
return R_PLT;
case R_MIPS_HI16:
case R_MIPS_LO16:
+ case R_MIPS_GOT_OFST:
// MIPS _gp_disp designates offset between start of function and 'gp'
// pointer into GOT. __gnu_local_gp is equal to the current value of
// the 'gp'. Therefore any relocations against them do not require
@@ -1268,12 +1269,16 @@ RelExpr MipsTargetInfo<ELFT>::getRelExpr
case R_MIPS_PCLO16:
return R_PC;
case R_MIPS_GOT16:
- case R_MIPS_CALL16:
if (S.isLocal())
return R_MIPS_GOT_LOCAL;
+ // fallthrough
+ case R_MIPS_CALL16:
+ case R_MIPS_GOT_DISP:
if (!S.isPreemptible())
return R_MIPS_GOT;
return R_GOT_OFF;
+ case R_MIPS_GOT_PAGE:
+ return R_MIPS_GOT_LOCAL;
}
}
@@ -1451,10 +1456,13 @@ void MipsTargetInfo<ELFT>::relocateOne(u
write32<E>(Loc, (Instr & ~0x3ffffff) | (Val >> 2));
break;
}
+ case R_MIPS_GOT_DISP:
+ case R_MIPS_GOT_PAGE:
case R_MIPS_GOT16:
checkInt<16>(Val, Type);
// fallthrough
case R_MIPS_CALL16:
+ case R_MIPS_GOT_OFST:
writeMipsLo16<E>(Loc, Val);
break;
case R_MIPS_GPREL16: {
@@ -1515,7 +1523,7 @@ void MipsTargetInfo<ELFT>::relocateOne(u
template <class ELFT>
bool MipsTargetInfo<ELFT>::usesOnlyLowPageBits(uint32_t Type) const {
- return Type == R_MIPS_LO16;
+ return Type == R_MIPS_LO16 || Type == R_MIPS_GOT_OFST;
}
}
}
Added: lld/trunk/test/ELF/mips-64-got.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/mips-64-got.s?rev=268525&view=auto
==============================================================================
--- lld/trunk/test/ELF/mips-64-got.s (added)
+++ lld/trunk/test/ELF/mips-64-got.s Wed May 4 12:47:11 2016
@@ -0,0 +1,80 @@
+# Check MIPS N64 ABI GOT relocations
+
+# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux \
+# RUN: %p/Inputs/mips-pic.s -o %t.so.o
+# RUN: llvm-mc -filetype=obj -triple=mips64-unknown-linux %s -o %t.exe.o
+# RUN: ld.lld %t.so.o -shared -o %t.so
+# RUN: ld.lld %t.exe.o %t.so -o %t.exe
+# RUN: llvm-objdump -d -t %t.exe | FileCheck %s
+# RUN: llvm-readobj -r -mips-plt-got %t.exe | FileCheck -check-prefix=GOT %s
+
+# REQUIRES: mips
+
+# CHECK: __start:
+
+# CHECK-NEXT: 20000: df 82 80 20 ld $2, -32736($gp)
+# CHECK-NEXT: 20004: 64 42 00 14 daddiu $2, $2, 20
+# CHECK-NEXT: 20008: 24 42 80 30 addiu $2, $2, -32720
+# CHECK-NEXT: 2000c: 24 42 80 28 addiu $2, $2, -32728
+
+# CHECK: 0000000000020014 .text 00000000 foo
+# CHECK: 0000000000037ff0 .got 00000000 .hidden _gp
+# CHECK: 0000000000020000 .text 00000000 __start
+# CHECK: 0000000000020010 .text 00000000 bar
+
+# GOT: Relocations [
+# GOT-NEXT: ]
+# GOT-NEXT: Primary GOT {
+# GOT-NEXT: Canonical gp value: 0x37FF0
+# GOT-NEXT: Reserved entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x30000
+# GOT-NEXT: Access: -32752
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Purpose: Lazy resolver
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x30008
+# GOT-NEXT: Access: -32744
+# GOT-NEXT: Initial: 0x8000000000000000
+# GOT-NEXT: Purpose: Module pointer (GNU extension)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Local entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x30010
+# GOT-NEXT: Access: -32736
+# GOT-NEXT: Initial: 0x20000
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x30018
+# GOT-NEXT: Access: -32728
+# GOT-NEXT: Initial: 0x20010
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x30020
+# GOT-NEXT: Access: -32720
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function
+# GOT-NEXT: Section: Undefined
+# GOT-NEXT: Name: foo1a
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Number of TLS and multi-GOT entries: 0
+# GOT-NEXT: }
+
+ .text
+ .global __start, bar
+__start:
+ ld $v0,%got_page(foo)($gp) # R_MIPS_GOT_PAGE
+ daddiu $v0,$v0,%got_ofst(foo) # R_MIPS_GOT_OFST
+ addiu $v0,$v0,%got_disp(foo1a) # R_MIPS_GOT_DISP
+ addiu $v0,$v0,%got_disp(bar) # R_MIPS_GOT_DISP
+
+bar:
+ nop
+foo:
+ nop
More information about the llvm-commits
mailing list