[lld] r235288 - [Mips] Support R_MICROMIPS_GOT_DISP / PAGE / OFST relocations handling
Simon Atanasyan
simon at atanasyan.com
Mon Apr 20 00:33:06 PDT 2015
Author: atanasyan
Date: Mon Apr 20 02:33:02 2015
New Revision: 235288
URL: http://llvm.org/viewvc/llvm-project?rev=235288&view=rev
Log:
[Mips] Support R_MICROMIPS_GOT_DISP / PAGE / OFST relocations handling
Added:
lld/trunk/test/elf/Mips/got-page-32-micro.test
lld/trunk/test/elf/Mips/got-page-64-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=235288&r1=235287&r2=235288&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp Mon Apr 20 02:33:02 2015
@@ -123,6 +123,9 @@ static MipsRelocationParams getRelocatio
case R_MICROMIPS_TLS_GD:
case R_MICROMIPS_TLS_LDM:
case R_MICROMIPS_TLS_GOTTPREL:
+ case R_MICROMIPS_GOT_DISP:
+ case R_MICROMIPS_GOT_PAGE:
+ case R_MICROMIPS_GOT_OFST:
case R_MICROMIPS_GOT_HI16:
case R_MICROMIPS_GOT_LO16:
case R_MICROMIPS_CALL_HI16:
@@ -244,7 +247,7 @@ static uint64_t relocGOTHi16(uint64_t S,
return (S - GP + 0x8000) >> 16;
}
-/// R_MIPS_GOT_OFST
+/// R_MIPS_GOT_OFST, R_MICROMIPS_GOT_OFST
/// rel16 offset of (S+A) from the page pointer (verify)
static uint32_t relocGOTOfst(uint64_t S, int64_t A) {
uint64_t page = (S + A + 0x8000) & ~0xffff;
@@ -439,6 +442,8 @@ static ErrorOr<uint64_t> calculateReloca
case R_MIPS_CALL16:
case R_MIPS_GOT_DISP:
case R_MIPS_GOT_PAGE:
+ case R_MICROMIPS_GOT_DISP:
+ case R_MICROMIPS_GOT_PAGE:
case R_MICROMIPS_GOT16:
case R_MICROMIPS_CALL16:
case R_MIPS_TLS_GD:
@@ -449,6 +454,7 @@ static ErrorOr<uint64_t> calculateReloca
case R_MICROMIPS_TLS_GOTTPREL:
return relocGOT(tgtAddr, gpAddr);
case R_MIPS_GOT_OFST:
+ case R_MICROMIPS_GOT_OFST:
return relocGOTOfst(tgtAddr, addend);
case R_MIPS_PC18_S3:
return relocPc18(relAddr, tgtAddr, addend);
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=235288&r1=235287&r2=235288&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp Mon Apr 20 02:33:02 2015
@@ -555,9 +555,12 @@ void RelocationPass<ELFT>::handleReferen
case R_MICROMIPS_CALL_LO16:
case R_MIPS_GOT_DISP:
case R_MIPS_GOT_PAGE:
+ case R_MICROMIPS_GOT_DISP:
+ case R_MICROMIPS_GOT_PAGE:
handleGOT(ref);
break;
case R_MIPS_GOT_OFST:
+ case R_MICROMIPS_GOT_OFST:
// Nothing to do. We create GOT page entry in the R_MIPS_GOT_PAGE handler.
break;
case R_MIPS_GPREL16:
@@ -819,13 +822,15 @@ template <typename ELFT> void Relocation
return;
}
- if (ref.kindValue() == R_MIPS_GOT_PAGE)
+ if (ref.kindValue() == R_MIPS_GOT_PAGE ||
+ ref.kindValue() == R_MICROMIPS_GOT_PAGE)
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_CALL_HI16 ||
ref.kindValue() == R_MIPS_CALL_LO16 ||
+ ref.kindValue() == R_MICROMIPS_GOT_DISP ||
ref.kindValue() == R_MICROMIPS_GOT_HI16 ||
ref.kindValue() == R_MICROMIPS_GOT_LO16 ||
ref.kindValue() == R_MICROMIPS_CALL_HI16 ||
Added: lld/trunk/test/elf/Mips/got-page-32-micro.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/got-page-32-micro.test?rev=235288&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/got-page-32-micro.test (added)
+++ lld/trunk/test/elf/Mips/got-page-32-micro.test Mon Apr 20 02:33:02 2015
@@ -0,0 +1,251 @@
+# Check handling of R_MICROMIPS_GOT_DISP / PAGE / OFST relocations
+# in case of O32 ABI.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor gnu -target mipsel -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -symbols -dyn-symbols -mips-plt-got %t.exe \
+# RUN: | FileCheck -check-prefix=GOT %s
+# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=RAW %s
+
+# GOT: Symbol {
+# GOT: Name: LT3
+# GOT-NEXT: Value: 0x40018D
+# GOT: Symbol {
+# GOT: Name: LT4
+# GOT-NEXT: Value: 0x400191
+# GOT: Symbol {
+# GOT: Name: T0
+# GOT-NEXT: Value: 0x40015D
+# GOT: Symbol {
+# GOT: Name: LT1
+# GOT-NEXT: Value: 0x400185
+# GOT: Symbol {
+# GOT: Name: LT2
+# GOT-NEXT: Value: 0x400189
+# GOT: Symbol {
+# GOT: Name: T1@
+# GOT-NEXT: Value: 0x0
+# GOT: Symbol {
+# GOT: Name: T2@
+# GOT-NEXT: Value: 0x0
+
+# GOT: Primary GOT {
+# GOT-NEXT: Canonical gp value: 0x408FF0
+# GOT-NEXT: Reserved entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401000
+# GOT-NEXT: Access: -32752
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Purpose: Lazy resolver
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401004
+# GOT-NEXT: Access: -32748
+# GOT-NEXT: Initial: 0x80000000
+# GOT-NEXT: Purpose: Module pointer (GNU extension)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Local entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401008
+# GOT-NEXT: Access: -32744
+# GOT-NEXT: Initial: 0x400185
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x40100C
+# GOT-NEXT: Access: -32740
+# GOT-NEXT: Initial: 0x400000
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401010
+# GOT-NEXT: Access: -32736
+# GOT-NEXT: Initial: 0x400000
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401014
+# GOT-NEXT: Access: -32732
+# GOT-NEXT: Initial: 0x40018D
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401018
+# GOT-NEXT: Access: -32728
+# GOT-NEXT: Initial: 0x400000
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x40101C
+# GOT-NEXT: Access: -32724
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T1@
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x401020
+# GOT-NEXT: Access: -32720
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T2@
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Number of TLS and multi-GOT entries: 0
+# GOT-NEXT: }
+
+# RAW: Contents of section .text:
+# RAW-NEXT: {{[0-9a-f]+}} 00002c80 00001880 00002c80 00003080
+# ^ = -32724 (T1)
+# ^ = -32744 (LT1)
+# ^ -32724 (T1)
+# ^ -32720 (T2)
+# RAW-NEXT: {{[0-9a-f]+}} 00001c80 00002080 00000000 00000000
+# ^ -32740 (PAGE)
+# ^ -32736 (PAGE)
+# ^ T1 OFST
+# ^ T2 OFST
+# RAW-NEXT: {{[0-9a-f]+}} 00008501 00008901 00002480 00002880
+# ^ LT1 OFST
+# ^ LT2 OFST
+# ^ = -32732 (LT3)
+# ^ -32728 (PAGE)
+# RAW-NEXT: {{[0-9a-f]+}} 00009101 00000000
+# ^ LT4 OFST
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ARCH_32R2, EF_MIPS_ABI_O32, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 0x4
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 0x4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS32
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ARCH_32R2, EF_MIPS_ABI_O32, EF_MIPS_MICROMIPS]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x4
+ Size: 0x38
+
+ - Name: .rel.text
+ Type: SHT_RELA
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0x0
+ Symbol: T1
+ Type: R_MICROMIPS_GOT_DISP
+ - Offset: 0x4
+ Symbol: LT1
+ Type: R_MICROMIPS_GOT_DISP
+ - Offset: 0x8
+ Symbol: T1
+ Type: R_MICROMIPS_GOT_PAGE
+ - Offset: 0xC
+ Symbol: T2
+ Type: R_MICROMIPS_GOT_PAGE
+ - Offset: 0x10
+ Symbol: LT1
+ Type: R_MICROMIPS_GOT_PAGE
+ - Offset: 0x14
+ Symbol: LT2
+ Type: R_MICROMIPS_GOT_PAGE
+ - Offset: 0x18
+ Symbol: T1
+ Type: R_MICROMIPS_GOT_OFST
+ - Offset: 0x1C
+ Symbol: T2
+ Type: R_MICROMIPS_GOT_OFST
+ - Offset: 0x20
+ Symbol: LT1
+ Type: R_MICROMIPS_GOT_OFST
+ - Offset: 0x24
+ Symbol: LT2
+ Type: R_MICROMIPS_GOT_OFST
+ - Offset: 0x28
+ Symbol: LT3
+ Type: R_MICROMIPS_GOT_DISP
+ - Offset: 0x2C
+ Symbol: LT4
+ Type: R_MICROMIPS_GOT_PAGE
+ - Offset: 0x30
+ Symbol: LT4
+ Type: R_MICROMIPS_GOT_OFST
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+ - Name: LT3
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x30
+ Size: 0x4
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: LT4
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x34
+ Size: 0x4
+ Other: [STO_MIPS_MICROMIPS]
+
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x8
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: LT1
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x28
+ Size: 0x4
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: LT2
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x2c
+ Size: 0x4
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: T1
+ - Name: T2
+...
Added: lld/trunk/test/elf/Mips/got-page-64-micro.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/Mips/got-page-64-micro.test?rev=235288&view=auto
==============================================================================
--- lld/trunk/test/elf/Mips/got-page-64-micro.test (added)
+++ lld/trunk/test/elf/Mips/got-page-64-micro.test Mon Apr 20 02:33:02 2015
@@ -0,0 +1,210 @@
+# Check handling of R_MICROMIPS_GOT_DISP / PAGE / OFST relocations
+# in case of N64 ABI.
+
+# RUN: yaml2obj -format=elf -docnum 1 %s > %t-so.o
+# RUN: lld -flavor gnu -target mips64el -shared -o %t.so %t-so.o
+# RUN: yaml2obj -format=elf -docnum 2 %s > %t-o.o
+# RUN: lld -flavor gnu -target mips64el -e T0 -o %t.exe %t-o.o %t.so
+# RUN: llvm-readobj -symbols -dyn-symbols -mips-plt-got %t.exe \
+# RUN: | FileCheck -check-prefix=GOT %s
+# RUN: llvm-objdump -s %t.exe | FileCheck -check-prefix=RAW %s
+
+# GOT: Symbol {
+# GOT: Name: T0
+# GOT-NEXT: Value: 0x1200001F9
+# GOT: Symbol {
+# GOT: Name: LT1
+# GOT-NEXT: Value: 0x120000221
+# GOT: Symbol {
+# GOT: Name: LT2
+# GOT-NEXT: Value: 0x120000225
+# GOT: Symbol {
+# GOT: Name: T1@
+# GOT-NEXT: Value: 0x0
+# GOT: Symbol {
+# GOT: Name: T2@
+# GOT-NEXT: Value: 0x0
+
+# GOT: Primary GOT {
+# GOT-NEXT: Canonical gp value: 0x120008FF0
+# GOT-NEXT: Reserved entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001000
+# GOT-NEXT: Access: -32752
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Purpose: Lazy resolver
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001008
+# GOT-NEXT: Access: -32744
+# GOT-NEXT: Initial: 0x8000000000000000
+# GOT-NEXT: Purpose: Module pointer (GNU extension)
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Local entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001010
+# GOT-NEXT: Access: -32736
+# GOT-NEXT: Initial: 0x120000221
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001018
+# GOT-NEXT: Access: -32728
+# GOT-NEXT: Initial: 0x120000000
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001020
+# GOT-NEXT: Access: -32720
+# GOT-NEXT: Initial: 0x120000000
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Global entries [
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001028
+# GOT-NEXT: Access: -32712
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T1@
+# GOT-NEXT: }
+# GOT-NEXT: Entry {
+# GOT-NEXT: Address: 0x120001030
+# GOT-NEXT: Access: -32704
+# GOT-NEXT: Initial: 0x0
+# GOT-NEXT: Value: 0x0
+# GOT-NEXT: Type: Function (0x2)
+# GOT-NEXT: Section: Undefined (0x0)
+# GOT-NEXT: Name: T2@
+# GOT-NEXT: }
+# GOT-NEXT: ]
+# GOT-NEXT: Number of TLS and multi-GOT entries: 0
+# GOT-NEXT: }
+
+# RAW: Contents of section .text:
+# RAW-NEXT: {{[0-9a-f]+}} 38800000 20800000 38800000 40800000
+# ^ = -32712 (T1)
+# ^ = -32736 (LT1)
+# ^ -32712 (T1)
+# ^ -32704 (T2)
+# RAW-NEXT: {{[0-9a-f]+}} 28800000 30800000 00000000 00000000
+# ^ -32728 (PAGE)
+# ^ -32720 (PAGE)
+# ^ T1 OFST
+# ^ T2 OFST
+# RAW-NEXT: {{[0-9a-f]+}} 21020000 25020000 00000000 00000000
+# ^ LT1 OFST
+# ^ LT2 OFST
+
+# so.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ARCH_64R2, EF_MIPS_MICROMIPS]
+
+Sections:
+- Name: .text
+ Type: SHT_PROGBITS
+ Size: 8
+ AddressAlign: 16
+ Flags: [SHF_EXECINSTR, SHF_ALLOC]
+
+Symbols:
+ Global:
+ - Name: T1
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x0
+ Size: 0x4
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: T2
+ Section: .text
+ Type: STT_FUNC
+ Value: 0x4
+ Size: 0x4
+
+# o.o
+---
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_REL
+ Machine: EM_MIPS
+ Flags: [EF_MIPS_NOREORDER, EF_MIPS_PIC, EF_MIPS_CPIC,
+ EF_MIPS_ARCH_64R2, EF_MIPS_MICROMIPS]
+
+Sections:
+ - Name: .text
+ Type: SHT_PROGBITS
+ Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
+ AddressAlign: 0x4
+ Size: 0x30
+
+ - Name: .rel.text
+ Type: SHT_RELA
+ Link: .symtab
+ Info: .text
+ AddressAlign: 0x04
+ Relocations:
+ - Offset: 0x0
+ Symbol: T1
+ Type: R_MIPS_GOT_DISP
+ - Offset: 0x4
+ Symbol: LT1
+ Type: R_MIPS_GOT_DISP
+ - Offset: 0x8
+ Symbol: T1
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0xC
+ Symbol: T2
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0x10
+ Symbol: LT1
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0x14
+ Symbol: LT2
+ Type: R_MIPS_GOT_PAGE
+ - Offset: 0x18
+ Symbol: T1
+ Type: R_MIPS_GOT_OFST
+ - Offset: 0x1C
+ Symbol: T2
+ Type: R_MIPS_GOT_OFST
+ - Offset: 0x20
+ Symbol: LT1
+ Type: R_MIPS_GOT_OFST
+ - Offset: 0x24
+ Symbol: LT2
+ Type: R_MIPS_GOT_OFST
+
+Symbols:
+ Local:
+ - Name: .text
+ Type: STT_SECTION
+ Section: .text
+
+ Global:
+ - Name: T0
+ Type: STT_FUNC
+ Section: .text
+ Size: 0x8
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: LT1
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x28
+ Size: 0x4
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: LT2
+ Type: STT_FUNC
+ Section: .text
+ Value: 0x2c
+ Size: 0x4
+ Other: [STO_MIPS_MICROMIPS]
+ - Name: T1
+ - Name: T2
+...
More information about the llvm-commits
mailing list