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; 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/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<"">, HelpText<"Specify a finalizer function">; @@ -305,6 +307,7 @@ def alias_export_dynamic_E: Flag<["-"], "E">, Alias; def alias_export_dynamic_symbol: J<"export-dynamic-symbol=">, Alias; +def alias_filter: Separate<["-"], "F">, Alias; def alias_fini_fini: J<"fini=">, Alias; def alias_format_b: S<"b">, Alias; def alias_hash_style_hash_style: J<"hash-style=">, Alias; 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: 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: 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