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 --- /dev/null +++ b/llvm/test/tools/llvm-objcopy/MachO/bitcode-strip.test @@ -0,0 +1,45 @@ +## 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: llvm-bitcode-strip expects a single output path specified with -o + +--- !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 --- a/llvm/tools/llvm-objcopy/BitcodeStripOpts.td +++ b/llvm/tools/llvm-objcopy/BitcodeStripOpts.td @@ -17,8 +17,11 @@ def h : Flag<["-"], "h">, Alias; def version : Flag<["--"], "version">, - HelpText<"Print the version and exit.">; + HelpText<"Print the version and exit">; def V : Flag<["-"], "V">, Alias, HelpText<"Alias for --version">; + +def output : JoinedOrSeparate<["-"], "o">, HelpText<"Write output to ">, + MetaVarName<"">; diff --git a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp --- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp +++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp @@ -1207,7 +1207,12 @@ "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);