Skip to content

Commit 2267c58

Browse files
committed
[llvm-strip] Add --strip-symbol
Differential revision: https://reviews.llvm.org/D57440 llvm-svn: 352746
1 parent a001008 commit 2267c58

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

llvm/test/tools/llvm-objcopy/ELF/strip-symbol.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# RUN: yaml2obj %s > %t
22
# RUN: llvm-objcopy --strip-symbol baz -N bar %t %t2
33
# RUN: llvm-readobj --symbols --sections %t2 | FileCheck %s
4+
# RUN: llvm-strip --strip-symbol baz -N bar %t -o %t3
5+
# RUN: llvm-readobj --symbols --sections %t3 | FileCheck %s
46

57
!ELF
68
FileHeader:

llvm/tools/llvm-objcopy/CopyConfig.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,19 +480,22 @@ DriverConfig parseStripOptions(ArrayRef<const char *> ArgsArr) {
480480
Config.StripAll = InputArgs.hasArg(STRIP_strip_all);
481481
Config.StripAllGNU = InputArgs.hasArg(STRIP_strip_all_gnu);
482482

483-
if (!Config.StripDebug && !Config.StripUnneeded &&
484-
Config.DiscardMode == DiscardType::None && !Config.StripAllGNU)
485-
Config.StripAll = true;
486-
487483
for (auto Arg : InputArgs.filtered(STRIP_keep_section))
488484
Config.KeepSection.push_back(Arg->getValue());
489485

490486
for (auto Arg : InputArgs.filtered(STRIP_remove_section))
491487
Config.ToRemove.push_back(Arg->getValue());
492488

489+
for (auto Arg : InputArgs.filtered(STRIP_strip_symbol))
490+
Config.SymbolsToRemove.push_back(Arg->getValue());
491+
493492
for (auto Arg : InputArgs.filtered(STRIP_keep_symbol))
494493
Config.SymbolsToKeep.push_back(Arg->getValue());
495494

495+
if (!Config.StripDebug && !Config.StripUnneeded &&
496+
Config.DiscardMode == DiscardType::None && !Config.StripAllGNU && Config.SymbolsToRemove.empty())
497+
Config.StripAll = true;
498+
496499
Config.DeterministicArchives =
497500
InputArgs.hasFlag(STRIP_enable_deterministic_archives,
498501
STRIP_disable_deterministic_archives, /*default=*/true);

llvm/tools/llvm-objcopy/StripOpts.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ defm remove_section : Eq<"remove-section", "Remove <section>">,
5151
MetaVarName<"section">;
5252
def R : JoinedOrSeparate<["-"], "R">, Alias<remove_section>;
5353

54+
defm strip_symbol : Eq<"strip-symbol", "Strip <symbol>">,
55+
MetaVarName<"symbol">;
56+
def N : JoinedOrSeparate<["-"], "N">, Alias<strip_symbol>;
57+
5458
defm keep_section : Eq<"keep-section", "Keep <section>">,
5559
MetaVarName<"section">;
5660
defm keep_symbol : Eq<"keep-symbol", "Do not remove symbol <symbol>">,

0 commit comments

Comments
 (0)