[PATCH] D77021: [Hexagon] R_HEX_GD_PLT_B22_PCREL cannot be relaxed.
Sid Manning via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 30 10:16:46 PDT 2020
sidneym updated this revision to Diff 253617.
sidneym added a comment.
Update and add more context to the testcase.
call a at GDPLT is transformed to call __tls_get_addr I added some more context to the testcase to show the sequence. I'm not sure just saying call a at GDPLT is just an alias for call __tls_get_addr is 100% correct but that is basically how I think of it. Section 16.10 of the Hexagon ABI discusses this and the link is here:
http://lists.llvm.org/pipermail/llvm-dev/attachments/20190916/21516a52/attachment-0001.pdf
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D77021/new/
https://reviews.llvm.org/D77021
Files:
lld/ELF/Relocations.cpp
lld/test/ELF/hexagon-tls-gd-symbolic.s
Index: lld/test/ELF/hexagon-tls-gd-symbolic.s
===================================================================
--- /dev/null
+++ 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 at 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_ at PCREL)
+ r0 = add(r2,##a at GDGOT)
+ call a at 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", at progbits
+.globl a
+a:
+.word 1
Index: lld/ELF/Relocations.cpp
===================================================================
--- lld/ELF/Relocations.cpp
+++ 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 at 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);
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77021.253617.patch
Type: text/x-patch
Size: 2464 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200330/5371d3db/attachment-0001.bin>
More information about the llvm-commits
mailing list