1# RUN: yaml2obj %s -o %t 2 3## Verify that the input file is valid and contains the expected load command. 4# RUN: llvm-objdump --private-headers %t | FileCheck %s --check-prefix=CHECK-ORIGINAL 5 6# CHECK-ORIGINAL: cmd LC_CODE_SIGNATURE 7# CHECK-ORIGINAL-NEXT: cmdsize 16 8# CHECK-ORIGINAL-NEXT: dataoff 16544 9# CHECK-ORIGINAL-NEXT: datasize 280 10 11# RUN: llvm-objcopy %t %t.copy 12# RUN: obj2yaml %t > %t.yaml 13# RUN: obj2yaml %t.copy > %t.copy.yaml 14 15## Verify that the copy still includes the load command 16# RUN: FileCheck %s --check-prefix=CHECK-COPY < %t.copy.yaml 17# CHECK-COPY: - cmd: LC_CODE_SIGNATURE 18# CHECK-COPY-NEXT: cmdsize: 16 19# CHECK-COPY-NEXT: dataoff: 16544 20# CHECK-COPY-NEXT: datasize: 304 21 22## Remove information changed by regeneration of load command: 23## - __LINKEDIT segment filesize may change (4 lines) 24## - LC_CODE_SIGNATURE command dataoff and datasize may change (3 lines) 25## - __LINKEDIT data locations may change 26## NOTE: The {N;N;N;N;d} means delete the next four lines for BSD and GNU sed. 27## The ,+4d is a GNU extension which seems not to work in macOS 10.15 28 29# RUN: sed -e '/__LINKEDIT/{N;N;N;N;d;}' \ 30# RUN: -e '/LC_CODE_SIGNATURE/{N;N;N;d;}' \ 31# RUN: -e '/n_strx/d' \ 32# RUN: -e '/dyld_stub_binder/d' %t.yaml > %t.clean.yaml 33 34# RUN: sed -e '/__LINKEDIT/{N;N;N;N;d;}' \ 35# RUN: -e '/LC_CODE_SIGNATURE/{N;N;N;d;}' \ 36# RUN: -e '/n_strx/d' \ 37# RUN: -e '/dyld_stub_binder/d' %t.copy.yaml > %t.copy.clean.yaml 38 39## Verify the remainder of the object file remains unchanged 40# RUN: diff %t.clean.yaml %t.copy.clean.yaml 41 42## Verify the new signature is valid 43# RUN: %python %p/Inputs/code-signature-check.py %t.copy 16544 304 0 16544 44 45--- !mach-o 46FileHeader: 47 magic: 0xFEEDFACF 48 cputype: 0x1000007 49 cpusubtype: 0x3 50 filetype: 0x2 51 ncmds: 15 52 sizeofcmds: 760 53 flags: 0x200085 54 reserved: 0x0 55LoadCommands: 56 - cmd: LC_SEGMENT_64 57 cmdsize: 72 58 segname: __PAGEZERO 59 vmaddr: 0 60 vmsize: 4294967296 61 fileoff: 0 62 filesize: 0 63 maxprot: 0 64 initprot: 0 65 nsects: 0 66 flags: 0 67 - cmd: LC_SEGMENT_64 68 cmdsize: 232 69 segname: __TEXT 70 vmaddr: 4294967296 71 vmsize: 16384 72 fileoff: 0 73 filesize: 16384 74 maxprot: 5 75 initprot: 5 76 nsects: 2 77 flags: 0 78 Sections: 79 - sectname: __text 80 segname: __TEXT 81 addr: 0x100003FA0 82 size: 15 83 offset: 0x3FA0 84 align: 4 85 reloff: 0x0 86 nreloc: 0 87 flags: 0x80000400 88 reserved1: 0x0 89 reserved2: 0x0 90 reserved3: 0x0 91 content: 554889E531C0C745FC000000005DC3 92 - sectname: __unwind_info 93 segname: __TEXT 94 addr: 0x100003FB0 95 size: 72 96 offset: 0x3FB0 97 align: 2 98 reloff: 0x0 99 nreloc: 0 100 flags: 0x0 101 reserved1: 0x0 102 reserved2: 0x0 103 reserved3: 0x0 104 content: 010000001C000000000000001C000000000000001C00000002000000A03F00003400000034000000B03F00000000000034000000030000000C000100100001000000000000000001 105 - cmd: LC_SEGMENT_64 106 cmdsize: 72 107 segname: __LINKEDIT 108 vmaddr: 4294983680 109 vmsize: 16384 110 fileoff: 16384 111 filesize: 440 112 maxprot: 1 113 initprot: 1 114 nsects: 0 115 flags: 0 116 - cmd: LC_DYLD_INFO_ONLY 117 cmdsize: 48 118 rebase_off: 0 119 rebase_size: 0 120 bind_off: 0 121 bind_size: 0 122 weak_bind_off: 0 123 weak_bind_size: 0 124 lazy_bind_off: 0 125 lazy_bind_size: 0 126 export_off: 16384 127 export_size: 48 128 - cmd: LC_SYMTAB 129 cmdsize: 24 130 symoff: 16440 131 nsyms: 3 132 stroff: 16488 133 strsize: 48 134 - cmd: LC_DYSYMTAB 135 cmdsize: 80 136 ilocalsym: 0 137 nlocalsym: 0 138 iextdefsym: 0 139 nextdefsym: 2 140 iundefsym: 2 141 nundefsym: 1 142 tocoff: 0 143 ntoc: 0 144 modtaboff: 0 145 nmodtab: 0 146 extrefsymoff: 0 147 nextrefsyms: 0 148 indirectsymoff: 0 149 nindirectsyms: 0 150 extreloff: 0 151 nextrel: 0 152 locreloff: 0 153 nlocrel: 0 154 - cmd: LC_LOAD_DYLINKER 155 cmdsize: 32 156 name: 12 157 Content: '/usr/lib/dyld' 158 ZeroPadBytes: 7 159 - cmd: LC_UUID 160 cmdsize: 24 161 uuid: 42759668-1CBA-3094-8E2D-F01E1A66E815 162 - cmd: LC_BUILD_VERSION 163 cmdsize: 32 164 platform: 1 165 minos: 720896 166 sdk: 721664 167 ntools: 1 168 Tools: 169 - tool: 3 170 version: 42600704 171 - cmd: LC_SOURCE_VERSION 172 cmdsize: 16 173 version: 0 174 - cmd: LC_MAIN 175 cmdsize: 24 176 entryoff: 16288 177 stacksize: 0 178 - cmd: LC_LOAD_DYLIB 179 cmdsize: 56 180 dylib: 181 name: 24 182 timestamp: 2 183 current_version: 84698117 184 compatibility_version: 65536 185 Content: '/usr/lib/libSystem.B.dylib' 186 ZeroPadBytes: 6 187 - cmd: LC_FUNCTION_STARTS 188 cmdsize: 16 189 dataoff: 16432 190 datasize: 8 191 - cmd: LC_DATA_IN_CODE 192 cmdsize: 16 193 dataoff: 16440 194 datasize: 0 195 - cmd: LC_CODE_SIGNATURE 196 cmdsize: 16 197 dataoff: 16544 198 datasize: 280 199LinkEditData: 200 ExportTrie: 201 TerminalSize: 0 202 NodeOffset: 0 203 Name: '' 204 Flags: 0x0 205 Address: 0x0 206 Other: 0x0 207 ImportName: '' 208 Children: 209 - TerminalSize: 0 210 NodeOffset: 5 211 Name: _ 212 Flags: 0x0 213 Address: 0x0 214 Other: 0x0 215 ImportName: '' 216 Children: 217 - TerminalSize: 2 218 NodeOffset: 33 219 Name: _mh_execute_header 220 Flags: 0x0 221 Address: 0x0 222 Other: 0x0 223 ImportName: '' 224 - TerminalSize: 3 225 NodeOffset: 37 226 Name: main 227 Flags: 0x0 228 Address: 0x3FA0 229 Other: 0x0 230 ImportName: '' 231 NameList: 232 - n_strx: 2 233 n_type: 0xF 234 n_sect: 1 235 n_desc: 16 236 n_value: 4294967296 237 - n_strx: 22 238 n_type: 0xF 239 n_sect: 1 240 n_desc: 0 241 n_value: 4294983584 242 - n_strx: 28 243 n_type: 0x1 244 n_sect: 0 245 n_desc: 256 246 n_value: 0 247 StringTable: 248 - ' ' 249 - __mh_execute_header 250 - _main 251 - dyld_stub_binder 252 - '' 253 - '' 254 - '' 255... 256