From 54b1d56c0152e658c138f464ea45ff8e40ff2fbc Mon Sep 17 00:00:00 2001 From: Simon Atanasyan Date: Fri, 10 Apr 2015 21:00:29 +0000 Subject: [PATCH] [Mips] Support R_MIPS_EH relocation handling The patch supports just the R_MIPS_EH relocation handling and does not implement full specification of compact exception tables for MIPS ABIs. llvm-svn: 234634 --- .../ELF/Mips/MipsRelocationHandler.cpp | 2 + .../ReaderWriter/ELF/Mips/MipsRelocationPass.cpp | 6 +- lld/test/elf/Mips/rel-eh-01.test | 186 +++++++++++++++++++++ lld/test/elf/Mips/rel-eh-02.test | 130 ++++++++++++++ 4 files changed, 322 insertions(+), 2 deletions(-) create mode 100644 lld/test/elf/Mips/rel-eh-01.test create mode 100644 lld/test/elf/Mips/rel-eh-02.test diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp b/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp index 35baebf..c4c8cba 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationHandler.cpp @@ -56,6 +56,7 @@ static MipsRelocationParams getRelocationParams(uint32_t rType) { case R_MIPS_32: case R_MIPS_GPREL32: case R_MIPS_PC32: + case R_MIPS_EH: return {4, 0xffffffff, 0, false}; case LLD_R_MIPS_32_HI16: return {4, 0xffff0000, 0, false}; @@ -401,6 +402,7 @@ static ErrorOr calculateRelocation(Reference::KindValue kind, return relocPcLo16(relAddr, tgtAddr, addend); case R_MICROMIPS_LO16: return relocLo16(relAddr, tgtAddr, addend, isGP, true); + case R_MIPS_EH: case R_MIPS_GOT16: case R_MIPS_CALL16: case R_MIPS_GOT_DISP: diff --git a/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp b/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp index 203957a..0861fc1 100644 --- a/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp +++ b/lld/lib/ReaderWriter/ELF/Mips/MipsRelocationPass.cpp @@ -527,6 +527,7 @@ void RelocationPass::handleReference(const MipsELFDefinedAtom &atom, case R_MICROMIPS_26_S1: handle26(atom, ref); break; + case R_MIPS_EH: case R_MIPS_GOT16: case R_MIPS_CALL16: case R_MICROMIPS_GOT16: @@ -607,7 +608,8 @@ void RelocationPass::collectReferenceInfo( _hasStaticRelocations.insert(ref.target()); if (refKind != R_MIPS_CALL16 && refKind != R_MICROMIPS_CALL16 && - refKind != R_MIPS_26 && refKind != R_MICROMIPS_26_S1) + refKind != R_MIPS_26 && refKind != R_MICROMIPS_26_S1 && + refKind != R_MIPS_EH) _requiresPtrEquality.insert(ref.target()); } @@ -787,7 +789,7 @@ template void RelocationPass::handleGOT(Reference &ref) { if (ref.kindValue() == R_MIPS_GOT_PAGE) ref.setTarget(getLocalGOTPageEntry(ref)); - else if (ref.kindValue() == R_MIPS_GOT_DISP) + else if (ref.kindValue() == R_MIPS_GOT_DISP || ref.kindValue() == R_MIPS_EH) ref.setTarget(getLocalGOTEntry(ref)); else if (isLocal(ref.target())) ref.setTarget(getLocalGOTPageEntry(ref)); diff --git a/lld/test/elf/Mips/rel-eh-01.test b/lld/test/elf/Mips/rel-eh-01.test new file mode 100644 index 0000000..55a0813 --- /dev/null +++ b/lld/test/elf/Mips/rel-eh-01.test @@ -0,0 +1,186 @@ +# Check R_MIPS_EH relocation handling: writing result of a relocation +# calculation, adding GOT entries etc. + +# 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 > %t1.o +# RUN: yaml2obj -format=elf -docnum 3 %s > %t2.o +# RUN: lld -flavor gnu -target mipsel -e T0 -o %t.exe %t1.o %t2.o %t.so +# RUN: llvm-objdump -s -t %t.exe | FileCheck -check-prefix=RAW %s +# RUN: llvm-readobj -mips-plt-got %t.exe | FileCheck -check-prefix=GOT %s + +# RAW: Contents of section .gnu_extab: +# RAW-NEXT: 400178 001880ff ff000000 1c80ffff 2080ffff +# ^ T1 GOT entry = 0xffff8018 = -32744 +# ^ L1 GOT entry = 0xffff801c = -32740 +# E1 GOT entry = 0xffff8020 = -32736 ^ +# RAW: Contents of section .got: +# RAW-NEXT: 401000 00000000 00000080 60014000 00204000 +# RAW-NEXT: 401010 00000000 + +# RAW: SYMBOL TABLE: +# RAW: 00402000 l .data 00000004 L1 +# RAW: 00400160 g F .text 00000004 T1 + +# GOT: Local entries [ +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x401008 +# GOT-NEXT: Access: -32744 +# GOT-NEXT: Initial: 0x400160 +# GOT-NEXT: } +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x40100C +# GOT-NEXT: Access: -32740 +# GOT-NEXT: Initial: 0x402000 +# GOT-NEXT: } +# GOT-NEXT: ] +# GOT-NEXT: Global entries [ +# GOT-NEXT: Entry { +# GOT-NEXT: Address: 0x401010 +# 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: E1@ (1) +# GOT-NEXT: } +# GOT-NEXT: ] +# GOT-NEXT: Number of TLS and multi-GOT entries: 0 + +# so.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_NOREORDER, EF_MIPS_CPIC, EF_MIPS_PIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [SHF_ALLOC, SHF_EXECINSTR] + AddressAlign: 16 + Size: 4 + +Symbols: + Global: + - Name: E1 + Type: STT_FUNC + Section: .text + Value: 0 + Size: 4 + +# t1.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_NOREORDER, EF_MIPS_CPIC, EF_MIPS_PIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [SHF_ALLOC, SHF_EXECINSTR] + AddressAlign: 16 + Size: 4 + +Symbols: + Global: + - Name: T1 + Type: STT_FUNC + Section: .text + Value: 0 + Size: 4 + +# t2.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_NOREORDER, EF_MIPS_CPIC, EF_MIPS_PIC, + EF_MIPS_ABI_O32, EF_MIPS_ARCH_32R2] + +Sections: + - Name: .text + Type: SHT_PROGBITS + Flags: [SHF_ALLOC, SHF_EXECINSTR] + AddressAlign: 16 + Size: 8 + + - Name: .data + Type: SHT_PROGBITS + Flags: [SHF_WRITE, SHF_ALLOC] + AddressAlign: 16 + Size: 4 + + - Name: .gnu_extab + Type: SHT_PROGBITS + Flags: [SHF_ALLOC] + AddressAlign: 4 + Size: 16 + + - Name: .rel.gnu_extab + Type: SHT_REL + Link: .symtab + AddressAlign: 4 + Info: .gnu_extab + Relocations: + - Offset: 1 + Symbol: T1 + Type: R_MIPS_EH + - Offset: 8 + Symbol: L1 + Type: R_MIPS_EH + - Offset: 12 + Symbol: E1 + Type: R_MIPS_EH + + - Name: .eh_frame_entry + Type: SHT_PROGBITS + Flags: [SHF_ALLOC] + AddressAlign: 4 + Content: "0000000100000001" + + - Name: .rel.eh_frame_entry + Type: SHT_REL + Link: .symtab + AddressAlign: 4 + Info: .eh_frame_entry + Relocations: + - Offset: 0 + Symbol: .text + Type: R_MIPS_PC32 + - Offset: 4 + Symbol: .gnu_extab + Type: R_MIPS_PC32 + +Symbols: + Local: + - Name: .text + Type: STT_SECTION + Section: .text + - Name: .gnu_extab + Type: STT_SECTION + Section: .gnu_extab + - Name: L1 + Type: STT_OBJECT + Section: .data + Value: 0 + Size: 4 + + Global: + - Name: T0 + Type: STT_FUNC + Section: .text + Value: 0 + Size: 8 + - Name: E1 + - Name: T1 +... diff --git a/lld/test/elf/Mips/rel-eh-02.test b/lld/test/elf/Mips/rel-eh-02.test new file mode 100644 index 0000000..df2c028 --- /dev/null +++ b/lld/test/elf/Mips/rel-eh-02.test @@ -0,0 +1,130 @@ +# Conditions: +# a) Linking a non-shared executable file. +# b) Relocations' targets are symbols defined in the shared object. +# Check: +# a) The R_MIPS_REL32 relocation is not created for any symbols. +# b) The R_MIPS_COPY relocation is created for the D1 symbol. +# c) No entries in the dynamic symbols table has the STO_MIPS_PLT flag. +# +# 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 -dt -r %t.exe | FileCheck -check-prefix=PLT-SYM %s + +# PLT-SYM: Relocations [ +# PLT-SYM-NEXT: Section (5) .rel.dyn { +# PLT-SYM-NEXT: 0x{{[0-9A-F]+}} R_MIPS_COPY D1 0x0 +# PLT-SYM-NEXT: } + +# PLT-SYM: DynamicSymbols [ +# PLT-SYM-NOT: Other: 8 + +# 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: 8 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 4 + Flags: [SHF_WRITE, SHF_ALLOC] + +Symbols: + Global: + - Name: T1 + Section: .text + Type: STT_FUNC + Value: 0 + Size: 4 + - Name: T2 + Section: .text + Type: STT_FUNC + Value: 4 + Size: 4 + - Name: D1 + Section: .data + Type: STT_OBJECT + Value: 0 + Size: 4 + +# o.o +--- +FileHeader: + Class: ELFCLASS32 + Data: ELFDATA2LSB + Type: ET_REL + Machine: EM_MIPS + Flags: [EF_MIPS_CPIC, EF_MIPS_ABI_O32, EF_MIPS_ARCH_32] + +Sections: +- Name: .text + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_EXECINSTR, SHF_ALLOC] + +- Name: .data + Type: SHT_PROGBITS + Size: 0x08 + AddressAlign: 16 + Flags: [SHF_WRITE, SHF_ALLOC] + +- Name: .rel.text + Type: SHT_REL + Info: .text + AddressAlign: 4 + Relocations: + - Offset: 0 + Symbol: T1 + Type: R_MIPS_26 + - Offset: 4 + Symbol: D1 + Type: R_MIPS_PC32 + +- Name: .rel.data + Type: SHT_REL + Info: .data + AddressAlign: 4 + Relocations: + - Offset: 0 + Symbol: T1 + Type: R_MIPS_EH + - Offset: 4 + Symbol: T2 + Type: R_MIPS_EH + - Offset: 8 + Symbol: D1 + Type: R_MIPS_EH + +Symbols: + Global: + - Name: T0 + Section: .text + Type: STT_FUNC + Value: 0x0 + Size: 8 + - Name: T1 + Type: STT_FUNC + - Name: T2 + Type: STT_FUNC + - Name: D0 + Section: .data + Type: STT_OBJECT + Value: 0x0 + Size: 8 + - Name: D1 + Type: STT_OBJECT +... -- 2.7.4