diff --git a/llvm/test/tools/llvm-objcopy/MachO/Inputs/mh_preload.yaml b/llvm/test/tools/llvm-objcopy/MachO/Inputs/mh_preload.yaml new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-objcopy/MachO/Inputs/mh_preload.yaml @@ -0,0 +1,99 @@ +--- !mach-o +FileHeader: + magic: 0xFEEDFACF + cputype: 0x100000C + cpusubtype: 0x0 + filetype: 0x5 + ncmds: 4 + sizeofcmds: 568 + flags: 0x1 + reserved: 0x0 +LoadCommands: + - cmd: LC_SEGMENT_64 + cmdsize: 232 + segname: __TEXT + vmaddr: 15728640 + vmsize: 16384 + fileoff: 32768 + filesize: 16384 + maxprot: 5 + initprot: 5 + nsects: 2 + flags: 0 + Sections: + - sectname: __text + segname: __TEXT + addr: 0xF00000 + size: 4 + offset: 0x8000 + align: 2 + reloff: 0x0 + nreloc: 0 + flags: 0x80000400 + reserved1: 0x0 + reserved2: 0x0 + reserved3: 0x0 + content: C0035FD6 + - sectname: __foo + segname: __TEXT + addr: 0xF00004 + size: 8 + offset: 0x8004 + align: 0 + reloff: 0x0 + nreloc: 0 + flags: 0x0 + reserved1: 0x0 + reserved2: 0x0 + reserved3: 0x0 + content: FFFF0000FFFF0000 + - cmd: LC_SYMTAB + cmdsize: 24 + symoff: 49152 + nsyms: 1 + stroff: 49168 + strsize: 8 + - cmd: LC_UUID + cmdsize: 24 + uuid: 57ABEDF8-484D-35A6-85BD-32CA7C92BBE3 + - cmd: LC_UNIXTHREAD + cmdsize: 288 + PayloadBytes: [ 0x6, 0x0, 0x0, 0x0, 0x44, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0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0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xF0, 0x0, 0x0, 0x0, + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ] +LinkEditData: + NameList: + - n_strx: 2 + n_type: 0xF + n_sect: 1 + n_desc: 0 + n_value: 15728640 + StringTable: + - ' ' + - start +... diff --git a/llvm/test/tools/llvm-objcopy/MachO/mh-preload-unsupported.test b/llvm/test/tools/llvm-objcopy/MachO/mh-preload-unsupported.test new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-objcopy/MachO/mh-preload-unsupported.test @@ -0,0 +1,4 @@ +RUN: yaml2obj %p/Inputs/mh_preload.yaml > %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 @@ -392,6 +392,11 @@ if (!O) return createFileError(Config.InputFilename, O.takeError()); + if (O->get()->Header.FileType == MachO::HeaderFileType::MH_PRELOAD) + return createStringError(std::errc::invalid_argument, + "%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));