From 35bee3e06bc02a7575283d4dca1841ca170b373d Mon Sep 17 00:00:00 2001 From: Alexander Shaposhnikov Date: Wed, 23 May 2018 19:44:19 +0000 Subject: [PATCH] [llvm-strip] Expose --keep-symbol option Expose --keep-symbol option in llvm-strip. Test plan: make check-all Differential revision: https://reviews.llvm.org/D47222 llvm-svn: 333117 --- .../tools/llvm-objcopy/strip-all-and-keep-symbol.test | 8 ++++++++ llvm/tools/llvm-objcopy/StripOpts.td | 7 +++++++ llvm/tools/llvm-objcopy/llvm-objcopy.cpp | 3 +++ 3 files changed, 18 insertions(+) diff --git a/llvm/test/tools/llvm-objcopy/strip-all-and-keep-symbol.test b/llvm/test/tools/llvm-objcopy/strip-all-and-keep-symbol.test index 6cb5f855b55b..c0f22b489b16 100644 --- a/llvm/test/tools/llvm-objcopy/strip-all-and-keep-symbol.test +++ b/llvm/test/tools/llvm-objcopy/strip-all-and-keep-symbol.test @@ -1,7 +1,15 @@ # 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 +# Verify that the first run of llvm-objcopy +# has not modified the input binary. +# RUN: cmp %t %t1 + +# RUN: llvm-strip -keep-symbol=foo %t1 +# RUN: cmp %t1 %t2 + !ELF FileHeader: Class: ELFCLASS64 diff --git a/llvm/tools/llvm-objcopy/StripOpts.td b/llvm/tools/llvm-objcopy/StripOpts.td index 1d7a1aec14d4..7c8862f5406c 100644 --- a/llvm/tools/llvm-objcopy/StripOpts.td +++ b/llvm/tools/llvm-objcopy/StripOpts.td @@ -16,3 +16,10 @@ defm remove_section : Eq<"remove-section">, def R : JoinedOrSeparate<["-"], "R">, Alias; + +defm keep_symbol : Eq<"keep-symbol">, + MetaVarName<"symbol">, + HelpText<"Do not remove symbol ">; + +def K : JoinedOrSeparate<["-"], "K">, + Alias; diff --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp index dbe8f8c10ac9..6aac11af1bb7 100644 --- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp +++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp @@ -557,6 +557,9 @@ CopyConfig ParseStripOptions(ArrayRef ArgsArr) { 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; }