[lld] r321430 - Allow relocations in rw sections to create plt entries.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 24 11:02:10 PST 2017


Author: rafael
Date: Sun Dec 24 11:02:10 2017
New Revision: 321430

URL: http://llvm.org/viewvc/llvm-project?rev=321430&view=rev
Log:
Allow relocations in rw sections to create plt entries.

If a relocation cannot be implemented by the dynamic linker and the
section is rw, allow creating a plt entry to use as the function
address as if the section was ro.

This matches bfd and gold. It also matches our behavior with -z
notext.

Added:
    lld/trunk/test/ELF/Inputs/writable-sec-plt-reloc.s
    lld/trunk/test/ELF/writable-sec-plt-reloc.s
Modified:
    lld/trunk/ELF/Relocations.cpp
    lld/trunk/test/ELF/x86-64-dyn-rel-error.s
    lld/trunk/test/ELF/x86-64-dyn-rel-error2.s

Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=321430&r1=321429&r2=321430&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Sun Dec 24 11:02:10 2017
@@ -585,14 +585,10 @@ template <class ELFT>
 static RelExpr adjustExpr(Symbol &Sym, RelExpr Expr, RelType Type,
                           InputSectionBase &S, uint64_t RelOff,
                           bool &IsConstant) {
-  // We can create any dynamic relocation if a section is simply writable.
-  if (S.Flags & SHF_WRITE)
-    return Expr;
-
-  // Or, if we are allowed to create dynamic relocations against
-  // read-only sections (i.e. when "-z notext" is given),
-  // we can create a dynamic relocation as we want, too.
-  if (!Config->ZText) {
+  // 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.
+  if ((S.Flags & SHF_WRITE) || !Config->ZText) {
     // We use PLT for relocations that may overflow in runtime,
     // see comment for getPltExpr().
     if (Sym.isFunc() && !Target->isPicRel(Type))

Added: lld/trunk/test/ELF/Inputs/writable-sec-plt-reloc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/writable-sec-plt-reloc.s?rev=321430&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/writable-sec-plt-reloc.s (added)
+++ lld/trunk/test/ELF/Inputs/writable-sec-plt-reloc.s Sun Dec 24 11:02:10 2017
@@ -0,0 +1,4 @@
+        .global foo
+        .type foo, @function
+foo:
+        retq

Added: lld/trunk/test/ELF/writable-sec-plt-reloc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/writable-sec-plt-reloc.s?rev=321430&view=auto
==============================================================================
--- lld/trunk/test/ELF/writable-sec-plt-reloc.s (added)
+++ lld/trunk/test/ELF/writable-sec-plt-reloc.s Sun Dec 24 11:02:10 2017
@@ -0,0 +1,14 @@
+# REQUIRES: x86
+# RUN: llvm-mc %s -o %t.o -filetype=obj -triple=x86_64-pc-linux
+# RUN: llvm-mc %p/Inputs/writable-sec-plt-reloc.s -o %t2.o -filetype=obj -triple=x86_64-pc-linux
+# RUN: ld.lld %t2.o -o %t2.so -shared
+# RUN: ld.lld %t.o %t2.so -o %t
+# RUN: llvm-readelf --symbols -r %t | FileCheck %s
+
+# CHECK: R_X86_64_JUMP_SLOT {{.*}} foo + 0
+# CHECK: 0000000000201010     0 FUNC    GLOBAL DEFAULT  UND foo
+
+.section .bar,"awx"
+.global _start
+_start:
+        call foo

Modified: lld/trunk/test/ELF/x86-64-dyn-rel-error.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/x86-64-dyn-rel-error.s?rev=321430&r1=321429&r2=321430&view=diff
==============================================================================
--- lld/trunk/test/ELF/x86-64-dyn-rel-error.s (original)
+++ lld/trunk/test/ELF/x86-64-dyn-rel-error.s Sun Dec 24 11:02:10 2017
@@ -7,7 +7,7 @@
         .global _start
 _start:
         .data
-        .long bar
+        .long zed
 
 // CHECK: relocation R_X86_64_32 cannot be used against shared object; recompile with -fPIC
 

Modified: lld/trunk/test/ELF/x86-64-dyn-rel-error2.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/x86-64-dyn-rel-error2.s?rev=321430&r1=321429&r2=321430&view=diff
==============================================================================
--- lld/trunk/test/ELF/x86-64-dyn-rel-error2.s (original)
+++ lld/trunk/test/ELF/x86-64-dyn-rel-error2.s Sun Dec 24 11:02:10 2017
@@ -11,4 +11,4 @@
         .global _start
 _start:
         .data
-        .long bar - .
+        .long zed - .




More information about the llvm-commits mailing list