[lld] r321499 - Don't try to preempt protected symbols with -z notext.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 27 12:53:13 PST 2017


Author: rafael
Date: Wed Dec 27 12:53:13 2017
New Revision: 321499

URL: http://llvm.org/viewvc/llvm-project?rev=321499&view=rev
Log:
Don't try to preempt protected symbols with -z notext.

I will send a followup patch removing the FIXME this patch adds.

Added:
    lld/trunk/test/ELF/Inputs/znotext-plt-relocations-protected.s
    lld/trunk/test/ELF/znotext-plt-relocations-protected.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=321499&r1=321498&r2=321499&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Wed Dec 27 12:53:13 2017
@@ -598,19 +598,19 @@ static RelExpr adjustExpr(Symbol &Sym, R
     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.
-  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))
-      return getPltExpr(Sym, Expr, IsConstant);
+  // 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.
+  // linker to write a value to read only memory or use an unsupported
+  // relocation.
+
+  // FIXME: This is a hack to avoid changing error messages for now.
+  if (CanWrite && !Sym.isFunc())
+    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.

Added: lld/trunk/test/ELF/Inputs/znotext-plt-relocations-protected.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/znotext-plt-relocations-protected.s?rev=321499&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/znotext-plt-relocations-protected.s (added)
+++ lld/trunk/test/ELF/Inputs/znotext-plt-relocations-protected.s Wed Dec 27 12:53:13 2017
@@ -0,0 +1,5 @@
+.global foo
+.type foo, at function
+.protected foo
+foo:
+ nop

Added: lld/trunk/test/ELF/znotext-plt-relocations-protected.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/znotext-plt-relocations-protected.s?rev=321499&view=auto
==============================================================================
--- lld/trunk/test/ELF/znotext-plt-relocations-protected.s (added)
+++ lld/trunk/test/ELF/znotext-plt-relocations-protected.s Wed Dec 27 12:53:13 2017
@@ -0,0 +1,11 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/znotext-plt-relocations-protected.s -o %t2.o
+# RUN: ld.lld %t2.o -o %t2.so -shared
+# RUN: not ld.lld -z notext %t.o %t2.so -o %t 2>&1 | FileCheck %s
+
+# CHECK: error: cannot preempt symbol: foo
+
+.global _start
+_start:
+callq foo




More information about the llvm-commits mailing list