[lld] r240266 - [Mips] Support R_MIPS_LITERAL relocation handling
Simon Atanasyan
simon at atanasyan.com
Mon Jun 22 02:26:49 PDT 2015
Author: atanasyan
Date: Mon Jun 22 04:26:48 2015
New Revision: 240266
URL: http://llvm.org/viewvc/llvm-project?rev=240266&view=rev
Log:
[Mips] Support R_MIPS_LITERAL relocation handling
Added:
lld/trunk/test/elf/Mips/rel-lit.test
Modified:
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp
lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp?rev=240266&r1=240265&r2=240266&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp Mon Jun 22 04:26:48 2015
@@ -117,6 +117,7 @@ static MipsRelocationParams getRelocatio
case R_MIPS_TLS_GD:
case R_MIPS_TLS_LDM:
case R_MIPS_TLS_GOTTPREL:
+ case R_MIPS_LITERAL:
return {4, 0xffff, 0, false, signedCheck<16>};
case R_MIPS_GOT_HI16:
case R_MIPS_GOT_LO16:
@@ -455,7 +456,7 @@ static ErrorOr<int64_t> calculateRelocat
return relocLo16(0, tgtAddr, addend, false, true);
case R_MIPS_GPREL16:
case R_MIPS_GPREL32:
- return tgtAddr + addend - gpAddr;
+ case R_MIPS_LITERAL:
case R_MICROMIPS_GPREL16:
case R_MICROMIPS_GPREL7_S2:
return tgtAddr + addend - gpAddr;
@@ -634,6 +635,7 @@ Reference::Addend readMipsRelocAddend(Re
case R_MIPS_GPREL16:
case R_MICROMIPS_GPREL16:
case R_MIPS_PCLO16:
+ case R_MIPS_LITERAL:
return llvm::SignExtend32<16>(res);
case R_MICROMIPS_GPREL7_S2:
return llvm::SignExtend32<9>(res);
Modified: lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp?rev=240266&r1=240265&r2=240266&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp Mon Jun 22 04:26:48 2015
@@ -578,6 +578,7 @@ void RelocationPass<ELFT>::handleReferen
case R_MIPS_GPREL16:
case R_MICROMIPS_GPREL16:
case R_MICROMIPS_GPREL7_S2:
+ case R_MIPS_LITERAL:
if (isLocal(ref.target()))
ref.setAddend(ref.addend() + atom.file().getGP0());
break;
@@ -624,6 +625,7 @@ static bool isConstrainSym(const MipsELF
case R_MIPS_GPREL32:
case R_MICROMIPS_GPREL16:
case R_MICROMIPS_GPREL7_S2:
+ case R_MIPS_LITERAL:
return false;
default:
return true;
Added: lld/trunk/test/elf/Mips/rel-lit.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/rel-lit.test?rev=240266&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/rel-lit.test (added)
+++ lld/trunk/test/elf/Mips/rel-lit.test Mon Jun 22 04:26:48 2015
@@ -0,0 +1,57 @@
+# Check handling of R_MIPS_LITERAL relocation.
+
+# RUN: yaml2obj -format=elf %s > %t.o
+# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t.o
+# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
+
+# CHECK: Contents of section .text:
+# CHECK-NEXT: 400130 0f100000
+# ^ 0x402000 + 0x7fff - 0x408ff0 = 0x100f
+
+# CHECK: 00402000 g .data 00000004 D0
+# CHECK: 00408ff0 g *ABS* 00000000 _gp_disp
+
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 16
+ Content: "ff7f0000"
+
+ - Name: .rel.text
+ Type: SHT_REL
+ Link: .symtab
+ AddressAlign: 4
+ Info: .text
+ Relocations:
+ - Offset: 0
+ Symbol: D0
+ Type: R_MIPS_LITERAL
+
+ - Name: .data
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_WRITE ]
+ AddressAlign: 16
+ Size: 4
+
+Symbols:
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Value: 0
+ Size: 4
+ - Name: D0
+ Type: STT_OBJECT
+ Section: .data
+ Value: 0
+ Size: 4
+...
More information about the llvm-commits
mailing list