[Mips] Support R_MIPS_CALL_HI16 / R_MIPS_CALL_LO16 relocations handling

llvm-svn: 234725
This commit is contained in:
Simon Atanasyan 2015-04-13 08:20:48 +00:00
parent 077372889b
commit 62f261b014
3 changed files with 123 additions and 4 deletions

View File

@ -84,6 +84,8 @@ static MipsRelocationParams getRelocationParams(uint32_t rType) {
case R_MIPS_GOT_OFST:
case R_MIPS_GOT_HI16:
case R_MIPS_GOT_LO16:
case R_MIPS_CALL_HI16:
case R_MIPS_CALL_LO16:
case R_MIPS_TLS_DTPREL_HI16:
case R_MIPS_TLS_DTPREL_LO16:
case R_MIPS_TLS_TPREL_HI16:
@ -223,13 +225,13 @@ static uint64_t relocGOT(uint64_t S, uint64_t GP) {
return G;
}
/// \brief R_MIPS_GOT_LO16
/// \brief R_MIPS_GOT_LO16, R_MIPS_CALL_LO16
/// rel16 G (truncate)
static uint64_t relocGOTLo16(uint64_t S, uint64_t GP) {
return S - GP;
}
/// \brief R_MIPS_GOT_HI16
/// \brief R_MIPS_GOT_HI16, R_MIPS_CALL_HI16
/// rel16 %high(G) (truncate)
static uint64_t relocGOTHi16(uint64_t S, uint64_t GP) {
return (S - GP + 0x8000) >> 16;
@ -417,8 +419,10 @@ static ErrorOr<uint64_t> calculateRelocation(Reference::KindValue kind,
case R_MICROMIPS_LO16:
return relocLo16(relAddr, tgtAddr, addend, isGP, true);
case R_MIPS_GOT_LO16:
case R_MIPS_CALL_LO16:
return relocGOTLo16(tgtAddr, gpAddr);
case R_MIPS_GOT_HI16:
case R_MIPS_CALL_HI16:
return relocGOTHi16(tgtAddr, gpAddr);
case R_MIPS_EH:
case R_MIPS_GOT16:

View File

@ -532,6 +532,8 @@ void RelocationPass<ELFT>::handleReference(const MipsELFDefinedAtom<ELFT> &atom,
case R_MIPS_CALL16:
case R_MIPS_GOT_HI16:
case R_MIPS_GOT_LO16:
case R_MIPS_CALL_HI16:
case R_MIPS_CALL_LO16:
case R_MICROMIPS_GOT16:
case R_MICROMIPS_CALL16:
case R_MIPS_GOT_DISP:
@ -615,6 +617,7 @@ void RelocationPass<ELFT>::collectReferenceInfo(
if (refKind != R_MIPS_CALL16 && refKind != R_MICROMIPS_CALL16 &&
refKind != R_MIPS_26 && refKind != R_MICROMIPS_26_S1 &&
refKind != R_MIPS_GOT_HI16 && refKind != R_MIPS_GOT_LO16 &&
refKind != R_MIPS_CALL_HI16 && refKind != R_MIPS_CALL_LO16 &&
refKind != R_MIPS_EH)
_requiresPtrEquality.insert(ref.target());
}
@ -645,7 +648,8 @@ bool RelocationPass<ELFT>::mightBeDynamic(const MipsELFDefinedAtom<ELFT> &atom,
Reference::KindValue refKind) const {
if (refKind == R_MIPS_CALL16 || refKind == R_MIPS_GOT16 ||
refKind == R_MICROMIPS_CALL16 || refKind == R_MICROMIPS_GOT16 ||
refKind == R_MIPS_GOT_HI16 || refKind == R_MIPS_GOT_LO16)
refKind == R_MIPS_GOT_HI16 || refKind == R_MIPS_GOT_LO16 ||
refKind == R_MIPS_CALL_HI16 || refKind == R_MIPS_CALL_LO16)
return true;
if (refKind != R_MIPS_32 && refKind != R_MIPS_64)
@ -798,7 +802,9 @@ template <typename ELFT> void RelocationPass<ELFT>::handleGOT(Reference &ref) {
ref.setTarget(getLocalGOTPageEntry(ref));
else if (ref.kindValue() == R_MIPS_GOT_DISP ||
ref.kindValue() == R_MIPS_GOT_HI16 ||
ref.kindValue() == R_MIPS_GOT_LO16 || ref.kindValue() == R_MIPS_EH)
ref.kindValue() == R_MIPS_GOT_LO16 ||
ref.kindValue() == R_MIPS_CALL_HI16 ||
ref.kindValue() == R_MIPS_CALL_LO16 || ref.kindValue() == R_MIPS_EH)
ref.setTarget(getLocalGOTEntry(ref));
else if (isLocal(ref.target()))
ref.setTarget(getLocalGOTPageEntry(ref));

View File

@ -0,0 +1,109 @@
# Check handling of R_MIPS_CALL_HI16 / R_MIPS_CALL_LO16 relocations.
# RUN: yaml2obj -format=elf -docnum 1 %s > %t1.so.o
# RUN: lld -flavor gnu -target mipsel -shared -o %t1.so %t1.so.o
# RUN: yaml2obj -format=elf -docnum 2 %s > %t2.so.o
# RUN: lld -flavor gnu -target mipsel -shared -o %t2.so %t2.so.o %t1.so
# RUN: llvm-objdump -s -t %t2.so | FileCheck -check-prefix=RAW %s
# RUN: llvm-readobj -mips-plt-got %t2.so | FileCheck -check-prefix=GOT %s
# RAW: Contents of section .text:
# RAW-NEXT: 0110 00000000 18800000 00000000 1c800000
# ^ -32744 ^ -32740
# RAW-NEXT: 0120 00000000
# RAW: SYMBOL TABLE:
# RAW: 00000120 l F .text 00000004 T1
# GOT: Local entries [
# GOT-NEXT: Entry {
# GOT-NEXT: Address: 0x1008
# GOT-NEXT: Access: -32744
# GOT-NEXT: Initial: 0x120
# GOT-NEXT: }
# GOT-NEXT: ]
# GOT-NEXT: Global entries [
# GOT-NEXT: Entry {
# GOT-NEXT: Address: 0x100C
# GOT-NEXT: Access: -32740
# GOT-NEXT: Initial: 0x0
# GOT-NEXT: Value: 0x0
# GOT-NEXT: Type: Function (0x2)
# GOT-NEXT: Section: Undefined (0x0)
# GOT-NEXT: Name: T2@ (4)
# GOT-NEXT: }
# GOT-NEXT: ]
# t1.so.o
---
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
Size: 4
AddressAlign: 16
Flags: [SHF_ALLOC, SHF_EXECINSTR]
Symbols:
Global:
- Name: T2
Section: .text
Type: STT_FUNC
Value: 0
Size: 4
# t2.so.o
---
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
Size: 20
AddressAlign: 16
Flags: [SHF_ALLOC, SHF_EXECINSTR]
- Name: .rel.text
Type: SHT_REL
Info: .text
AddressAlign: 4
Relocations:
- Offset: 0
Symbol: T1
Type: R_MIPS_CALL_HI16
- Offset: 4
Symbol: T1
Type: R_MIPS_CALL_LO16
- Offset: 8
Symbol: T2
Type: R_MIPS_CALL_HI16
- Offset: 12
Symbol: T2
Type: R_MIPS_CALL_LO16
Symbols:
Local:
- Name: T1
Section: .text
Type: STT_FUNC
Value: 16
Size: 4
Global:
- Name: T0
Section: .text
Type: STT_FUNC
Value: 0
Size: 16
- Name: T2
...