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,68 @@ +## Test output flag is required + +# RUN: yaml2obj %s -o %t +# RUN: not llvm-bitcode-strip %t +# RUN: llvm-bitcode-strip %t -o %t2 + +--- !mach-o +FileHeader: + magic: 0xFEEDFACF + cputype: 0x01000007 + cpusubtype: 0x00000003 + filetype: 0x00000001 + ncmds: 1 + sizeofcmds: 312 + flags: 0x00002000 + reserved: 0x00000000 +LoadCommands: + - cmd: LC_SEGMENT_64 + cmdsize: 312 + segname: '' + vmaddr: 0 + vmsize: 12 + fileoff: 344 + filesize: 12 + maxprot: 7 + initprot: 7 + nsects: 3 + flags: 0 + Sections: + - sectname: __text + segname: __TEXT + addr: 0x0000000000000000 + content: 'AABBCCDD' + size: 4 + offset: 344 + align: 0 + reloff: 0x00000000 + nreloc: 0 + flags: 0x80000400 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 + - sectname: __data + segname: __DATA + addr: 0x0000000000000004 + content: 'DDAADDAA' + size: 4 + offset: 348 + align: 0 + reloff: 0x00000000 + nreloc: 0 + flags: 0x00000000 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 + - sectname: __bundle + segname: __LLVM + addr: 0x0000000000000008 + content: 'EEFFEEFF' + size: 4 + offset: 352 + align: 0 + reloff: 0x00000000 + nreloc: 0 + flags: 0x00000000 + 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 @@ -22,3 +22,6 @@ 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,13 @@ "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, + "llvm-bitcode-strip expects a single output path specified with -o"); + } + Config.OutputFilename = InputArgs.getLastArgValue(BITCODE_STRIP_output); DC.CopyConfigs.push_back(std::move(ConfigMgr)); return std::move(DC);