[lld] r321684 - Produce relocations with weak undef if the section is RW.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 2 17:24:58 PST 2018


Author: rafael
Date: Tue Jan  2 17:24:58 2018
New Revision: 321684

URL: http://llvm.org/viewvc/llvm-project?rev=321684&view=rev
Log:
Produce relocations with weak undef if the section is RW.

If a section is RW there is no reason to drop a relocation with a weak
undefined symbol.

Added:
    lld/trunk/test/ELF/weak-undef-rw.s
Modified:
    lld/trunk/ELF/Relocations.cpp

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=321684&r1=321683&r2=321684&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Tue Jan  2 17:24:58 2018
@@ -592,6 +592,12 @@ static RelExpr adjustExpr(Symbol &Sym, R
   if (IsConstant)
     return Expr;
 
+  // We can create any dynamic relocation supported by the dynamic linker if a
+  // section is writable or we are passed -z notext.
+  bool CanWrite = (S.Flags & SHF_WRITE) || !Config->ZText;
+  if (CanWrite && Target->isPicRel(Type))
+    return Expr;
+
   // If the relocation is to a weak undef, and we are producing
   // executable, give up on it and produce a non preemptible 0.
   if (!Config->Shared && Sym.isUndefWeak()) {
@@ -600,12 +606,6 @@ static RelExpr adjustExpr(Symbol &Sym, R
     return Expr;
   }
 
-  // We can create any dynamic relocation supported by the dynamic linker if a
-  // section is writable or we are passed -z notext.
-  bool CanWrite = (S.Flags & SHF_WRITE) || !Config->ZText;
-  if (CanWrite && Target->isPicRel(Type))
-    return Expr;
-
   // If we got here we know that this relocation would require the dynamic
   // linker to write a value to read only memory or use an unsupported
   // relocation.

Added: lld/trunk/test/ELF/weak-undef-rw.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/weak-undef-rw.s?rev=321684&view=auto
==============================================================================
--- lld/trunk/test/ELF/weak-undef-rw.s (added)
+++ lld/trunk/test/ELF/weak-undef-rw.s Tue Jan  2 17:24:58 2018
@@ -0,0 +1,12 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld %t.o -o %t --export-dynamic
+# RUN: llvm-readobj -r %t | FileCheck %s
+
+# CHECK: R_X86_64_64 foobar 0x0
+
+        .global _start
+_start:
+        .data
+        .weak foobar
+        .quad foobar




More information about the llvm-commits mailing list