[llvm] 3787de4 - [llvm-objcopy] Make llvm-strip --only-keep-debug suppress default --strip-all

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 18 14:16:16 PDT 2022


Author: John McIver
Date: 2022-04-18T14:16:10-07:00
New Revision: 3787de40de207b6a505e7b110d58ef4497241bff

URL: https://github.com/llvm/llvm-project/commit/3787de40de207b6a505e7b110d58ef4497241bff
DIFF: https://github.com/llvm/llvm-project/commit/3787de40de207b6a505e7b110d58ef4497241bff.diff

LOG: [llvm-objcopy] Make llvm-strip --only-keep-debug suppress default --strip-all

Fixes #54417

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D123798

Added: 
    

Modified: 
    llvm/test/tools/llvm-objcopy/COFF/only-keep-debug.test
    llvm/test/tools/llvm-objcopy/ELF/only-keep-debug.test
    llvm/tools/llvm-objcopy/ObjcopyOptions.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/test/tools/llvm-objcopy/COFF/only-keep-debug.test b/llvm/test/tools/llvm-objcopy/COFF/only-keep-debug.test
index 66cdeea3006b6..3ba5f4eb0cd07 100644
--- a/llvm/test/tools/llvm-objcopy/COFF/only-keep-debug.test
+++ b/llvm/test/tools/llvm-objcopy/COFF/only-keep-debug.test
@@ -3,9 +3,9 @@ RUN: yaml2obj %p/Inputs/only-keep-sections.yaml -o %t.in.exe
 RUN: llvm-objcopy --only-keep-debug %t.in.exe %t.out.exe
 RUN: llvm-readobj --sections %t.out.exe | FileCheck %s --check-prefix=SECTIONS
 RUN: llvm-objdump -t %t.out.exe | FileCheck %s --check-prefix=SYMBOLS
-# Run llvm-strip with --strip-symbol on a non-existent symbol to prevent
-# defaulting to --strip-all.
-RUN: llvm-strip --only-keep-debug --strip-symbol foo %t.in.exe -o %t-strip.out.exe
+
+## --only-keep-debug suppresses the default --strip-all.
+RUN: llvm-strip --only-keep-debug %t.in.exe -o %t-strip.out.exe
 RUN: cmp %t.out.exe %t-strip.out.exe
 
 Check that all non-debug/buildid sections with IMAGE_SCN_CNT_CODE

diff  --git a/llvm/test/tools/llvm-objcopy/ELF/only-keep-debug.test b/llvm/test/tools/llvm-objcopy/ELF/only-keep-debug.test
index 88b937120ace1..c144b1d35c043 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/only-keep-debug.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/only-keep-debug.test
@@ -1,6 +1,9 @@
 # RUN: yaml2obj --docnum=1 %s -o %t1
 # RUN: llvm-objcopy --only-keep-debug %t1 %t1.dbg
 # RUN: llvm-readelf -S -l -x .note1 -x .note2 -x .debug_abbrev -x .debug_frame -x .debug_info %t1.dbg | FileCheck %s
+## --only-keep-debug suppresses the default --strip-all.
+# RUN: llvm-strip --only-keep-debug %t1
+# RUN: llvm-readelf -S -l -x .note1 -x .note2 -x .debug_abbrev -x .debug_frame -x .debug_info %t1 | FileCheck %s
 
 ## Check that SHT_NOTE and .debug* are kept, but others are changed to SHT_NOBITS.
 ## SHT_NOBITS sections do not occupy space in the output.

diff  --git a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
index db17216d8f75f..95046d4d85ccc 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
+++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
@@ -1313,8 +1313,9 @@ objcopy::parseStripOptions(ArrayRef<const char *> RawArgsArr,
       return std::move(E);
 
   if (!InputArgs.hasArg(STRIP_no_strip_all) && !Config.StripDebug &&
-      !Config.StripUnneeded && Config.DiscardMode == DiscardType::None &&
-      !Config.StripAllGNU && Config.SymbolsToRemove.empty())
+      !Config.OnlyKeepDebug && !Config.StripUnneeded &&
+      Config.DiscardMode == DiscardType::None && !Config.StripAllGNU &&
+      Config.SymbolsToRemove.empty())
     Config.StripAll = true;
 
   if (Config.DiscardMode == DiscardType::All) {


        


More information about the llvm-commits mailing list