[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
This commit is contained in:
Richard Howell 2022-03-04 08:00:21 -08:00 committed by Daniel Rodríguez Troitiño
parent 4a94a33ca6
commit 8e6d2fe4d4
3 changed files with 54 additions and 2 deletions

View File

@ -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

View File

@ -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>">;

View File

@ -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);