[llvm] 8e6d2fe - [llvm] add -o flag to llvm-bitcode-strip
Daniel RodrÃguez Troitiño via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 4 08:03:59 PST 2022
Author: Richard Howell
Date: 2022-03-04T08:03:51-08:00
New Revision: 8e6d2fe4d4035b5fe198e06fc08b707b58a64c68
URL: https://github.com/llvm/llvm-project/commit/8e6d2fe4d4035b5fe198e06fc08b707b58a64c68
DIFF: https://github.com/llvm/llvm-project/commit/8e6d2fe4d4035b5fe198e06fc08b707b58a64c68.diff
LOG: [llvm] add -o flag to llvm-bitcode-strip
Add the -o flag to specify an output path for llvm-bitcode-strip.
This matches the interface to the Xcode bitcode_strip tool.
Reviewed By: jhenderson
Differential Revision: https://reviews.llvm.org/D120731
Added:
llvm/test/tools/llvm-objcopy/MachO/bitcode-strip.test
Modified:
llvm/tools/llvm-objcopy/BitcodeStripOpts.td
llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-objcopy/MachO/bitcode-strip.test b/llvm/test/tools/llvm-objcopy/MachO/bitcode-strip.test
new file mode 100644
index 0000000000000..aa19f9d563580
--- /dev/null
+++ b/llvm/test/tools/llvm-objcopy/MachO/bitcode-strip.test
@@ -0,0 +1,44 @@
+## Test output flag is required.
+# RUN: yaml2obj %s -o %t
+# RUN: not llvm-bitcode-strip %t 2>&1 | FileCheck --check-prefix=MISSING-ARG %s
+# RUN: llvm-bitcode-strip %t -o %t2
+# RUN: cmp %t %t2
+
+# MISSING-ARG: llvm-bitcode-strip: error: -o is a required argument
+
+--- !mach-o
+FileHeader:
+ magic: 0xFEEDFACF
+ cputype: 0x01000007
+ cpusubtype: 0x00000003
+ filetype: 0x00000001
+ ncmds: 1
+ sizeofcmds: 152
+ flags: 0x00002000
+ reserved: 0x00000000
+LoadCommands:
+ - cmd: LC_SEGMENT_64
+ cmdsize: 152
+ segname: __TEXT
+ vmaddr: 0
+ vmsize: 4
+ fileoff: 184
+ filesize: 4
+ maxprot: 7
+ initprot: 7
+ nsects: 1
+ flags: 0
+ Sections:
+ - sectname: __text
+ segname: __TEXT
+ addr: 0x0000000000000000
+ content: 'AABBCCDD'
+ size: 4
+ offset: 184
+ align: 0
+ reloff: 0x00000000
+ nreloc: 0
+ flags: 0x80000400
+ reserved1: 0x00000000
+ reserved2: 0x00000000
+ reserved3: 0x00000000
diff --git a/llvm/tools/llvm-objcopy/BitcodeStripOpts.td b/llvm/tools/llvm-objcopy/BitcodeStripOpts.td
index cc178164b03c9..8f945899e8077 100644
--- a/llvm/tools/llvm-objcopy/BitcodeStripOpts.td
+++ b/llvm/tools/llvm-objcopy/BitcodeStripOpts.td
@@ -17,8 +17,11 @@ def help : Flag<["--"], "help">;
def h : Flag<["-"], "h">, Alias<help>;
def version : Flag<["--"], "version">,
- HelpText<"Print the version and exit.">;
+ HelpText<"Print the version and exit">;
def V : Flag<["-"], "V">,
Alias<version>,
HelpText<"Alias for --version">;
+
+def output : JoinedOrSeparate<["-"], "o">, HelpText<"Write output to <file>">,
+ MetaVarName<"<file>">;
diff --git a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
index db3823d1f9c89..c627095205b65 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
+++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
@@ -1221,7 +1221,12 @@ objcopy::parseBitcodeStripOptions(ArrayRef<const char *> ArgsArr) {
"llvm-bitcode-strip expects a single input file");
assert(!Positional.empty());
Config.InputFilename = Positional[0];
- Config.OutputFilename = Positional[0];
+
+ if (!InputArgs.hasArg(BITCODE_STRIP_output)) {
+ return createStringError(errc::invalid_argument,
+ "-o is a required argument");
+ }
+ Config.OutputFilename = InputArgs.getLastArgValue(BITCODE_STRIP_output);
DC.CopyConfigs.push_back(std::move(ConfigMgr));
return std::move(DC);
More information about the llvm-commits
mailing list