diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -1333,7 +1333,10 @@ // stub type. It should be ignored if optimized to R_PC. if (config->emachine == EM_PPC && expr == R_PPC32_PLTREL) addend &= ~0x8000; - expr = fromPlt(expr); + // R_HEX_GD_PLT_B22_PCREL (call a@GDPLT) is transformed into + // call __tls_get_addr even if the symbol is in the same module. + if (!(config->emachine == EM_HEXAGON && type == R_HEX_GD_PLT_B22_PCREL)) + expr = fromPlt(expr); } } 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,50 @@ +# 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 associated 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 in this particular case +## since Hexagon will transform the call a@GDPLT to call __tls_get_addr +## +## The following produces the code sequence similar to the test: +## __thread int a=1; +## int get() { +## return a; +## } +## When built -fpic and linked with -Bsymbolic the above mentioned +## error surfaced. + +.globl _start +.type _start, @function + +_start: + r2 = add(pc,##_GLOBAL_OFFSET_TABLE_@PCREL) + r0 = add(r2,##a@GDGOT) + call a@GDPLT + r0 = memw(r0+#0) +# DISASM: { immext(#{{.*}}) +# DISASM-NEXT: r2 = add(pc,##{{.*}}) } +# DISASM-NEXT:{ immext(#{{.*}}) +# DISASM-NEXT: r0 = add(r2,##-{{.*}}) } +# DISASM-NEXT:{ call {{.*}} } +# DISASM-NEXT:{ r0 = memw(r0+#0x0) } + + +# CHECK: DynamicSection +# CHECK: 0x0000001E FLAGS SYMBOLIC + +# RELOC: Relocations [ +# RELOC: {{.*}}R_HEX_JMP_SLOT +# RELOC-NEXT: {{.*}}R_HEX_JMP_SLOT __tls_get_addr +# RELOC-NEXT: } +# RELOC-NEXT: ] + +.section .tdata,"awT",@progbits +.globl a +a: +.word 1