[Mips] Support R_MICROMIPS_SUB relocation handling

llvm-svn: 240265
This commit is contained in:
Simon Atanasyan 2015-06-22 09:26:41 +00:00
parent 1af72b898c
commit ca0fe2f4a4
2 changed files with 68 additions and 2 deletions

View File

@ -74,6 +74,8 @@ static MipsRelocationParams getRelocationParams(uint32_t rType) {
case R_MIPS_64:
case R_MIPS_SUB:
return {8, 0xffffffffffffffffull, 0, false, dummyCheck};
case R_MICROMIPS_SUB:
return {8, 0xffffffffffffffffull, 0, true, dummyCheck};
case R_MIPS_32:
case R_MIPS_GPREL32:
case R_MIPS_REL32:
@ -350,8 +352,9 @@ static CrossJumpMode getCrossJumpMode(const Reference &ref) {
}
}
static uint32_t microShuffle(uint32_t ins) {
return ((ins & 0xffff) << 16) | ((ins & 0xffff0000) >> 16);
static uint64_t microShuffle(uint64_t ins) {
return (ins & 0xffffffff00000000ull) | ((ins & 0xffff) << 16) |
((ins & 0xffff0000) >> 16);
}
static ErrorOr<int64_t> calculateRelocation(Reference::KindValue kind,
@ -368,6 +371,7 @@ static ErrorOr<int64_t> calculateRelocation(Reference::KindValue kind,
case R_MIPS_64:
return tgtAddr + addend;
case R_MIPS_SUB:
case R_MICROMIPS_SUB:
return tgtAddr - addend;
case R_MIPS_26:
return reloc26loc(relAddr, tgtAddr, addend, 2);

View File

@ -0,0 +1,62 @@
# Check handling of R_MICROMIPS_SUB relocation.
# RUN: yaml2obj -format=elf %s > %t.o
# RUN: lld -flavor gnu -target mips64el -o %t.exe %t.o
# RUN: llvm-objdump -s -t %t.exe | FileCheck %s
# CHECK: Contents of section .data:
# CHECK-NEXT: 120002000 0020cc01 01000000 0020d001 0100ffff
# ^^ __start - 4 = 0x1200001cc
# ^^ __start - 0x1000000000000
# = 0xffff0001200001d0
# CHECK: SYMBOL TABLE:
# CHECK: 00000001200001d0 g .rodata 00000008 __start
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_REL
Machine: EM_MIPS
Flags: [EF_MIPS_PIC, EF_MIPS_CPIC, EF_MIPS_ARCH_64, EF_MIPS_MICROMIPS]
Sections:
- Name: .text
Type: SHT_PROGBITS
Size: 8
AddressAlign: 16
Flags: [SHF_ALLOC]
- Name: .data
Type: SHT_PROGBITS
Size: 16
AddressAlign: 16
Flags: [SHF_ALLOC, SHF_WRITE]
- Name: .rela.data
Type: SHT_RELA
Info: .data
AddressAlign: 4
Relocations:
- Offset: 0
Symbol: __start
Type: R_MICROMIPS_SUB
Addend: 4
- Offset: 8
Symbol: __start
Type: R_MICROMIPS_SUB
Addend: 0x1000000000000
Symbols:
Global:
- Name: __start
Section: .text
Value: 0
Size: 8
- Name: D1
Section: .data
Value: 0
Size: 8
- Name: D2
Section: .data
Value: 8
Size: 8