[PATCH] D35352: [ELF] - Implement filter library support (-F / --filter)
George Rimar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 13 04:55:30 PDT 2017
grimar created this revision.
Herald added a subscriber: emaste.
This is PR33766.
-F name
--filter=name
When creating an ELF shared object, set the internal DT_FILTER field to the specified name. This tells the dynamic linker that the symbol table of the shared object which is being created should be used as a filter on the symbol table of the shared object name.
If you later link a program against this filter object, then, when you run the program, the dynamic linker will see the DT_FILTER field. The dynamic linker will resolve symbols according to the symbol table of the filter object as usual, but it will actually link to the definitions found in the shared object name. Thus the filter object can be used to select a subset of the symbols provided by the object name.
(https://linux.die.net/man/1/ld).
Shared Objects as Filters:
https://docs.oracle.com/cd/E19683-01/817-3677/chapter4-31738/index.html
https://reviews.llvm.org/D35352
Files:
ELF/Config.h
ELF/Driver.cpp
ELF/Options.td
ELF/SyntheticSections.cpp
test/ELF/auxiliary.s
test/ELF/filter.s
Index: test/ELF/filter.s
===================================================================
--- test/ELF/filter.s
+++ test/ELF/filter.s
@@ -0,0 +1,12 @@
+# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+# RUN: ld.lld %t.o -shared -F foo.so -o %t1
+# RUN: llvm-readobj --dynamic-table %t1 | FileCheck %s
+# RUN: ld.lld %t.o -shared --filter=foo.so -o %t2
+# RUN: llvm-readobj --dynamic-table %t2 | FileCheck %s
+
+# CHECK: DynamicSection [
+# CHECK-NEXT: Tag Type Name/Value
+# CHECK-NEXT: 0x000000007FFFFFFF FILTER FilterLibrary (foo.so)
+
+# RUN: not ld.lld %t.o -F x -o %t 2>&1 | FileCheck -check-prefix=ERR %s
+# ERR: -F/--filter may not be used without -shared
Index: test/ELF/auxiliary.s
===================================================================
--- test/ELF/auxiliary.s
+++ test/ELF/auxiliary.s
@@ -4,8 +4,8 @@
# CHECK: DynamicSection [
# CHECK-NEXT: Tag Type Name/Value
-# CHECK-NEXT: 0x000000007FFFFFFD AUXILIARY Auxiliary library: [aaa]
-# CHECK-NEXT: 0x000000007FFFFFFD AUXILIARY Auxiliary library: [bbb]
+# CHECK-NEXT: 0x000000007FFFFFFD AUXILIARY AuxiliaryLibrary (aaa)
+# CHECK-NEXT: 0x000000007FFFFFFD AUXILIARY AuxiliaryLibrary (bbb)
# RUN: not ld.lld %t.o -f aaa --auxiliary bbb -o %t 2>&1 \
# RUN: | FileCheck -check-prefix=ERR %s
Index: ELF/SyntheticSections.cpp
===================================================================
--- ELF/SyntheticSections.cpp
+++ ELF/SyntheticSections.cpp
@@ -1021,6 +1021,8 @@
// fixed early.
for (StringRef S : Config->AuxiliaryList)
add({DT_AUXILIARY, InX::DynStrTab->addString(S)});
+ if (!Config->Filter.empty())
+ add({DT_FILTER, InX::DynStrTab->addString(Config->Filter)});
if (!Config->Rpath.empty())
add({Config->EnableNewDtags ? DT_RUNPATH : DT_RPATH,
InX::DynStrTab->addString(Config->Rpath)});
Index: ELF/Options.td
===================================================================
--- ELF/Options.td
+++ 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: ELF/Driver.cpp
===================================================================
--- ELF/Driver.cpp
+++ ELF/Driver.cpp
@@ -262,6 +262,9 @@
if (!Config->Shared && !Config->AuxiliaryList.empty())
error("-f may not be used without -shared");
+ if (!Config->Shared && !Config->Filter.empty())
+ error("-F/--filter may not be used without -shared");
+
if (Config->Relocatable) {
if (Config->Shared)
error("-r and -shared may not be used together");
@@ -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->Filter = Args.getLastArgValue(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: ELF/Config.h
===================================================================
--- ELF/Config.h
+++ ELF/Config.h
@@ -85,6 +85,7 @@
llvm::StringRef DynamicLinker;
llvm::StringRef Entry;
llvm::StringRef Emulation;
+ llvm::StringRef Filter;
llvm::StringRef Fini;
llvm::StringRef Init;
llvm::StringRef LTOAAPipeline;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D35352.106411.patch
Type: text/x-patch
Size: 3983 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170713/7f51d36f/attachment.bin>
More information about the llvm-commits
mailing list