diff --git a/llvm/test/tools/llvm-objcopy/MachO/mh-preload-unsupported.yaml b/llvm/test/tools/llvm-objcopy/MachO/mh-preload-unsupported.yaml new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-objcopy/MachO/mh-preload-unsupported.yaml @@ -0,0 +1,16 @@ +--- !mach-o +FileHeader: + magic: 0xFEEDFACF + cputype: 0x100000C + cpusubtype: 0x0 + filetype: 0x5 + ncmds: 0 + sizeofcmds: 0 + flags: 0x1 + reserved: 0x0 +... + +# RUN: yaml2obj %s > %t +# RUN: not llvm-objcopy %t 2>&1 | FileCheck %s -DFILE=%t +# +# CHECK: error: [[FILE]]: MH_PRELOAD files are not supported diff --git a/llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp b/llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp --- a/llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp +++ b/llvm/tools/llvm-objcopy/MachO/MachOObjcopy.cpp @@ -389,6 +389,11 @@ if (!O) return createFileError(Config.InputFilename, O.takeError()); + if (O->get()->Header.FileType == MachO::HeaderFileType::MH_PRELOAD) + return createStringError(std::errc::not_supported, + "%s: MH_PRELOAD files are not supported", + Config.InputFilename.str().c_str()); + if (Error E = handleArgs(Config, MachOConfig, **O)) return createFileError(Config.InputFilename, std::move(E));