[llvm] r351663 - [llvm-objcopy] [COFF] Implement --only-section
Martin Storsjo via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 19 11:42:54 PST 2019
Author: mstorsjo
Date: Sat Jan 19 11:42:54 2019
New Revision: 351663
URL: http://llvm.org/viewvc/llvm-project?rev=351663&view=rev
Log:
[llvm-objcopy] [COFF] Implement --only-section
Differential Revision: https://reviews.llvm.org/D56873
Added:
llvm/trunk/test/tools/llvm-objcopy/COFF/only-section.test
Modified:
llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.cpp
Added: llvm/trunk/test/tools/llvm-objcopy/COFF/only-section.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/COFF/only-section.test?rev=351663&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/COFF/only-section.test (added)
+++ llvm/trunk/test/tools/llvm-objcopy/COFF/only-section.test Sat Jan 19 11:42:54 2019
@@ -0,0 +1,21 @@
+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,SECTIONS-DEBUG,SYMBOLS,SYMBOLS-DEBUG
+
+Adding another section stripping option makes it return the intersection of
+kept sections - in this case keeping only .text.
+
+RUN: llvm-objcopy --only-section .debug_discardable --only-section .text --strip-debug %t.in.exe %t.combination.exe
+RUN: llvm-objdump --section-headers -t %t.combination.exe | FileCheck %s --check-prefixes=SECTIONS,SECTIONS-TEXT,SYMBOLS,SYMBOLS-TEXT
+
+SECTIONS: Sections:
+SECTIONS-NEXT: Idx Name
+SECTIONS-DEBUG-NEXT: .debug_discardable
+SECTIONS-TEXT-NEXT: .text
+SECTIONS-EMPTY:
+
+SYMBOLS: SYMBOL TABLE:
+SYMBOLS-DEBUG-NEXT: debug_discardable_sym
+SYMBOLS-TEXT-NEXT: main
+SYMBOLS-EMPTY:
Modified: llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.cpp?rev=351663&r1=351662&r2=351663&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/COFF/COFFObjcopy.cpp Sat Jan 19 11:42:54 2019
@@ -33,6 +33,12 @@ static bool isDebugSection(const Section
static Error handleArgs(const CopyConfig &Config, Object &Obj) {
// Perform the actual section removals.
Obj.removeSections([&Config](const Section &Sec) {
+ // Contrary to --only-keep-debug, --only-section fully removes sections that
+ // aren't mentioned.
+ if (!Config.OnlySection.empty() &&
+ !is_contained(Config.OnlySection, Sec.Name))
+ return true;
+
if (Config.StripDebug || Config.StripAll || Config.StripAllGNU ||
Config.DiscardAll || Config.StripUnneeded) {
if (isDebugSection(Sec) &&
More information about the llvm-commits
mailing list