[PATCH] D41551: [ELF] - Allow relocation to a weak undefined symbol when -z notext is given.
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 26 00:30:40 PST 2017
grimar updated this revision to Diff 128151.
grimar added a comment.
- Rebased.
https://reviews.llvm.org/D41551
Files:
ELF/Relocations.cpp
test/ELF/retain-und.s
test/ELF/znotext-weak-undef.s
Index: test/ELF/znotext-weak-undef.s
===================================================================
--- test/ELF/znotext-weak-undef.s
+++ test/ELF/znotext-weak-undef.s
@@ -0,0 +1,14 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld -z notext -shared %t.o -o %t
+# RUN: llvm-readobj -r %t | FileCheck %s
+
+# CHECK: Relocations [
+# CHECK-NEXT: ]
+
+.text
+.global foo
+.weak foo
+
+_start:
+mov $foo,%eax
Index: test/ELF/retain-und.s
===================================================================
--- test/ELF/retain-und.s
+++ test/ELF/retain-und.s
@@ -8,9 +8,6 @@
# RUN: llvm-readobj -r %t2.so | FileCheck %s
# CHECK: Relocations [
-# CHECK-NEXT: Section ({{.*}}) .rela.dyn {
-# CHECK-NEXT: 0x{{.*}} R_X86_64_64 foo 0x0
-# CHECK-NEXT: }
# CHECK-NEXT: ]
.data
Index: ELF/Relocations.cpp
===================================================================
--- ELF/Relocations.cpp
+++ ELF/Relocations.cpp
@@ -585,6 +585,19 @@
static RelExpr adjustExpr(Symbol &Sym, RelExpr Expr, RelType Type,
InputSectionBase &S, uint64_t RelOff,
bool &IsConstant) {
+ // If a relocation can be applied at link-time, we don't need to
+ // create a dynamic relocation in the first place.
+ if (IsConstant)
+ return Expr;
+
+ // If the relocation is to a weak undef, give up on it and produce a
+ // non preemptible 0.
+ if (Sym.isUndefWeak()) {
+ Sym.IsPreemptible = false;
+ IsConstant = true;
+ return Expr;
+ }
+
// If a section writable or if we are allowed to create dynamic relocations
// against read-only sections (i.e. when "-z notext" is given), we can create
// any dynamic relocation the dynamic linker knows how to handle.
@@ -596,22 +609,9 @@
return Expr;
}
- // If a relocation can be applied at link-time, we don't need to
- // create a dynamic relocation in the first place.
- if (IsConstant)
- return Expr;
-
// If we got here we know that this relocation would require the dynamic
// linker to write a value to read only memory.
- // If the relocation is to a weak undef, give up on it and produce a
- // non preemptible 0.
- if (Sym.isUndefWeak()) {
- Sym.IsPreemptible = false;
- IsConstant = true;
- return Expr;
- }
-
// We can hack around it if we are producing an executable and
// the refered symbol can be preemepted to refer to the executable.
if (Config->Shared || (Config->Pic && !isRelExpr(Expr))) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41551.128151.patch
Type: text/x-patch
Size: 2527 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171226/6550264d/attachment-0001.bin>
More information about the llvm-commits
mailing list