[PATCH] D56873: [llvm-objcopy] [COFF] Implement --only-section
Martin Storsjö via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 17 12:09:42 PST 2019
mstorsjo created this revision.
mstorsjo added reviewers: jhenderson, alexshap, jakehehrlich, rupprecht, rnk.
This uses the same input data as for --only-keep-debug. As a contrast, --only-keep-debug truncates the other sections, while --only-section fully removes the other sections.
Repository:
rL LLVM
https://reviews.llvm.org/D56873
Files:
test/tools/llvm-objcopy/COFF/only-section.test
tools/llvm-objcopy/COFF/COFFObjcopy.cpp
Index: tools/llvm-objcopy/COFF/COFFObjcopy.cpp
===================================================================
--- tools/llvm-objcopy/COFF/COFFObjcopy.cpp
+++ tools/llvm-objcopy/COFF/COFFObjcopy.cpp
@@ -34,6 +34,16 @@
static Error handleArgs(const CopyConfig &Config, Object &Obj) {
// Perform the actual section removals.
Obj.removeSections([&Config](const Section &Sec) {
+ if (!Config.OnlySection.empty()) {
+ // Explicitly keep these sections.
+ if (is_contained(Config.OnlySection, Sec.Name))
+ return false;
+
+ // Remove everything else. Contrary to --only-keep-debug, --only-section
+ // fully removes everything else.
+ return true;
+ }
+
if (Config.StripDebug || Config.StripAll || Config.StripAllGNU ||
Config.DiscardAll || Config.StripUnneeded) {
if (isDebugSection(Sec) &&
Index: test/tools/llvm-objcopy/COFF/only-section.test
===================================================================
--- /dev/null
+++ test/tools/llvm-objcopy/COFF/only-section.test
@@ -0,0 +1,13 @@
+RUN: yaml2obj %p/Inputs/only-keep-sections.yaml > %t.in.exe
+
+RUN: llvm-objcopy --only-section .debug_discardable %t.in.exe %t.out.exe
+RUN: llvm-objdump --section-headers -t %t.out.exe | FileCheck %s --check-prefixes=SECTIONS,SYMBOLS
+
+SECTIONS: Sections:
+SECTIONS-NEXT: Idx Name
+SECTIONS-NEXT: .debug_discardable
+SECTIONS-NEXT-EMPTY:
+
+SYMBOLS: SYMBOL TABLE:
+SYMBOLS-NEXT: debug_discardable_sym
+SYMBOLS-EMPTY:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D56873.182371.patch
Type: text/x-patch
Size: 1481 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190117/5c186b58/attachment.bin>
More information about the llvm-commits
mailing list