Index: test/tools/llvm-objcopy/strip-all-and-keep-symbol.test =================================================================== --- test/tools/llvm-objcopy/strip-all-and-keep-symbol.test +++ test/tools/llvm-objcopy/strip-all-and-keep-symbol.test @@ -1,7 +1,12 @@ # RUN: yaml2obj %s > %t +# RUN: cp %t %t1 # RUN: llvm-objcopy --strip-all --keep-symbol foo %t %t2 # RUN: llvm-readobj -sections -symbols %t2 | FileCheck %s +# RUN: cmp %t %t1 +# RUN: llvm-strip -keep-symbol=foo %t1 +# RUN: cmp %t1 %t2 + !ELF FileHeader: Class: ELFCLASS64 Index: tools/llvm-objcopy/StripOpts.td =================================================================== --- tools/llvm-objcopy/StripOpts.td +++ tools/llvm-objcopy/StripOpts.td @@ -16,3 +16,10 @@ def R : JoinedOrSeparate<["-"], "R">, Alias; + +defm keep_symbol : Eq<"keep-symbol">, + MetaVarName<"symbol">, + HelpText<"Do not remove symbol ">; + +def K : JoinedOrSeparate<["-"], "K">, + Alias; Index: tools/llvm-objcopy/llvm-objcopy.cpp =================================================================== --- tools/llvm-objcopy/llvm-objcopy.cpp +++ tools/llvm-objcopy/llvm-objcopy.cpp @@ -557,6 +557,9 @@ for (auto Arg : InputArgs.filtered(STRIP_remove_section)) Config.ToRemove.push_back(Arg->getValue()); + + for (auto Arg : InputArgs.filtered(STRIP_keep_symbol)) + Config.SymbolsToKeep.push_back(Arg->getValue()); return Config; }