diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -1325,8 +1325,11 @@ // be resolved within the executable will actually be resolved that way at // runtime, because the main executable is always at the beginning of a search // list. We can leverage that fact. - if (!sym.isPreemptible && (!sym.isGnuIFunc() || config->zIfuncNoplt)) { - if (expr == R_GOT_PC && !isAbsoluteValue(sym)) { + // R_HEX_GD_PLT_B22_PCREL is transformed into a call to __tls_get_addr even + // if the symbol is in the same module. + if (!sym.isPreemptible && (!sym.isGnuIFunc() || config->zIfuncNoplt) && + (type != R_HEX_GD_PLT_B22_PCREL)) { + if (expr == R_GOT_PC && !isAbsoluteValue(sym)) { expr = target->adjustRelaxExpr(type, relocatedAddr, expr); } else { // The 0x8000 bit of r_addend of R_PPC_PLTREL24 is used to choose call diff --git a/lld/test/ELF/hexagon-tls-gd-symbolic.s b/lld/test/ELF/hexagon-tls-gd-symbolic.s new file mode 100644 --- /dev/null +++ b/lld/test/ELF/hexagon-tls-gd-symbolic.s @@ -0,0 +1,35 @@ +# REQUIRES: hexagon +# RUN: llvm-mc -filetype=obj -triple=hexagon-unknown-elf %s -o %t.o +# RUN: ld.lld -Bsymbolic -shared %t.o -o %t.so +# RUN: llvm-objdump -d --no-show-raw-insn --print-imm-hex %t.so | FileCheck -check-prefix DISASM %s +# RUN: llvm-readobj -d %t.so | FileCheck %s +# RUN: llvm-readobj -r %t.so | FileCheck -check-prefix RELOC %s + +# Prior to change affiliated with this test lld for the Hexagon target would +# error out with something like: +# ld.lld: error: relocation R_HEX_GD_PLT_B22_PCREL cannot refer to absolute symbol: a +# Binding to the internal symbol doesn't apply for GDPLT since Hexagon +# will transform the call a@GDPLT to call __tls_get_addr + +.globl _start +.type _start, @function + +_start: + call a@GDPLT +# DISASM: 10210: { call 0x10250 } + + +# CHECK: DynamicSection +# CHECK: 0x0000001E FLAGS SYMBOLIC + +# RELOC: Relocations [ +# RELOC-NEXT: Section (5) .rela.plt { +# RELOC-NEXT: 0x302D4 R_HEX_JMP_SLOT - 0x0 +# RELOC-NEXT: 0x302D8 R_HEX_JMP_SLOT __tls_get_addr 0x0 +# RELOC-NEXT: } +# RELOC-NEXT: ] + +.section .tdata,"awT",@progbits +.globl a +a: +.word 1