|
| 1 | +# RUN: rm -rf %t && mkdir %t |
| 2 | +# RUN: yaml2obj %s -o %t/original |
| 3 | +# RUN: llvm-strip --strip-all %t/original -o %t/stripped |
| 4 | +# RUN: llvm-readobj --macho-segment %t/stripped | FileCheck %s |
| 5 | + |
| 6 | +# CHECK-LABEL: Name: __PAGEZERO |
| 7 | +# CHECK: fileoff: 16384 |
| 8 | + |
| 9 | +# CHECK-LABEL: Name: __TEXT |
| 10 | +# CHECK: fileoff: 16384 |
| 11 | + |
| 12 | +# The YAML below is the following code |
| 13 | +# int main(int argc, char **argv) { return 0; } |
| 14 | +# Compiled on macOS against the macOS SDK and passing `-Wl,-encryptable` |
| 15 | +# Contents are removed, since they are not important for the test. We need a |
| 16 | +# small text segment (smaller than a page). |
| 17 | +--- !mach-o |
| 18 | +FileHeader: |
| 19 | + magic: 0xFEEDFACF |
| 20 | + cputype: 0x100000C |
| 21 | + cpusubtype: 0x0 |
| 22 | + filetype: 0x2 |
| 23 | + ncmds: 15 |
| 24 | + sizeofcmds: 696 |
| 25 | + flags: 0x200085 |
| 26 | + reserved: 0x0 |
| 27 | +LoadCommands: |
| 28 | + - cmd: LC_SEGMENT_64 |
| 29 | + cmdsize: 72 |
| 30 | + segname: __PAGEZERO |
| 31 | + vmaddr: 0 |
| 32 | + vmsize: 4294967296 |
| 33 | + fileoff: 0 |
| 34 | + filesize: 0 |
| 35 | + maxprot: 0 |
| 36 | + initprot: 0 |
| 37 | + nsects: 0 |
| 38 | + flags: 0 |
| 39 | + - cmd: LC_SEGMENT_64 |
| 40 | + cmdsize: 232 |
| 41 | + segname: __TEXT |
| 42 | + vmaddr: 4294967296 |
| 43 | + vmsize: 32768 |
| 44 | + fileoff: 0 |
| 45 | + filesize: 32768 |
| 46 | + maxprot: 5 |
| 47 | + initprot: 5 |
| 48 | + nsects: 2 |
| 49 | + flags: 0 |
| 50 | + Sections: |
| 51 | + - sectname: __text |
| 52 | + segname: __TEXT |
| 53 | + addr: 0x100004000 |
| 54 | + size: 32 |
| 55 | + offset: 0x4000 |
| 56 | + align: 2 |
| 57 | + reloff: 0x0 |
| 58 | + nreloc: 0 |
| 59 | + flags: 0x80000400 |
| 60 | + reserved1: 0x0 |
| 61 | + reserved2: 0x0 |
| 62 | + reserved3: 0x0 |
| 63 | + - sectname: __unwind_info |
| 64 | + segname: __TEXT |
| 65 | + addr: 0x100004020 |
| 66 | + size: 4152 |
| 67 | + offset: 0x4020 |
| 68 | + align: 2 |
| 69 | + reloff: 0x0 |
| 70 | + nreloc: 0 |
| 71 | + flags: 0x0 |
| 72 | + reserved1: 0x0 |
| 73 | + reserved2: 0x0 |
| 74 | + reserved3: 0x0 |
| 75 | + - cmd: LC_SEGMENT_64 |
| 76 | + cmdsize: 72 |
| 77 | + segname: __LINKEDIT |
| 78 | + vmaddr: 4295000064 |
| 79 | + vmsize: 592 |
| 80 | + fileoff: 32768 |
| 81 | + filesize: 592 |
| 82 | + maxprot: 1 |
| 83 | + initprot: 1 |
| 84 | + nsects: 0 |
| 85 | + flags: 0 |
| 86 | + - cmd: LC_DYLD_CHAINED_FIXUPS |
| 87 | + cmdsize: 16 |
| 88 | + dataoff: 32768 |
| 89 | + datasize: 48 |
| 90 | + - cmd: LC_DYLD_EXPORTS_TRIE |
| 91 | + cmdsize: 16 |
| 92 | + dataoff: 32816 |
| 93 | + datasize: 48 |
| 94 | + - cmd: LC_SYMTAB |
| 95 | + cmdsize: 24 |
| 96 | + symoff: 32872 |
| 97 | + nsyms: 2 |
| 98 | + stroff: 32904 |
| 99 | + strsize: 32 |
| 100 | + - cmd: LC_DYSYMTAB |
| 101 | + cmdsize: 80 |
| 102 | + ilocalsym: 0 |
| 103 | + nlocalsym: 0 |
| 104 | + iextdefsym: 0 |
| 105 | + nextdefsym: 2 |
| 106 | + iundefsym: 2 |
| 107 | + nundefsym: 0 |
| 108 | + tocoff: 0 |
| 109 | + ntoc: 0 |
| 110 | + modtaboff: 0 |
| 111 | + nmodtab: 0 |
| 112 | + extrefsymoff: 0 |
| 113 | + nextrefsyms: 0 |
| 114 | + indirectsymoff: 0 |
| 115 | + nindirectsyms: 0 |
| 116 | + extreloff: 0 |
| 117 | + nextrel: 0 |
| 118 | + locreloff: 0 |
| 119 | + nlocrel: 0 |
| 120 | + - cmd: LC_ENCRYPTION_INFO_64 |
| 121 | + cmdsize: 24 |
| 122 | + cryptoff: 16384 |
| 123 | + cryptsize: 16384 |
| 124 | + cryptid: 0 |
| 125 | + pad: 0 |
| 126 | + - cmd: LC_LOAD_DYLINKER |
| 127 | + cmdsize: 32 |
| 128 | + name: 12 |
| 129 | + Content: '/usr/lib/dyld' |
| 130 | + ZeroPadBytes: 7 |
| 131 | + - cmd: LC_UUID |
| 132 | + cmdsize: 24 |
| 133 | + uuid: 4C4C4447-5555-3144-A18A-01E9EB7E7D92 |
| 134 | + - cmd: LC_BUILD_VERSION |
| 135 | + cmdsize: 32 |
| 136 | + platform: 1 |
| 137 | + minos: 983040 |
| 138 | + sdk: 983552 |
| 139 | + ntools: 1 |
| 140 | + Tools: |
| 141 | + - tool: 4 |
| 142 | + version: 1310720 |
| 143 | + - cmd: LC_MAIN |
| 144 | + cmdsize: 24 |
| 145 | + entryoff: 16384 |
| 146 | + stacksize: 0 |
| 147 | + - cmd: LC_FUNCTION_STARTS |
| 148 | + cmdsize: 16 |
| 149 | + dataoff: 32864 |
| 150 | + datasize: 8 |
| 151 | + - cmd: LC_DATA_IN_CODE |
| 152 | + cmdsize: 16 |
| 153 | + dataoff: 32872 |
| 154 | + datasize: 0 |
| 155 | + - cmd: LC_CODE_SIGNATURE |
| 156 | + cmdsize: 16 |
| 157 | + dataoff: 32944 |
| 158 | + datasize: 416 |
| 159 | +LinkEditData: |
| 160 | + ExportTrie: |
| 161 | + TerminalSize: 0 |
| 162 | + NodeOffset: 0 |
| 163 | + Name: '' |
| 164 | + Flags: 0x0 |
| 165 | + Address: 0x0 |
| 166 | + Other: 0x0 |
| 167 | + ImportName: '' |
| 168 | + Children: |
| 169 | + - TerminalSize: 0 |
| 170 | + NodeOffset: 5 |
| 171 | + Name: _ |
| 172 | + Flags: 0x0 |
| 173 | + Address: 0x0 |
| 174 | + Other: 0x0 |
| 175 | + ImportName: '' |
| 176 | + Children: |
| 177 | + - TerminalSize: 4 |
| 178 | + NodeOffset: 33 |
| 179 | + Name: main |
| 180 | + Flags: 0x0 |
| 181 | + Address: 0x4000 |
| 182 | + Other: 0x0 |
| 183 | + ImportName: '' |
| 184 | + - TerminalSize: 2 |
| 185 | + NodeOffset: 39 |
| 186 | + Name: _mh_execute_header |
| 187 | + Flags: 0x0 |
| 188 | + Address: 0x0 |
| 189 | + Other: 0x0 |
| 190 | + ImportName: '' |
| 191 | + NameList: |
| 192 | + - n_strx: 2 |
| 193 | + n_type: 0xF |
| 194 | + n_sect: 1 |
| 195 | + n_desc: 0 |
| 196 | + n_value: 4294983680 |
| 197 | + - n_strx: 8 |
| 198 | + n_type: 0xF |
| 199 | + n_sect: 1 |
| 200 | + n_desc: 16 |
| 201 | + n_value: 4294967296 |
| 202 | + StringTable: |
| 203 | + - ' ' |
| 204 | + - _main |
| 205 | + - __mh_execute_header |
| 206 | + - '' |
| 207 | + - '' |
| 208 | + - '' |
| 209 | + - '' |
| 210 | + FunctionStarts: [ 0x4000 ] |
| 211 | + ChainedFixups: [ 0x0, 0x0, 0x0, 0x0, 0x20, 0x0, 0x0, 0x0, 0x30, 0x0, |
| 212 | + 0x0, 0x0, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
| 213 | + 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
| 214 | + 0x0, 0x0, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, |
| 215 | + 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ] |
| 216 | +... |
| 217 | + |
0 commit comments