[PATCH] D35352: [ELF] - Implement filter library support (-F / --filter)

George Rimar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 17 02:43:54 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL308167: [ELF] - Implement filter library support (-F / --filter) (authored by grimar).

Changed prior to commit:
  https://reviews.llvm.org/D35352?vs=106597&id=106843#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D35352

Files:
  lld/trunk/ELF/Config.h
  lld/trunk/ELF/Driver.cpp
  lld/trunk/ELF/Options.td
  lld/trunk/ELF/SyntheticSections.cpp
  lld/trunk/test/ELF/filter.s


Index: lld/trunk/ELF/SyntheticSections.cpp
===================================================================
--- lld/trunk/ELF/SyntheticSections.cpp
+++ lld/trunk/ELF/SyntheticSections.cpp
@@ -1024,6 +1024,8 @@
 template <class ELFT> void DynamicSection<ELFT>::addEntries() {
   // Add strings to .dynstr early so that .dynstr's size will be
   // fixed early.
+  for (StringRef S : Config->FilterList)
+    add({DT_FILTER, InX::DynStrTab->addString(S)});
   for (StringRef S : Config->AuxiliaryList)
     add({DT_AUXILIARY, InX::DynStrTab->addString(S)});
   if (!Config->Rpath.empty())
Index: lld/trunk/ELF/Config.h
===================================================================
--- lld/trunk/ELF/Config.h
+++ lld/trunk/ELF/Config.h
@@ -99,6 +99,7 @@
   std::vector<VersionDefinition> VersionDefinitions;
   std::vector<llvm::StringRef> Argv;
   std::vector<llvm::StringRef> AuxiliaryList;
+  std::vector<llvm::StringRef> FilterList;
   std::vector<llvm::StringRef> SearchPaths;
   std::vector<llvm::StringRef> SymbolOrderingFile;
   std::vector<llvm::StringRef> Undefined;
Index: lld/trunk/ELF/Driver.cpp
===================================================================
--- lld/trunk/ELF/Driver.cpp
+++ lld/trunk/ELF/Driver.cpp
@@ -259,6 +259,9 @@
   if (Config->Pie && Config->Shared)
     error("-shared and -pie may not be used together");
 
+  if (!Config->Shared && !Config->FilterList.empty())
+    error("-F may not be used without -shared");
+
   if (!Config->Shared && !Config->AuxiliaryList.empty())
     error("-f may not be used without -shared");
 
@@ -631,6 +634,7 @@
       getArg(Args, OPT_export_dynamic, OPT_no_export_dynamic, false);
   Config->FatalWarnings =
       getArg(Args, OPT_fatal_warnings, OPT_no_fatal_warnings, false);
+  Config->FilterList = getArgs(Args, OPT_filter);
   Config->Fini = Args.getLastArgValue(OPT_fini, "_fini");
   Config->GcSections = getArg(Args, OPT_gc_sections, OPT_no_gc_sections, false);
   Config->GdbIndex = Args.hasArg(OPT_gdb_index);
Index: lld/trunk/ELF/Options.td
===================================================================
--- lld/trunk/ELF/Options.td
+++ lld/trunk/ELF/Options.td
@@ -104,6 +104,8 @@
 def fatal_warnings: F<"fatal-warnings">,
   HelpText<"Treat warnings as errors">;
 
+def filter: J<"filter=">, HelpText<"Set DT_FILTER field to the specified name">;
+
 def fini: S<"fini">, MetaVarName<"<symbol>">,
   HelpText<"Specify a finalizer function">;
 
@@ -305,6 +307,7 @@
 def alias_export_dynamic_E: Flag<["-"], "E">, Alias<export_dynamic>;
 def alias_export_dynamic_symbol: J<"export-dynamic-symbol=">,
   Alias<export_dynamic_symbol>;
+def alias_filter: Separate<["-"], "F">, Alias<filter>;
 def alias_fini_fini: J<"fini=">, Alias<fini>;
 def alias_format_b: S<"b">, Alias<format>;
 def alias_hash_style_hash_style: J<"hash-style=">, Alias<hash_style>;
Index: lld/trunk/test/ELF/filter.s
===================================================================
--- lld/trunk/test/ELF/filter.s
+++ lld/trunk/test/ELF/filter.s
@@ -0,0 +1,15 @@
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld %t.o -shared -F foo.so -F boo.so -o %t1
+# RUN: llvm-readobj --dynamic-table %t1 | FileCheck %s
+
+# Test alias.
+# RUN: ld.lld %t.o -shared --filter=foo.so --filter=boo.so -o %t2
+# RUN: llvm-readobj --dynamic-table %t2 | FileCheck %s
+
+# CHECK:      DynamicSection [
+# CHECK-NEXT: Tag                Type          Name/Value
+# CHECK-NEXT: 0x000000007FFFFFFF FILTER        Filter library: [foo.so]
+# CHECK-NEXT: 0x000000007FFFFFFF FILTER        Filter library: [boo.so]
+
+# RUN: not ld.lld %t.o -F x -o %t 2>&1 | FileCheck -check-prefix=ERR %s
+# ERR: -F may not be used without -shared


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35352.106843.patch
Type: text/x-patch
Size: 3708 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170717/280b8899/attachment.bin>


More information about the llvm-commits mailing list