diff options
author | Xing GUO <higuoxing@gmail.com> | 2020-05-27 16:59:45 +0800 |
---|---|---|
committer | Xing GUO <higuoxing@gmail.com> | 2020-05-28 09:54:46 +0800 |
commit | 3c3a6e26e7c39096b3df746faeaa743197657a8e (patch) | |
tree | 0ee348b770252652b6e67f3a5c1276ddff3533ed /llvm/test/ObjectYAML/MachO | |
parent | 87bea912c27caaa71ac9bc3d172995994b57e639 (diff) | |
download | llvm-3c3a6e26e7c39096b3df746faeaa743197657a8e.zip llvm-3c3a6e26e7c39096b3df746faeaa743197657a8e.tar.gz llvm-3c3a6e26e7c39096b3df746faeaa743197657a8e.tar.bz2 |
[ObjectYAML][MachO] Add error handling in MachOEmitter.
Currently, `yaml2macho` doesn't support error handling. This patch helps improve it.
Differential Revision: https://reviews.llvm.org/D80535
Diffstat (limited to 'llvm/test/ObjectYAML/MachO')
-rw-r--r-- | llvm/test/ObjectYAML/MachO/fat_macho_i386_x86_64.yaml | 43 | ||||
-rw-r--r-- | llvm/test/ObjectYAML/MachO/sections.yaml | 61 |
2 files changed, 102 insertions, 2 deletions
diff --git a/llvm/test/ObjectYAML/MachO/fat_macho_i386_x86_64.yaml b/llvm/test/ObjectYAML/MachO/fat_macho_i386_x86_64.yaml index 55a9df3..b9b2f2d 100644 --- a/llvm/test/ObjectYAML/MachO/fat_macho_i386_x86_64.yaml +++ b/llvm/test/ObjectYAML/MachO/fat_macho_i386_x86_64.yaml @@ -1,4 +1,9 @@ -# RUN: yaml2obj %s | obj2yaml | FileCheck %s +## This file contains test cases for generating Fat Mach-O binaries. + +## a) Test that yaml2obj emits Fat Mach-O binary and obj2yaml converts it +## back to YAML file. + +# RUN: yaml2obj --docnum=1 %s | obj2yaml | FileCheck %s --- !fat-mach-o FatHeader: @@ -72,3 +77,39 @@ Slices: #CHECK: flags: 0x00218085 #CHECK: reserved: 0x00000000 #CHECK: ... + +## b) Test that yaml2obj emits an error message if the number of 'FatArchs' is less than +## the number of 'Slices'. + +# RUN: not yaml2obj --docnum=2 %s -o %t2.fat-macho 2>&1 | FileCheck %s --check-prefix=ERROR + +# ERROR: yaml2obj: error: cannot write 'Slices' if not described in 'FatArches' + +--- !fat-mach-o +FatHeader: + magic: 0xCAFEBABE + nfat_arch: 2 +FatArchs: + ## 2 FatArchs are expected. + - cputype: 0x00000007 + cpusubtype: 0x00000003 + offset: 0x0000000000001000 + size: 0 + align: 0 +Slices: + - FileHeader: + magic: 0xFEEDFACE + cputype: 0x00000007 + cpusubtype: 0x00000003 + filetype: 0x00000002 + ncmds: 0 + sizeofcmds: 0 + flags: 0x00000000 + - FileHeader: + magic: 0xFEEDFACE + cputype: 0x00000007 + cpusubtype: 0x00000003 + filetype: 0x00000002 + ncmds: 0 + sizeofcmds: 0 + flags: 0x00000000 diff --git a/llvm/test/ObjectYAML/MachO/sections.yaml b/llvm/test/ObjectYAML/MachO/sections.yaml index 5da789d..f8c5370 100644 --- a/llvm/test/ObjectYAML/MachO/sections.yaml +++ b/llvm/test/ObjectYAML/MachO/sections.yaml @@ -1,4 +1,8 @@ -# RUN: yaml2obj %s | obj2yaml | FileCheck %s +## This file contains test cases for generating sections in Mach-O object files. + +## a) Test that yaml2obj emits sections and obj2yaml converts them back. + +# RUN: yaml2obj --docnum=1 %s | obj2yaml | FileCheck %s --- !mach-o FileHeader: @@ -281,3 +285,58 @@ LoadCommands: #CHECK: segname: __DATA #CHECK: - sectname: __la_symbol_ptr #CHECK: segname: __DATA + +## b) Test that yaml2obj emits an error message if we specify an offset that +## makes the current section and the previous one overlap. + +# RUN: not yaml2obj --docnum=2 %s -o %t2.macho 2>&1 | FileCheck %s --check-prefix=OVERLAP + +# OVERLAP: yaml2obj: error: wrote too much data somewhere, section offsets don't line up + +--- !mach-o +FileHeader: + magic: 0xFEEDFACF + cputype: 0x01000007 + cpusubtype: 0x80000003 + filetype: 0x00000002 + ncmds: 1 + sizeofcmds: 1024 + flags: 0x00000000 + reserved: 0x00000000 +LoadCommands: + - cmd: LC_SEGMENT_64 + cmdsize: 0xff + segname: __SEC + vmaddr: 0 + vmsize: 0 + fileoff: 0 + filesize: 0 + maxprot: 0 + initprot: 0 + nsects: 2 + flags: 0 + Sections: + - sectname: __sec1 + segname: __SEC + addr: 0x0000000000000000 + size: 2 + offset: 0x00000000 + align: 0 + reloff: 0x00000000 + nreloc: 0 + flags: 0x00000000 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 + - sectname: __sec2 + segname: __SEC + addr: 0x0000000000000000 + size: 2 + offset: 0x00000001 ## Specify an offset that makes __sec1 and __sec2 overlap. + align: 1 + reloff: 0x00000000 + nreloc: 0 + flags: 0x00000000 + reserved1: 0x00000000 + reserved2: 0x00000000 + reserved3: 0x00000000 |