[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
Sun Mar 29 10:41:04 PDT 2020


sidneym created this revision.
sidneym added reviewers: MaskRay, ruiu, bcain, kparzysz.
Herald added subscribers: arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

This type of relocation cannot be relaxed.  The branch referring to the symbol is redirected to __tls_get_addr.

      

Without this change lld could error out with ld.lld: error: relocation R_HEX_GD_PLT_B22_PCREL cannot refer to absolute symbol ... in some cases.


Repository:
  rG LLVM Github Monorepo

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,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 at GDPLT to call __tls_get_addr
+
+.globl _start
+.type _start, @function
+
+_start:
+                   call a at 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", at progbits
+.globl  a
+a:
+.word 1
Index: lld/ELF/Relocations.cpp
===================================================================
--- lld/ELF/Relocations.cpp
+++ 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77021.253435.patch
Type: text/x-patch
Size: 2287 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200329/5b879c93/attachment-0001.bin>


More information about the llvm-commits mailing list