[llvm-objcopy] Add --keep-symbols option

Differential Revision: https://reviews.llvm.org/D60054

llvm-svn: 357418
This commit is contained in:
Yi Kong 2019-04-01 18:12:43 +00:00
parent a9e847238e
commit f2baddb0fc
3 changed files with 20 additions and 0 deletions

View File

@ -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

View File

@ -596,6 +596,10 @@ Expected<DriverConfig> parseObjcopyOptions(ArrayRef<const char *> ArgsArr) {
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<NewSymbolInfo> NSI = parseNewSymbolInfo(Arg->getValue());
if (!NSI)

View File

@ -207,6 +207,15 @@ defm keep_symbol : Eq<"keep-symbol", "Do not remove symbol <symbol>">,
MetaVarName<"symbol">;
def K : JoinedOrSeparate<["-"], "K">, Alias<keep_symbol>;
defm keep_symbols
: Eq<"keep-symbols",
"Reads a list of symbols from <filename> and runs as if "
"--keep-symbol=<symbol> is set for each one. <filename> "
"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. "