From 89d7ab0430699067ec4d9ddef393c35f39f21c6d Mon Sep 17 00:00:00 2001 From: Wolfgang Pieb Date: Thu, 8 Aug 2019 00:35:16 +0000 Subject: [PATCH] [llvm-strip] Support --strip-sections llvm-objcopy already supports --strip-sections. It is a good fit for its alias llvm-strip to support it as well. Reviewers: rupprecht, jhenderson Differential Revision: https://reviews.llvm.org/D65787 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@368241 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/tools/llvm-objcopy/ELF/strip-sections.test | 5 +++++ tools/llvm-objcopy/CopyConfig.cpp | 1 + tools/llvm-objcopy/StripOpts.td | 3 +++ 3 files changed, 9 insertions(+) diff --git a/test/tools/llvm-objcopy/ELF/strip-sections.test b/test/tools/llvm-objcopy/ELF/strip-sections.test index 492a0821521..40032d93a3d 100644 --- a/test/tools/llvm-objcopy/ELF/strip-sections.test +++ b/test/tools/llvm-objcopy/ELF/strip-sections.test @@ -8,6 +8,11 @@ # RUN: llvm-objcopy %t %t3 # RUN: od -t x1 -j 4096 -N 12 %t3 | FileCheck %s --check-prefix=VALIDATE +## Check that llvm-strip --strip-sections is equivalent to +## llvm-objcopy --strip-sections. +# RUN: llvm-strip --strip-sections %t -o %t4 +# RUN: cmp %t2 %t4 + !ELF FileHeader: Class: ELFCLASS64 diff --git a/tools/llvm-objcopy/CopyConfig.cpp b/tools/llvm-objcopy/CopyConfig.cpp index 4001aac4ed4..3cd95665139 100644 --- a/tools/llvm-objcopy/CopyConfig.cpp +++ b/tools/llvm-objcopy/CopyConfig.cpp @@ -810,6 +810,7 @@ parseStripOptions(ArrayRef ArgsArr, InputArgs.hasFlag(STRIP_discard_all, STRIP_discard_locals) ? DiscardType::All : DiscardType::Locals; + Config.StripSections = InputArgs.hasArg(STRIP_strip_sections); Config.StripUnneeded = InputArgs.hasArg(STRIP_strip_unneeded); if (auto Arg = InputArgs.getLastArg(STRIP_strip_all, STRIP_no_strip_all)) Config.StripAll = Arg->getOption().getID() == STRIP_strip_all; diff --git a/tools/llvm-objcopy/StripOpts.td b/tools/llvm-objcopy/StripOpts.td index 1d06bb3dfb3..e46d9e8bf10 100644 --- a/tools/llvm-objcopy/StripOpts.td +++ b/tools/llvm-objcopy/StripOpts.td @@ -52,6 +52,9 @@ def strip_debug : Flag<["--"], "strip-debug">, def d : Flag<["-"], "d">, Alias; def g : Flag<["-"], "g">, Alias; def S : Flag<["-"], "S">, Alias; +def strip_sections + : Flag<["--"], "strip-sections">, + HelpText<"Remove all section headers and all sections not in segments">; def strip_unneeded : Flag<["--"], "strip-unneeded">, HelpText<"Remove all symbols not needed by relocations">; -- 2.40.0