From 0fa8f701ccf6f29544394b358f38b748e3f7ab24 Mon Sep 17 00:00:00 2001 From: Sid Manning Date: Thu, 2 Jan 2020 12:54:59 -0600 Subject: [PATCH] [ELF][Hexagon] Add support for IE relocations Differential Revision: https://reviews.llvm.org/D71143 --- lld/ELF/Arch/Hexagon.cpp | 22 ++++++++++++ lld/ELF/Relocations.cpp | 4 ++- lld/test/ELF/hexagon-tls-ie.s | 78 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 lld/test/ELF/hexagon-tls-ie.s diff --git a/lld/ELF/Arch/Hexagon.cpp b/lld/ELF/Arch/Hexagon.cpp index d29932d..106bc9b 100644 --- a/lld/ELF/Arch/Hexagon.cpp +++ b/lld/ELF/Arch/Hexagon.cpp @@ -54,6 +54,7 @@ Hexagon::Hexagon() { // Hexagon Linux uses 64K pages by default. defaultMaxPageSize = 0x10000; noneRel = R_HEX_NONE; + tlsGotRel = R_HEX_TPREL_32; } uint32_t Hexagon::calcEFlags() const { @@ -115,6 +116,11 @@ RelExpr Hexagon::getRelExpr(RelType type, const Symbol &s, case R_HEX_B22_PCREL_X: case R_HEX_B32_PCREL_X: return R_PLT_PC; + case R_HEX_IE_32_6_X: + case R_HEX_IE_16_X: + case R_HEX_IE_HI16: + case R_HEX_IE_LO16: + return R_GOT; case R_HEX_GOTREL_11_X: case R_HEX_GOTREL_16_X: case R_HEX_GOTREL_32_6_X: @@ -125,6 +131,13 @@ RelExpr Hexagon::getRelExpr(RelType type, const Symbol &s, case R_HEX_GOT_16_X: case R_HEX_GOT_32_6_X: return R_GOTPLT; + case R_HEX_IE_GOT_11_X: + case R_HEX_IE_GOT_16_X: + case R_HEX_IE_GOT_32_6_X: + case R_HEX_IE_GOT_HI16: + case R_HEX_IE_GOT_LO16: + config->hasStaticTlsModel = true; + return R_GOTPLT; case R_HEX_TPREL_11_X: case R_HEX_TPREL_16: case R_HEX_TPREL_16_X: @@ -227,6 +240,7 @@ void Hexagon::relocateOne(uint8_t *loc, RelType type, uint64_t val) const { or32le(loc, applyMask(0x00203fe0, val & 0x3f)); break; case R_HEX_11_X: + case R_HEX_IE_GOT_11_X: case R_HEX_GOT_11_X: case R_HEX_GOTREL_11_X: case R_HEX_TPREL_11_X: @@ -236,6 +250,8 @@ void Hexagon::relocateOne(uint8_t *loc, RelType type, uint64_t val) const { or32le(loc, applyMask(0x000007e0, val)); break; case R_HEX_16_X: // These relocs only have 6 effective bits. + case R_HEX_IE_16_X: + case R_HEX_IE_GOT_16_X: case R_HEX_GOT_16_X: case R_HEX_GOTREL_16_X: case R_HEX_TPREL_16_X: @@ -251,6 +267,8 @@ void Hexagon::relocateOne(uint8_t *loc, RelType type, uint64_t val) const { case R_HEX_32_6_X: case R_HEX_GOT_32_6_X: case R_HEX_GOTREL_32_6_X: + case R_HEX_IE_GOT_32_6_X: + case R_HEX_IE_32_6_X: case R_HEX_TPREL_32_6_X: or32le(loc, applyMask(0x0fff3fff, val >> 6)); break; @@ -285,11 +303,15 @@ void Hexagon::relocateOne(uint8_t *loc, RelType type, uint64_t val) const { break; case R_HEX_GOTREL_HI16: case R_HEX_HI16: + case R_HEX_IE_GOT_HI16: + case R_HEX_IE_HI16: case R_HEX_TPREL_HI16: or32le(loc, applyMask(0x00c03fff, val >> 16)); break; case R_HEX_GOTREL_LO16: case R_HEX_LO16: + case R_HEX_IE_GOT_LO16: + case R_HEX_IE_LO16: case R_HEX_TPREL_LO16: or32le(loc, applyMask(0x00c03fff, val)); break; diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index 8025779..1df8a15 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -177,7 +177,9 @@ handleTlsRelocation(RelType type, Symbol &sym, InputSectionBase &c, return 1; } - bool canRelax = config->emachine != EM_ARM && config->emachine != EM_RISCV; + bool canRelax = config->emachine != EM_ARM && + config->emachine != EM_HEXAGON && + config->emachine != EM_RISCV; // If we are producing an executable and the symbol is non-preemptable, it // must be defined and the code sequence can be relaxed to use Local-Exec. diff --git a/lld/test/ELF/hexagon-tls-ie.s b/lld/test/ELF/hexagon-tls-ie.s new file mode 100644 index 0000000..ea05279 --- /dev/null +++ b/lld/test/ELF/hexagon-tls-ie.s @@ -0,0 +1,78 @@ +# REQUIRES: hexagon +# RUN: llvm-mc -filetype=obj -triple=hexagon-unknown-elf %s -o %t.o +# RUN: llvm-readobj -r %t.o | FileCheck -check-prefix=RELOC %s +# RUN: ld.lld %t.o -o %t +## shared needs -z notext because of the R_HEX_IE_16/32_X(R_GOT) static +## relocations +# RUN: ld.lld -z notext -shared %t.o -o %t.so +# RUN: llvm-objdump -d --no-show-raw-insn --print-imm-hex %t | FileCheck %s +# RUN: llvm-readobj -x .got %t | FileCheck -check-prefix=GOT %s +# RUN: llvm-objdump -d --no-show-raw-insn --print-imm-hex %t.so | \ +# RUN: FileCheck -check-prefix=SHARED %s +# RUN: llvm-readobj -r %t.so | FileCheck -check-prefix=RELA %s + + .globl _start + .type _start, @function +_start: + +# RELOC: 0x0 R_HEX_IE_32_6_X a 0x0 +# RELOC-NEXT: 0x4 R_HEX_IE_16_X a 0x0 +# CHECK: { immext(#0x30180) +# CHECK-NEXT: r2 = memw(##0x301a4) } + r2 = memw(##a@IE) + +# RELOC-NEXT: 0x8 R_HEX_IE_LO16 a 0x0 +# CHECK: { r2.l = #0x1a4 } + r2.l = #a@IE +# RELOC-NEXT: 0xC R_HEX_IE_HI16 a 0x0 +# CHECK: { r2.h = #0x3 } + r2.h = #a@IE + + +# GOT: Hex dump of section '.got': +# GOT-NEXT: 0x000301a4 f0ffffff f4ffffff f8ffffff fcffffff + r2 = memw(##a@IE) + r2 = memw(##b@IE) + r2 = memw(##c@IE) + r2 = memw(##d@IE) + +# RELOC: 0x30 R_HEX_IE_GOT_32_6_X a 0x0 +# RELOC-NEXT: 0x34 R_HEX_IE_GOT_16_X a 0x0 +# SHARED: { immext(#0xfffeffc0) +# SHARED-NEXT: r2 = memw(##0xfffefff0) } + r2 = memw(##a@IEGOT) + +# RELOC-NEXT: 0x38 R_HEX_IE_GOT_LO16 a 0x0 +# SHARED: { r2.l = #0xfff0 } + r2.l = #a@IEGOT +# RELOC-NEXT: 0x3C R_HEX_IE_GOT_HI16 a 0x0 +# SHARED: { r2.h = #0xfffe } + r2.h = #a@IEGOT + +# RELOC: 0x44 R_HEX_IE_GOT_11_X a 0x0 +# SHARED: { immext(#0xfffeffc0) +# SHARED-NEXT: r0 = !cmp.eq(r1,##-0x10010) } + r0=!cmp.eq(r1,##a@iegot) + +# RELA: 0x203C4 R_HEX_TPREL_32 a 0x0 +# RELA-NEXT: 0x203C8 R_HEX_TPREL_32 b 0x0 +# RELA-NEXT: 0x203CC R_HEX_TPREL_32 c 0x0 +# RELA-NEXT: 0x203D0 R_HEX_TPREL_32 d 0x0 + r2 = memw(##b@IEGOT) + r2 = memw(##c@IEGOT) + r2 = memw(##d@IEGOT) + + +.section .tdata,"awT",@progbits +.globl a +a: +.word 1 +.globl b +b: +.word 2 +.globl c +c: +.word 3 +.globl d +d: +.word 4 -- 2.7.4