Skip to content

Commit 2c1a5d2

Browse files
committed
Let llvm-strip continue on encountering an error
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.
1 parent 05589ee commit 2c1a5d2

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

llvm/docs/ReleaseNotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ Changes to the LLVM tools
152152
---------------------------------
153153

154154
* llvm-objcopy now supports the `--update-section` flag for intermediate Mach-O object files.
155+
* llvm-strip now supports continuing to process files on encountering an error.
155156

156157
Changes to LLDB
157158
---------------------------------
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
## Checks that llvm-strip continues to strip objects after encountering a bad
2+
## one while emitting an error for each bad one.
3+
4+
# RUN: echo "bad" > %t1
5+
# RUN: yaml2obj %s -o %t2
6+
# RUN: cp %t1 %t3
7+
# RUN: not llvm-strip --strip-sections %t1 %t2 %t3 2>&1 | FileCheck %s --check-prefix=ERROR -DFILE1=%t1 -DFILE3=%t3 --implicit-check-not=error:
8+
9+
# ERROR: error: '[[FILE1]]': The file was not recognized as a valid object file
10+
# ERROR-NEXT: error: '[[FILE3]]': The file was not recognized as a valid object file
11+
12+
# RUN: llvm-readobj --file-header %t2 | FileCheck %s --check-prefix=NUMSECTIONS
13+
14+
# NUMSECTIONS: SectionHeaderCount: 0
15+
16+
!ELF
17+
FileHeader:
18+
Class: ELFCLASS64
19+
Data: ELFDATA2LSB
20+
Type: ET_EXEC
21+
Machine: EM_X86_64
22+
Sections:
23+
- Name: .debugGlobal
24+
Type: SHT_PROGBITS
25+
Content: "00000000"

llvm/tools/llvm-objcopy/llvm-objcopy.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,16 @@ int llvm_objcopy_main(int argc, char **argv, const llvm::ToolContext &) {
247247
WithColor::error(errs(), ToolName));
248248
return 1;
249249
}
250+
251+
int ret = 0;
250252
for (ConfigManager &ConfigMgr : DriverConfig->CopyConfigs) {
251253
assert(!ConfigMgr.Common.ErrorCallback);
252254
ConfigMgr.Common.ErrorCallback = reportWarning;
253255
if (Error E = executeObjcopy(ConfigMgr)) {
254256
logAllUnhandledErrors(std::move(E), WithColor::error(errs(), ToolName));
255-
return 1;
257+
ret = 1;
256258
}
257259
}
258260

259-
return 0;
261+
return ret;
260262
}

0 commit comments

Comments
 (0)