From: Eugene Leviant Date: Thu, 31 Jan 2019 12:16:20 +0000 (+0000) Subject: [llvm-strip] Add --strip-symbol X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b23da425d4530b54f57a581be5e09e1b07d78b56;p=llvm [llvm-strip] Add --strip-symbol Differential revision: https://reviews.llvm.org/D57440 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@352746 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/tools/llvm-objcopy/ELF/strip-symbol.test b/test/tools/llvm-objcopy/ELF/strip-symbol.test index ab5fee2c271..96c08c1a8df 100644 --- a/test/tools/llvm-objcopy/ELF/strip-symbol.test +++ b/test/tools/llvm-objcopy/ELF/strip-symbol.test @@ -1,6 +1,8 @@ # RUN: yaml2obj %s > %t # RUN: llvm-objcopy --strip-symbol baz -N bar %t %t2 # RUN: llvm-readobj --symbols --sections %t2 | FileCheck %s +# RUN: llvm-strip --strip-symbol baz -N bar %t -o %t3 +# RUN: llvm-readobj --symbols --sections %t3 | FileCheck %s !ELF FileHeader: diff --git a/tools/llvm-objcopy/CopyConfig.cpp b/tools/llvm-objcopy/CopyConfig.cpp index e72733a01f5..169a8ebb77f 100644 --- a/tools/llvm-objcopy/CopyConfig.cpp +++ b/tools/llvm-objcopy/CopyConfig.cpp @@ -480,19 +480,22 @@ DriverConfig parseStripOptions(ArrayRef ArgsArr) { Config.StripAll = InputArgs.hasArg(STRIP_strip_all); Config.StripAllGNU = InputArgs.hasArg(STRIP_strip_all_gnu); - if (!Config.StripDebug && !Config.StripUnneeded && - Config.DiscardMode == DiscardType::None && !Config.StripAllGNU) - Config.StripAll = true; - for (auto Arg : InputArgs.filtered(STRIP_keep_section)) Config.KeepSection.push_back(Arg->getValue()); for (auto Arg : InputArgs.filtered(STRIP_remove_section)) Config.ToRemove.push_back(Arg->getValue()); + for (auto Arg : InputArgs.filtered(STRIP_strip_symbol)) + Config.SymbolsToRemove.push_back(Arg->getValue()); + for (auto Arg : InputArgs.filtered(STRIP_keep_symbol)) Config.SymbolsToKeep.push_back(Arg->getValue()); + if (!Config.StripDebug && !Config.StripUnneeded && + Config.DiscardMode == DiscardType::None && !Config.StripAllGNU && Config.SymbolsToRemove.empty()) + Config.StripAll = true; + Config.DeterministicArchives = InputArgs.hasFlag(STRIP_enable_deterministic_archives, STRIP_disable_deterministic_archives, /*default=*/true); diff --git a/tools/llvm-objcopy/StripOpts.td b/tools/llvm-objcopy/StripOpts.td index 75f703439e9..f0f77254af0 100644 --- a/tools/llvm-objcopy/StripOpts.td +++ b/tools/llvm-objcopy/StripOpts.td @@ -51,6 +51,10 @@ defm remove_section : Eq<"remove-section", "Remove
">, MetaVarName<"section">; def R : JoinedOrSeparate<["-"], "R">, Alias; +defm strip_symbol : Eq<"strip-symbol", "Strip ">, + MetaVarName<"symbol">; +def N : JoinedOrSeparate<["-"], "N">, Alias; + defm keep_section : Eq<"keep-section", "Keep
">, MetaVarName<"section">; defm keep_symbol : Eq<"keep-symbol", "Do not remove symbol ">,