[lld] r269183 - [ELF] implemented -z defs option

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Wed May 11 06:48:42 PDT 2016


Author: grimar
Date: Wed May 11 08:48:41 2016
New Revision: 269183

URL: http://llvm.org/viewvc/llvm-project?rev=269183&view=rev
Log:
[ELF] implemented -z defs option

Just do not allow to link shared library if there are
undefined symbols.

This fixes PR27447

Differential revision: http://reviews.llvm.org/D20169

Added:
    lld/trunk/test/ELF/zdefs.s
Modified:
    lld/trunk/ELF/Config.h
    lld/trunk/ELF/Driver.cpp
    lld/trunk/ELF/Writer.cpp

Modified: lld/trunk/ELF/Config.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Config.h?rev=269183&r1=269182&r2=269183&view=diff
==============================================================================
--- lld/trunk/ELF/Config.h (original)
+++ lld/trunk/ELF/Config.h Wed May 11 08:48:41 2016
@@ -89,6 +89,7 @@ struct Configuration {
   bool VersionScript = false;
   bool WarnCommon;
   bool ZCombreloc;
+  bool ZDefs;
   bool ZExecStack;
   bool ZNodelete;
   bool ZNow;

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=269183&r1=269182&r2=269183&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Wed May 11 08:48:41 2016
@@ -353,6 +353,7 @@ void LinkerDriver::readConfigs(opt::Inpu
     error("number of threads must be > 0");
 
   Config->ZCombreloc = !hasZOption(Args, "nocombreloc");
+  Config->ZDefs = hasZOption(Args, "defs");
   Config->ZExecStack = hasZOption(Args, "execstack");
   Config->ZNodelete = hasZOption(Args, "nodelete");
   Config->ZNow = hasZOption(Args, "now");

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=269183&r1=269182&r2=269183&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed May 11 08:48:41 2016
@@ -793,7 +793,7 @@ static void reportUndefined(SymbolTable<
   if (!Config->NoUndefined) {
     if (Config->Relocatable)
       return;
-    if (Config->Shared)
+    if (Config->Shared && !Config->ZDefs)
       if (Sym->symbol()->Visibility == STV_DEFAULT)
         return;
   }

Added: lld/trunk/test/ELF/zdefs.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/zdefs.s?rev=269183&view=auto
==============================================================================
--- lld/trunk/test/ELF/zdefs.s (added)
+++ lld/trunk/test/ELF/zdefs.s Wed May 11 08:48:41 2016
@@ -0,0 +1,7 @@
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: ld.lld -shared %t.o -o %t1.so
+
+# RUN: not ld.lld -z defs -shared %t.o -o %t1.so 2>&1 | FileCheck -check-prefix=ERR %s
+# ERR: undefined symbol: foo
+
+callq foo at PLT




More information about the llvm-commits mailing list