[lld] r234726 - [Mips] Support R_MICROMIPS_GOT_HI/LO16 and R_MICROMIPS_CALL_HI/LO16 relocations
Simon Atanasyan
simon at atanasyan.com
Mon Apr 13 01:20:57 PDT 2015
Author: atanasyan
Date: Mon Apr 13 03:20:57 2015
New Revision: 234726
URL: http://llvm.org/viewvc/llvm-project?rev=234726&view=rev
Log:
[Mips] Support R_MICROMIPS_GOT_HI/LO16 and R_MICROMIPS_CALL_HI/LO16 relocations
Added:
lld/trunk/test/elf/Mips/rel-call-hilo-micro.test
lld/trunk/test/elf/Mips/rel-got-hilo-micro.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=234726&r1=234725&r2=234726&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp Mon Apr 13 03:20:57 2015
@@ -122,6 +122,10 @@ static MipsRelocationParams getRelocatio
case R_MICROMIPS_TLS_GD:
case R_MICROMIPS_TLS_LDM:
case R_MICROMIPS_TLS_GOTTPREL:
+ case R_MICROMIPS_GOT_HI16:
+ case R_MICROMIPS_GOT_LO16:
+ case R_MICROMIPS_CALL_HI16:
+ case R_MICROMIPS_CALL_LO16:
return {4, 0xffff, 0, true};
case R_MIPS_JALR:
return {4, 0x0, 0, false};
@@ -226,12 +230,14 @@ static uint64_t relocGOT(uint64_t S, uin
}
/// \brief R_MIPS_GOT_LO16, R_MIPS_CALL_LO16
+/// R_MICROMIPS_GOT_LO16, R_MICROMIPS_CALL_LO16
/// rel16 G (truncate)
static uint64_t relocGOTLo16(uint64_t S, uint64_t GP) {
return S - GP;
}
-/// \brief R_MIPS_GOT_HI16, R_MIPS_CALL_HI16
+/// \brief R_MIPS_GOT_HI16, R_MIPS_CALL_HI16,
+/// R_MICROMIPS_GOT_HI16, R_MICROMIPS_CALL_HI16
/// rel16 %high(G) (truncate)
static uint64_t relocGOTHi16(uint64_t S, uint64_t GP) {
return (S - GP + 0x8000) >> 16;
@@ -420,9 +426,13 @@ static ErrorOr<uint64_t> calculateReloca
return relocLo16(relAddr, tgtAddr, addend, isGP, true);
case R_MIPS_GOT_LO16:
case R_MIPS_CALL_LO16:
+ case R_MICROMIPS_GOT_LO16:
+ case R_MICROMIPS_CALL_LO16:
return relocGOTLo16(tgtAddr, gpAddr);
case R_MIPS_GOT_HI16:
case R_MIPS_CALL_HI16:
+ case R_MICROMIPS_GOT_HI16:
+ case R_MICROMIPS_CALL_HI16:
return relocGOTHi16(tgtAddr, gpAddr);
case R_MIPS_EH:
case R_MIPS_GOT16:
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=234726&r1=234725&r2=234726&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp Mon Apr 13 03:20:57 2015
@@ -536,6 +536,10 @@ void RelocationPass<ELFT>::handleReferen
case R_MIPS_CALL_LO16:
case R_MICROMIPS_GOT16:
case R_MICROMIPS_CALL16:
+ case R_MICROMIPS_GOT_HI16:
+ case R_MICROMIPS_GOT_LO16:
+ case R_MICROMIPS_CALL_HI16:
+ case R_MICROMIPS_CALL_LO16:
case R_MIPS_GOT_DISP:
case R_MIPS_GOT_PAGE:
handleGOT(ref);
@@ -618,6 +622,8 @@ void RelocationPass<ELFT>::collectRefere
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_MICROMIPS_GOT_HI16 && refKind != R_MICROMIPS_GOT_LO16 &&
+ refKind != R_MICROMIPS_CALL_HI16 && refKind != R_MICROMIPS_CALL_LO16 &&
refKind != R_MIPS_EH)
_requiresPtrEquality.insert(ref.target());
}
@@ -649,7 +655,9 @@ bool RelocationPass<ELFT>::mightBeDynami
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_CALL_HI16 || refKind == R_MIPS_CALL_LO16)
+ refKind == R_MIPS_CALL_HI16 || refKind == R_MIPS_CALL_LO16 ||
+ refKind == R_MICROMIPS_GOT_HI16 || refKind == R_MICROMIPS_GOT_LO16 ||
+ refKind == R_MICROMIPS_CALL_HI16 || refKind == R_MICROMIPS_CALL_LO16)
return true;
if (refKind != R_MIPS_32 && refKind != R_MIPS_64)
@@ -804,7 +812,12 @@ template <typename ELFT> void Relocation
ref.kindValue() == R_MIPS_GOT_HI16 ||
ref.kindValue() == R_MIPS_GOT_LO16 ||
ref.kindValue() == R_MIPS_CALL_HI16 ||
- ref.kindValue() == R_MIPS_CALL_LO16 || ref.kindValue() == R_MIPS_EH)
+ ref.kindValue() == R_MIPS_CALL_LO16 ||
+ ref.kindValue() == R_MICROMIPS_GOT_HI16 ||
+ ref.kindValue() == R_MICROMIPS_GOT_LO16 ||
+ ref.kindValue() == R_MICROMIPS_CALL_HI16 ||
+ ref.kindValue() == R_MICROMIPS_CALL_LO16 ||
+ ref.kindValue() == R_MIPS_EH)
ref.setTarget(getLocalGOTEntry(ref));
else if (isLocal(ref.target()))
ref.setTarget(getLocalGOTPageEntry(ref));
Added: lld/trunk/test/elf/Mips/rel-call-hilo-micro.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/rel-call-hilo-micro.test?rev=234726&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/rel-call-hilo-micro.test (added)
+++ lld/trunk/test/elf/Mips/rel-call-hilo-micro.test Mon Apr 13 03:20:57 2015
@@ -0,0 +1,154 @@
+# Check handling of R_MICROMIPS_CALL_HI16 / R_MICROMIPS_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: 0130 00000000 00001880 00000000 00002080
+# ^ -32744 ^ -32736
+# RAW-NEXT: 0140 00000000 00001c80 00000000 00002480
+# ^ -32740 ^ -32732
+# RAW-NEXT: 0150 00000000 00000000
+
+# RAW: SYMBOL TABLE:
+# RAW: 00000140 l F .text 00000014 T1
+# RAW: 00000154 l F .text 00000004 M1
+
+# GOT: Local entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1008
+# GOT-NEXT: Access: -32744
+# GOT-NEXT: Initial: 0x140
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x100C
+# GOT-NEXT: Access: -32740
+# GOT-NEXT: Initial: 0x155
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1010
+# GOT-NEXT: Access: -32736
+# 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: Entry {
+# GOT-NEXT: Address: 0x1014
+# GOT-NEXT: Access: -32732
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: M2@ (7)
+# 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_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+
+Symbols:
+ Global:
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: M2
+ Section: .text
+ Type: STT_FUNC
+ Value: 4
+ Size: 4
+ Other: [STO_MIPS_MICROMIPS]
+
+# 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_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 40
+ AddressAlign: 16
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MICROMIPS_CALL_HI16
+ - Offset: 4
+ Symbol: T1
+ Type: R_MICROMIPS_CALL_LO16
+ - Offset: 8
+ Symbol: T2
+ Type: R_MICROMIPS_CALL_HI16
+ - Offset: 12
+ Symbol: T2
+ Type: R_MICROMIPS_CALL_LO16
+ - Offset: 16
+ Symbol: M1
+ Type: R_MICROMIPS_CALL_HI16
+ - Offset: 20
+ Symbol: M1
+ Type: R_MICROMIPS_CALL_LO16
+ - Offset: 24
+ Symbol: M2
+ Type: R_MICROMIPS_CALL_HI16
+ - Offset: 28
+ Symbol: M2
+ Type: R_MICROMIPS_CALL_LO16
+
+Symbols:
+ Local:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 16
+ Size: 4
+ - Name: M1
+ Section: .text
+ Type: STT_FUNC
+ Value: 36
+ Size: 4
+ Other: [STO_MIPS_MICROMIPS]
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 16
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: T2
+ - Name: M2
+...
Added: lld/trunk/test/elf/Mips/rel-got-hilo-micro.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/rel-got-hilo-micro.test?rev=234726&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/rel-got-hilo-micro.test (added)
+++ lld/trunk/test/elf/Mips/rel-got-hilo-micro.test Mon Apr 13 03:20:57 2015
@@ -0,0 +1,154 @@
+# Check handling of R_MICROMIPS_GOT_HI16 / R_MICROMIPS_GOT_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: 0130 00000000 00001880 00000000 00002080
+# ^ -32744 ^ -32736
+# RAW-NEXT: 0140 00000000 00001c80 00000000 00002480
+# ^ -32740 ^ -32732
+# RAW-NEXT: 0150 00000000 00000000
+
+# RAW: SYMBOL TABLE:
+# RAW: 00000150 l F .text 00000004 T1
+# RAW: 00000154 l F .text 00000004 M1
+
+# GOT: Local entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1008
+# GOT-NEXT: Access: -32744
+# GOT-NEXT: Initial: 0x150
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x100C
+# GOT-NEXT: Access: -32740
+# GOT-NEXT: Initial: 0x155
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x1010
+# GOT-NEXT: Access: -32736
+# 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: Entry {
+# GOT-NEXT: Address: 0x1014
+# GOT-NEXT: Access: -32732
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: M2@ (7)
+# 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_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+
+Symbols:
+ Global:
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 4
+ - Name: M2
+ Section: .text
+ Type: STT_FUNC
+ Value: 4
+ Size: 4
+ Other: [STO_MIPS_MICROMIPS]
+
+# 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_32R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 40
+ AddressAlign: 16
+ Flags: [SHF_ALLOC, SHF_EXECINSTR]
+
+- Name: .rel.text
+ Type: SHT_REL
+ Info: .text
+ AddressAlign: 4
+ Relocations:
+ - Offset: 0
+ Symbol: T1
+ Type: R_MICROMIPS_GOT_HI16
+ - Offset: 4
+ Symbol: T1
+ Type: R_MICROMIPS_GOT_LO16
+ - Offset: 8
+ Symbol: T2
+ Type: R_MICROMIPS_GOT_HI16
+ - Offset: 12
+ Symbol: T2
+ Type: R_MICROMIPS_GOT_LO16
+ - Offset: 16
+ Symbol: M1
+ Type: R_MICROMIPS_GOT_HI16
+ - Offset: 20
+ Symbol: M1
+ Type: R_MICROMIPS_GOT_LO16
+ - Offset: 24
+ Symbol: M2
+ Type: R_MICROMIPS_GOT_HI16
+ - Offset: 28
+ Symbol: M2
+ Type: R_MICROMIPS_GOT_LO16
+
+Symbols:
+ Local:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 32
+ Size: 4
+ - Name: M1
+ Section: .text
+ Type: STT_FUNC
+ Value: 36
+ Size: 4
+ Other: [STO_MIPS_MICROMIPS]
+ Global:
+ - Name: T0
+ Section: .text
+ Type: STT_FUNC
+ Value: 0
+ Size: 32
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: T2
+ - Name: M2
+...
More information about the llvm-commits
mailing list