From: Peter Smith Date: Thu, 20 Oct 2016 09:59:26 +0000 (+0000) Subject: [ELF] Allow relative exceptions relocations in shared libraries X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d648603415b76a9d78be6400ae89dee61098dbdb;p=platform%2Fupstream%2Fllvm.git [ELF] Allow relative exceptions relocations in shared libraries The R_ARM_PREL31 and R_ARM_NONE relocations should not be faulted in shared libraries. In the case of R_ARM_NONE, we have moved the TLS relaxation hint instruction to R_TLSDESC_CALL so that R_HINT can be used without side-effects. In the case of R_ARM_PREL31 we permit it to be used against PLT entries as the personality routines are imported when used in shared libraries. Differential Revision: https://reviews.llvm.org/D25721 llvm-svn: 284710 --- diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp index 25d11ed..43b05e4 100644 --- a/lld/ELF/InputSection.cpp +++ b/lld/ELF/InputSection.cpp @@ -248,6 +248,7 @@ static typename ELFT::uint getSymVA(uint32_t Type, typename ELFT::uint A, const SymbolBody &Body, RelExpr Expr) { switch (Expr) { case R_HINT: + case R_TLSDESC_CALL: llvm_unreachable("cannot relocate hint relocs"); case R_TLSLD: return Out::Got->getTlsIndexOff() + A - Out::Got->getSize(); diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index e29df03..d7228f5 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -143,14 +143,14 @@ static unsigned handleTlsRelocation(uint32_t Type, SymbolBody &Body, return handleNoRelaxTlsRelocation(Type, Body, C, Offset, Addend, Expr); - if ((Expr == R_TLSDESC || Expr == R_TLSDESC_PAGE || Expr == R_HINT) && + if ((Expr == R_TLSDESC || Expr == R_TLSDESC_PAGE || Expr == R_TLSDESC_CALL) && Config->Shared) { if (Out::Got->addDynTlsEntry(Body)) { uintX_t Off = Out::Got->getGlobalDynOffset(Body); Out::RelaDyn->addReloc( {Target->TlsDescRel, Out::Got, Off, false, &Body, 0}); } - if (Expr != R_HINT) + if (Expr != R_TLSDESC_CALL) C.Relocations.push_back({Expr, Type, Offset, Addend, &Body}); return 1; } @@ -177,7 +177,7 @@ static unsigned handleTlsRelocation(uint32_t Type, SymbolBody &Body, return 1; } - if (Expr == R_TLSDESC_PAGE || Expr == R_TLSDESC || Expr == R_HINT || + if (Expr == R_TLSDESC_PAGE || Expr == R_TLSDESC || Expr == R_TLSDESC_CALL || Target->isTlsGlobalDynamicRel(Type)) { if (Config->Shared) { if (Out::Got->addDynTlsEntry(Body)) { @@ -304,9 +304,10 @@ static bool isStaticLinkTimeConstant(RelExpr E, uint32_t Type, // These expressions always compute a constant if (E == R_SIZE || E == R_GOT_FROM_END || E == R_GOT_OFF || E == R_MIPS_GOT_LOCAL_PAGE || E == R_MIPS_GOT_OFF || E == R_MIPS_TLSGD || - E == R_GOT_PAGE_PC || E == R_GOT_PC || E == R_PLT_PC || E == R_TLSGD_PC || - E == R_TLSGD || E == R_PPC_PLT_OPD || E == R_TLSDESC_PAGE || - E == R_HINT || E == R_THUNK_PC || E == R_THUNK_PLT_PC) + E == R_GOT_PAGE_PC || E == R_GOT_PC || E == R_PLT_PC || + E == R_TLSGD_PC || E == R_TLSGD || E == R_PPC_PLT_OPD || + E == R_TLSDESC_CALL || E == R_TLSDESC_PAGE || E == R_HINT || + E == R_THUNK_PC || E == R_THUNK_PLT_PC) return true; // These never do, except if the entire file is position dependent or if @@ -621,8 +622,9 @@ static void scanRelocs(InputSectionBase &C, ArrayRef Rels) { continue; } - // Ignore "hint" relocation because it is for optional code optimization. - if (Expr == R_HINT) + // Ignore "hint" and TLS Descriptor call relocation because they are + // only markers for relaxation. + if (Expr == R_HINT || Expr == R_TLSDESC_CALL) continue; if (needsPlt(Expr) || Expr == R_THUNK_ABS || Expr == R_THUNK_PC || diff --git a/lld/ELF/Relocations.h b/lld/ELF/Relocations.h index 0d0b0f2..3e28ad6 100644 --- a/lld/ELF/Relocations.h +++ b/lld/ELF/Relocations.h @@ -61,6 +61,7 @@ enum RelExpr { R_TLS, R_TLSDESC, R_TLSDESC_PAGE, + R_TLSDESC_CALL, R_TLSGD, R_TLSGD_PC, R_TLSLD, diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp index 66c7875..c1a9471 100644 --- a/lld/ELF/Target.cpp +++ b/lld/ELF/Target.cpp @@ -1172,7 +1172,7 @@ RelExpr AArch64TargetInfo::getRelExpr(uint32_t Type, case R_AARCH64_TLSDESC_ADD_LO12_NC: return R_TLSDESC; case R_AARCH64_TLSDESC_CALL: - return R_HINT; + return R_TLSDESC_CALL; case R_AARCH64_TLSLE_ADD_TPREL_HI12: case R_AARCH64_TLSLE_ADD_TPREL_LO12_NC: return R_TLS; @@ -1541,6 +1541,7 @@ RelExpr ARMTargetInfo::getRelExpr(uint32_t Type, const SymbolBody &S) const { case R_ARM_JUMP24: case R_ARM_PC24: case R_ARM_PLT32: + case R_ARM_PREL31: case R_ARM_THM_JUMP19: case R_ARM_THM_JUMP24: case R_ARM_THM_CALL: @@ -1574,11 +1575,12 @@ RelExpr ARMTargetInfo::getRelExpr(uint32_t Type, const SymbolBody &S) const { return R_GOTONLY_PC; case R_ARM_MOVW_PREL_NC: case R_ARM_MOVT_PREL: - case R_ARM_PREL31: case R_ARM_REL32: case R_ARM_THM_MOVW_PREL_NC: case R_ARM_THM_MOVT_PREL: return R_PC; + case R_ARM_NONE: + return R_HINT; case R_ARM_TLS_LE32: return R_TLS; } @@ -1660,8 +1662,6 @@ RelExpr ARMTargetInfo::getThunkExpr(RelExpr Expr, uint32_t RelocType, void ARMTargetInfo::relocateOne(uint8_t *Loc, uint32_t Type, uint64_t Val) const { switch (Type) { - case R_ARM_NONE: - break; case R_ARM_ABS32: case R_ARM_BASE_PREL: case R_ARM_GOTOFF32: diff --git a/lld/test/ELF/arm-exidx-shared.s b/lld/test/ELF/arm-exidx-shared.s new file mode 100644 index 0000000..b1df072 --- /dev/null +++ b/lld/test/ELF/arm-exidx-shared.s @@ -0,0 +1,44 @@ +// RUN: llvm-mc -filetype=obj -triple=armv7a-none-linux-gnueabi %s -o %t +// RUN: ld.lld %t --shared -o %t2 2>&1 +// RUN: llvm-readobj --relocations %t2 | FileCheck %s +// RUN: llvm-objdump -s -triple=armv7a-none-linux-gnueabi %t2 | FileCheck -check-prefix=CHECK-EXTAB %s + +// Check that the relative R_ARM_PREL31 relocation can access a PLT entry +// for when the personality routine is referenced from a shared library. +// Also check that the R_ARM_NONE no-op relocation can be used in a shared +// library. + .syntax unified +// Will produce an ARM.exidx entry with an R_ARM_NONE relocation to +// __aeabi_unwind_cpp_pr0 + .section .text.func1, "ax",%progbits + .global func1 +func1: + .fnstart + bx lr + .fnend + +// Will produce a R_ARM_PREL31 relocation with respect to the PLT entry of +// __gxx_personality_v0 + .section .text.func2, "ax",%progbits + .global func2 +func2: + .fnstart + bx lr + .personality __gxx_personality_v0 + .handlerdata + .long 0 + .section .text.func2 + .fnend + + .section .text.__aeabi_unwind_cpp_pr0, "ax", %progbits + .global __aeabi_unwind_cpp_pr0 +__aeabi_unwind_cpp_pr0: + bx lr + +// CHECK: Relocations [ +// CHECK-NEXT: Section (6) .rel.plt { +// CHECK-NEXT: 0x300C R_ARM_JUMP_SLOT __gxx_personality_v0 + +// CHECK-EXTAB: Contents of section .ARM.extab.text.func2: +// 0144 + 0ee0 = 0x1024 = __gxx_personality_v0(PLT) +// CHECK-EXTAB-NEXT: 0144 e00e0000 b0b0b000 00000000