[PATCH] D26133: [ELF] Relative relocations to absolute symbols in PIC
Petr Hosek via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 30 21:39:13 PDT 2016
phosek created this revision.
phosek added a reviewer: ruiu.
phosek added a subscriber: llvm-commits.
phosek set the repository for this revision to rL LLVM.
phosek added a project: lld.
While these might cause an overflow at runtime on some targets, lld shouldn't reject such a case, it's clearly meaningful and the technique is used on, at least, pre-VDSO GNU/Linux and AIX.
https://llvm.org/bugs/show_bug.cgi?id=30406
Repository:
rL LLVM
https://reviews.llvm.org/D26133
Files:
ELF/Relocations.cpp
test/ELF/relocation-relative-absolute.s
Index: test/ELF/relocation-relative-absolute.s
===================================================================
--- test/ELF/relocation-relative-absolute.s
+++ test/ELF/relocation-relative-absolute.s
@@ -1,11 +1,14 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
-# RUN: not ld.lld %t.o -o %t -pie 2>&1 | FileCheck %s
+# RUN: ld.lld %t.o -o %t -pie
+# RUN: llvm-readobj -dyn-relocations %t | FileCheck %s
+
+# CHECK: Dynamic Relocations {
+# CHECK-NEXT: }
.globl _start
_start:
-# CHECK: relocation R_X86_64_PLT32 cannot refer to absolute symbol answer
call answer at PLT
.globl answer
Index: ELF/Relocations.cpp
===================================================================
--- ELF/Relocations.cpp
+++ ELF/Relocations.cpp
@@ -328,23 +328,8 @@
bool AbsVal = isAbsoluteValue<ELFT>(Body);
bool RelE = isRelExpr(E);
- if (AbsVal && !RelE)
+ if (AbsVal || RelE)
return true;
- if (!AbsVal && RelE)
- return true;
-
- // Relative relocation to an absolute value. This is normally unrepresentable,
- // but if the relocation refers to a weak undefined symbol, we allow it to
- // resolve to the image base. This is a little strange, but it allows us to
- // link function calls to such symbols. Normally such a call will be guarded
- // with a comparison, which will load a zero from the GOT.
- if (AbsVal && RelE) {
- if (Body.isUndefined() && !Body.isLocal() && Body.symbol()->isWeak())
- return true;
- error("relocation " + getRelName(Type) +
- " cannot refer to absolute symbol " + Body.getName());
- return true;
- }
return Target->usesOnlyLowPageBits(Type);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26133.76350.patch
Type: text/x-patch
Size: 1674 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161031/71f86d44/attachment.bin>
More information about the llvm-commits
mailing list