[llvm] bd5f29c - [llvm-strip] Let llvm-strip continue on encountering an error (#129531)

via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 7 00:34:32 PST 2025


Author: Tejas Vipin
Date: 2025-03-07T08:34:29Z
New Revision: bd5f29c0081ffe03e6a9cf43bca471e7f82fe71d

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

LOG: [llvm-strip] Let llvm-strip continue on encountering an error (#129531)

This change means that llvm-strip no longer exits immediately upon
encountering an error when modifying a file and will instead continue
modifying the other inputs. Fixes #129412

Added: 
    llvm/test/tools/llvm-objcopy/strip-error-handling.test

Modified: 
    llvm/docs/ReleaseNotes.md
    llvm/tools/llvm-objcopy/llvm-objcopy.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index f2a477d9bdcc9..d7a80ae93aa34 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -159,6 +159,7 @@ Changes to the LLVM tools
 ---------------------------------
 
 * llvm-objcopy now supports the `--update-section` flag for intermediate Mach-O object files.
+* llvm-strip now supports continuing to process files on encountering an error.
 
 Changes to LLDB
 ---------------------------------

diff  --git a/llvm/test/tools/llvm-objcopy/strip-error-handling.test b/llvm/test/tools/llvm-objcopy/strip-error-handling.test
new file mode 100644
index 0000000000000..2db90336c3588
--- /dev/null
+++ b/llvm/test/tools/llvm-objcopy/strip-error-handling.test
@@ -0,0 +1,25 @@
+## Checks that llvm-strip continues to strip objects after encountering a bad
+## one while emitting an error for each bad one.
+
+# RUN: echo "bad" > %t1
+# RUN: yaml2obj %s -o %t2
+# RUN: cp %t1 %t3
+# RUN: not llvm-strip --strip-sections %t1 %t2 %t3 2>&1 | FileCheck %s --check-prefix=ERROR -DFILE1=%t1 -DFILE3=%t3 --implicit-check-not=error:
+
+# ERROR: error: '[[FILE1]]': The file was not recognized as a valid object file
+# ERROR-NEXT: error: '[[FILE3]]': The file was not recognized as a valid object file
+
+# RUN: llvm-readobj --file-header %t2 | FileCheck %s --check-prefix=NUMSECTIONS
+
+# NUMSECTIONS: SectionHeaderCount: 0
+
+!ELF
+FileHeader:
+  Class: ELFCLASS64
+  Data:  ELFDATA2LSB
+  Type:  ET_EXEC
+  Machine: EM_X86_64
+Sections:
+  - Name:    .debugGlobal
+    Type:    SHT_PROGBITS
+    Content: "00000000"

diff  --git a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
index 7e708e309f207..3b1108859faf0 100644
--- a/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
+++ b/llvm/tools/llvm-objcopy/llvm-objcopy.cpp
@@ -247,14 +247,16 @@ int llvm_objcopy_main(int argc, char **argv, const llvm::ToolContext &) {
                           WithColor::error(errs(), ToolName));
     return 1;
   }
+
+  int ret = 0;
   for (ConfigManager &ConfigMgr : DriverConfig->CopyConfigs) {
     assert(!ConfigMgr.Common.ErrorCallback);
     ConfigMgr.Common.ErrorCallback = reportWarning;
     if (Error E = executeObjcopy(ConfigMgr)) {
       logAllUnhandledErrors(std::move(E), WithColor::error(errs(), ToolName));
-      return 1;
+      ret = 1;
     }
   }
 
-  return 0;
+  return ret;
 }


        


More information about the llvm-commits mailing list