Index: llvm/test/tools/llvm-objcopy/ELF/keep-symbol.test =================================================================== --- llvm/test/tools/llvm-objcopy/ELF/keep-symbol.test +++ llvm/test/tools/llvm-objcopy/ELF/keep-symbol.test @@ -6,6 +6,13 @@ # RUN: llvm-readobj --symbols %t3 | FileCheck %s # RUN: llvm-readobj --symbols %t4 | FileCheck %s --check-prefix=REGEX +# RUN: echo 'foo' > %t.symbols +# RUN: echo 'bar' >> %t.symbols +# RUN: llvm-objcopy --discard-all --keep-symbols %t.symbols %t %t5 +# RUN: llvm-objcopy -K foo -N foo -N bar --keep-symbols %t.symbols -N baz %t %t6 +# RUN: llvm-readobj --symbols %t5 | FileCheck %s +# RUN: llvm-readobj --symbols %t6 | FileCheck %s + !ELF FileHeader: Class: ELFCLASS64 Index: llvm/tools/llvm-objcopy/CopyConfig.cpp =================================================================== --- llvm/tools/llvm-objcopy/CopyConfig.cpp +++ llvm/tools/llvm-objcopy/CopyConfig.cpp @@ -596,6 +596,10 @@ return std::move(E); for (auto Arg : InputArgs.filtered(OBJCOPY_keep_symbol)) Config.SymbolsToKeep.emplace_back(Arg->getValue(), UseRegex); + for (auto Arg : InputArgs.filtered(OBJCOPY_keep_symbols)) + if (Error E = addSymbolsFromFile(Config.SymbolsToKeep, DC.Alloc, + Arg->getValue(), UseRegex)) + return std::move(E); for (auto Arg : InputArgs.filtered(OBJCOPY_add_symbol)) { Expected NSI = parseNewSymbolInfo(Arg->getValue()); if (!NSI) Index: llvm/tools/llvm-objcopy/ObjcopyOpts.td =================================================================== --- llvm/tools/llvm-objcopy/ObjcopyOpts.td +++ llvm/tools/llvm-objcopy/ObjcopyOpts.td @@ -207,6 +207,15 @@ MetaVarName<"symbol">; def K : JoinedOrSeparate<["-"], "K">, Alias; +defm keep_symbols + : Eq<"keep-symbols", + "Reads a list of symbols from and runs as if " + "--keep-symbol= is set for each one. " + "contains one symbol per line and may contain comments beginning with " + "'#'. Leading and trailing whitespace is stripped from each line. May " + "be repeated to read symbols from many files.">, + MetaVarName<"filename">; + def only_keep_debug : Flag<["-", "--"], "only-keep-debug">, HelpText<"Clear sections that would not be stripped by --strip-debug. "