[PATCH] D26133: [ELF] Allow relative relocations to absolute symbols in PIC

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 7 12:05:18 PST 2017


phosek updated this revision to Diff 87494.
phosek added a comment.

Added tests.


Repository:
  rL LLVM

https://reviews.llvm.org/D26133

Files:
  ELF/Relocations.cpp
  test/ELF/Inputs/symbol-absolute.s
  test/ELF/linkerscript/symbol-absolute.s
  test/ELF/symbol-absolute.s


Index: test/ELF/symbol-absolute.s
===================================================================
--- /dev/null
+++ test/ELF/symbol-absolute.s
@@ -0,0 +1,13 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %tinput1.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux \
+# RUN:   %S/Inputs/symbol-absolute.s -o %tinput2.o
+# RUN: ld.lld -shared --gc-sections -o %t %tinput1.o %tinput2.o
+# RUN: llvm-readobj --elf-output-style=GNU --file-headers --symbols %t | FileCheck %s
+# CHECK: 0000000000000000     0 NOTYPE  LOCAL  HIDDEN   ABS _BASE
+
+.text
+.globl _start
+_start:
+       lea _BASE(%rip),%rax
Index: test/ELF/linkerscript/symbol-absolute.s
===================================================================
--- /dev/null
+++ test/ELF/linkerscript/symbol-absolute.s
@@ -0,0 +1,12 @@
+# REQUIRES: x86
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
+# RUN: echo "PROVIDE_HIDDEN(_BASE = 0);" > %t.script
+# RUN: ld.lld -shared --gc-sections -o %t1 %t %t.script
+# RUN: llvm-readobj --elf-output-style=GNU --file-headers --symbols %t1 | FileCheck %s
+# CHECK: 0000000000000000     0 NOTYPE  LOCAL  HIDDEN   ABS _BASE
+
+.text
+.globl _start
+_start:
+       lea _BASE(%rip),%rax
Index: test/ELF/Inputs/symbol-absolute.s
===================================================================
--- /dev/null
+++ test/ELF/Inputs/symbol-absolute.s
@@ -0,0 +1,3 @@
+.globl _BASE
+.hidden _BASE
+_BASE = 0
Index: ELF/Relocations.cpp
===================================================================
--- ELF/Relocations.cpp
+++ ELF/Relocations.cpp
@@ -351,6 +351,8 @@
   // between start of a function and '_gp' value and defined as absolute just
   // to simplify the code.
   if (AbsVal && RelE) {
+    if (Body.isLocal() || Body.getVisibility() == STV_HIDDEN)
+      return true;
     if (Body.isUndefined() && !Body.isLocal() && Body.symbol()->isWeak())
       return true;
     if (&Body == ElfSym<ELFT>::MipsGpDisp)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26133.87494.patch
Type: text/x-patch
Size: 1987 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170207/2f192b16/attachment.bin>


More information about the llvm-commits mailing list