Index: lld/ELF/Arch/Hexagon.cpp =================================================================== --- lld/ELF/Arch/Hexagon.cpp +++ lld/ELF/Arch/Hexagon.cpp @@ -54,6 +54,7 @@ // 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 @@ 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: @@ -124,6 +130,11 @@ case R_HEX_GOT_11_X: case R_HEX_GOT_16_X: case R_HEX_GOT_32_6_X: + 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: return R_GOTPLT; case R_HEX_TPREL_11_X: case R_HEX_TPREL_16: @@ -227,6 +238,7 @@ 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 +248,8 @@ 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 +265,8 @@ 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 +301,15 @@ 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; Index: lld/ELF/Relocations.cpp =================================================================== --- lld/ELF/Relocations.cpp +++ lld/ELF/Relocations.cpp @@ -177,7 +177,9 @@ 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. Index: lld/test/ELF/hexagon-tls-ie.s =================================================================== --- /dev/null +++ lld/test/ELF/hexagon-tls-ie.s @@ -0,0 +1,82 @@ +# 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 %t2 +# RUN: llvm-objdump -d --print-imm-hex %t | FileCheck %s +# RUN: llvm-objdump -d --section=.got %t | FileCheck -check-prefix=CHECK-GOT %s +# RUN: llvm-objdump -d --print-imm-hex %t2 | \ +# RUN: FileCheck -check-prefix=SHARED %s +# RUN: llvm-readobj -r %t2 | 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 + + +# Verify that the .got entries are created. +# CHECK-GOT: 000301a4 .got: +# CHECK-GOT-NEXT: 301a4: f0 ff ff ff fffffff0 +# CHECK-GOT-NEXT: 301a8: f4 ff ff ff fffffff4 +# CHECK-GOT-NEXT: 301ac: f8 ff ff ff fffffff8 +# CHECK-GOT-NEXT: 301b0: fc ff ff ff fffffffc + 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