Skip to content

Commit ecc8483

Browse files
[llvm-strip] Add -o option to llvm-strip
This diff implements the option -o for specifying a file to write the output to. Test plan: make check-all Differential revision: https://reviews.llvm.org/D47505 llvm-svn: 333693
1 parent 4037011 commit ecc8483

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

llvm/test/tools/llvm-objcopy/strip-all.test

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,26 @@
11
# RUN: yaml2obj %s > %t
2+
# RUN: cp %t %t3
23
# RUN: llvm-objcopy --strip-all %t %t2
34
# RUN: llvm-readobj -file-headers -sections %t2 | FileCheck %s
45

5-
# We run yaml2obj again rather than copy %t to avoid interfering
6-
# with llvm-objcopy's test (which potentially could have corrupted/updated the binary).
6+
# Verify that the previous llvm-objcopy's run has not modified the input.
7+
# RUN: cmp %t %t3
78

8-
# RUN: yaml2obj %s > %t3
99
# RUN: llvm-strip %t3
10-
# RUN: llvm-readobj -file-headers -sections %t3 | FileCheck %s
1110
# RUN: cmp %t2 %t3
1211

12+
# RUN: cp %t %t4
13+
# RUN: llvm-strip %t4 -o %t5
14+
# RUN: cmp %t2 %t5
15+
16+
# Verify that the previous llvm-strip's run has not modified the input.
17+
# RUN: cmp %t %t4
18+
19+
# RUN: cp %t %t-should-remain-the-same
20+
# RUN: llvm-strip %t4 -o %t-should-remain-the-same -o %t-should-be-stripped
21+
# RUN: cmp %t2 %t-should-be-stripped
22+
# RUN: cmp %t %t-should-remain-the-same
23+
1324
!ELF
1425
FileHeader:
1526
Class: ELFCLASS64

llvm/tools/llvm-objcopy/StripOpts.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ multiclass Eq<string name> {
77

88
def help : Flag<["-", "--"], "help">;
99

10+
defm output : Eq<"o">,
11+
MetaVarName<"output">,
12+
HelpText<"Write output to <file>">;
13+
1014
def strip_debug : Flag<["-", "--"], "strip-debug">,
1115
HelpText<"Remove debugging symbols only">;
1216

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,8 @@ CopyConfig ParseStripOptions(ArrayRef<const char *> ArgsArr) {
582582

583583
CopyConfig Config;
584584
Config.InputFilename = Positional[0];
585-
Config.OutputFilename = Positional[0];
585+
Config.OutputFilename =
586+
InputArgs.getLastArgValue(STRIP_output, Positional[0]);
586587

587588
// Strip debug info only.
588589
Config.StripDebug = InputArgs.hasArg(STRIP_strip_debug);

0 commit comments

Comments
 (0)