[Mips] Implement R_MIPS_PC18_S3 relocation handling

llvm-svn: 232756
This commit is contained in:
Simon Atanasyan 2015-03-19 19:59:06 +00:00
parent 5472ea1270
commit 48e088f354
2 changed files with 66 additions and 0 deletions

View File

@ -65,6 +65,8 @@ static MipsRelocationParams getRelocationParams(uint32_t rType) {
case R_MIPS_26:
case LLD_R_MIPS_GLOBAL_26:
return {4, 0x3ffffff, 2, false};
case R_MIPS_PC18_S3:
return {4, 0x3ffff, 3, false};
case R_MIPS_PC19_S2:
return {4, 0x7ffff, 2, false};
case R_MIPS_PC21_S2:
@ -225,6 +227,14 @@ static uint32_t relocGPRel32(uint64_t S, int64_t A, uint64_t GP) {
return result;
}
/// \brief R_MIPS_PC18_S3
static uint32_t relocPc18(uint64_t P, uint64_t S, int64_t A) {
A = llvm::SignExtend32<21>(A);
// FIXME (simon): Check that S + A has 8-byte alignment
int32_t result = S + A - ((P | 7) ^ 7); // pc with cleared 3-lsb
return result >> 3;
}
/// \brief R_MIPS_PC19_S2
static uint32_t relocPc19(uint64_t P, uint64_t S, int64_t A) {
A = llvm::SignExtend32<21>(A);
@ -381,6 +391,8 @@ static ErrorOr<uint64_t> calculateRelocation(const Reference &ref,
return relocGOT(tgtAddr, gpAddr);
case R_MIPS_GOT_OFST:
return relocGOTOfst(tgtAddr, ref.addend());
case R_MIPS_PC18_S3:
return relocPc18(relAddr, tgtAddr, ref.addend());
case R_MIPS_PC19_S2:
return relocPc19(relAddr, tgtAddr, ref.addend());
case R_MIPS_PC21_S2:

View File

@ -0,0 +1,54 @@
# Check handling of R_MIPS_PC18_S3 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: 400110 00000000 01000000 00000000 00000000
# ^ V
# A = -1 << 3 = -8 =>
# V = (T1 - 8 - (T0|7)^7) >> 3 =>
# V => 8 >> 3 = 1
# CHECK: SYMBOL TABLE:
# CHECK: 00400110 g F .text 00000010 T0
# CHECK: 00400120 g F .text 00000004 T1
FileHeader:
Class: ELFCLASS32
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_MIPS
Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R6]
Sections:
- Name: .text
Type: SHT_PROGBITS
Content: "00000000ffff0300000000000000000000000000"
# ^ T1
# ^ T0 ^ A := 0x3ffff == -1
AddressAlign: 16
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
- Name: .rel.text
Type: SHT_REL
Info: .text
AddressAlign: 4
Relocations:
- Offset: 4
Symbol: T1
Type: R_MIPS_PC18_S3
Symbols:
Global:
- Name: T0
Section: .text
Type: STT_FUNC
Value: 0
Size: 16
- Name: T1
Section: .text
Type: STT_FUNC
Value: 16
Size: 4