Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions llvm/docs/ReleaseNotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,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
---------------------------------
Expand Down
25 changes: 25 additions & 0 deletions llvm/test/tools/llvm-objcopy/strip-error-handling.test
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 4 additions & 2 deletions llvm/tools/llvm-objcopy/llvm-objcopy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}