xref: /llvm-project/llvm/test/tools/llvm-objcopy/MachO/basic-executable-copy.test (revision c0da287c30c9f511ccb07fdd42c997be2caea9ec)
1## This test verifies that llvm-objcopy copies an executable properly. It
2## uses llvm-readobj instead of cmp because some parts of the object
3## (e.g., the string table) are not identical; the output file is correct but
4## some offsets differ from the input file.
5# RUN: yaml2obj %s -o %t
6# RUN: llvm-objcopy %t %t2
7# RUN: llvm-readobj --file-headers --sections %t2 | FileCheck %s
8
9--- !mach-o
10FileHeader:
11  magic:           0xFEEDFACF
12  cputype:         0x01000007
13  cpusubtype:      0x80000003
14  filetype:        0x00000002
15  ncmds:           15
16  sizeofcmds:      976
17  flags:           0x00200085
18  reserved:        0x00000000
19LoadCommands:
20  - cmd:             LC_SEGMENT_64
21    cmdsize:         72
22    segname:         __PAGEZERO
23    vmaddr:          0
24    vmsize:          4294967296
25    fileoff:         0
26    filesize:        0
27    maxprot:         0
28    initprot:        0
29    nsects:          0
30    flags:           0
31  - cmd:             LC_SEGMENT_64
32    cmdsize:         232
33    segname:         __TEXT
34    vmaddr:          4294967296
35    vmsize:          4096
36    fileoff:         0
37    filesize:        4096
38    maxprot:         7
39    initprot:        5
40    nsects:          2
41    flags:           0
42    Sections:
43      - sectname:        __text
44        segname:         __TEXT
45        addr:            0x0000000100000F70
46        size:            58
47        offset:          0x00000F70
48        align:           4
49        reloff:          0x00000000
50        nreloc:          0
51        flags:           0x80000400
52        reserved1:       0x00000000
53        reserved2:       0x00000000
54        reserved3:       0x00000000
55      - sectname:        __unwind_info
56        segname:         __TEXT
57        addr:            0x0000000100000FAC
58        size:            72
59        offset:          0x00000FAC
60        align:           2
61        reloff:          0x00000000
62        nreloc:          0
63        flags:           0x00000000
64        reserved1:       0x00000000
65        reserved2:       0x00000000
66        reserved3:       0x00000000
67  - cmd:             LC_SEGMENT_64
68    cmdsize:         232
69    segname:         __DATA
70    vmaddr:          4294971392
71    vmsize:          4096
72    fileoff:         4096
73    filesize:        4096
74    maxprot:         7
75    initprot:        3
76    nsects:          2
77    flags:           0
78    Sections:
79      - sectname:        __data
80        segname:         __DATA
81        addr:            0x0000000100001000
82        size:            4
83        offset:          0x00001000
84        align:           2
85        reloff:          0x00000000
86        nreloc:          0
87        flags:           0x00000000
88        reserved1:       0x00000000
89        reserved2:       0x00000000
90        reserved3:       0x00000000
91      - sectname:        __common
92        segname:         __DATA
93        addr:            0x0000000100001004
94        size:            4
95        offset:          0x00000000
96        align:           2
97        reloff:          0x00000000
98        nreloc:          0
99        flags:           0x00000001
100        reserved1:       0x00000000
101        reserved2:       0x00000000
102        reserved3:       0x00000000
103  - cmd:             LC_SEGMENT_64
104    cmdsize:         72
105    segname:         __LINKEDIT
106    vmaddr:          4294975488
107    vmsize:          4096
108    fileoff:         8192
109    filesize:        232
110    maxprot:         7
111    initprot:        1
112    nsects:          0
113    flags:           0
114  - cmd:             LC_DYLD_INFO_ONLY
115    cmdsize:         48
116    rebase_off:      0
117    rebase_size:     0
118    bind_off:        0
119    bind_size:       0
120    weak_bind_off:   0
121    weak_bind_size:  0
122    lazy_bind_off:   0
123    lazy_bind_size:  0
124    export_off:      8192
125    export_size:     72
126  - cmd:             LC_SYMTAB
127    cmdsize:         24
128    symoff:          8272
129    nsyms:           6
130    stroff:          8368
131    strsize:         56
132  - cmd:             LC_DYSYMTAB
133    cmdsize:         80
134    ilocalsym:       0
135    nlocalsym:       0
136    iextdefsym:      0
137    nextdefsym:      5
138    iundefsym:       5
139    nundefsym:       1
140    tocoff:          0
141    ntoc:            0
142    modtaboff:       0
143    nmodtab:         0
144    extrefsymoff:    0
145    nextrefsyms:     0
146    indirectsymoff:  0
147    nindirectsyms:   0
148    extreloff:       0
149    nextrel:         0
150    locreloff:       0
151    nlocrel:         0
152  - cmd:             LC_LOAD_DYLINKER
153    cmdsize:         32
154    name:            12
155    Content:         '/usr/lib/dyld'
156    ZeroPadBytes:    7
157  - cmd:             LC_UUID
158    cmdsize:         24
159    uuid:            B6EE4FB7-4E1E-3C7A-80D3-CFBD89DBC0FE
160  - cmd:             LC_BUILD_VERSION
161    cmdsize:         32
162    platform:        1
163    minos:           658944
164    sdk:             658944
165    ntools:          1
166    Tools:
167      - tool:            3
168        version:         29491968
169  - cmd:             LC_SOURCE_VERSION
170    cmdsize:         16
171    version:         0
172  - cmd:             LC_LINKER_OPTIMIZATION_HINT
173    cmdsize:         16
174    dataoff:         0
175    datasize:        0
176  - cmd:             LC_MAIN
177    cmdsize:         24
178    entryoff:        3984
179    stacksize:       0
180  - cmd:             LC_LOAD_DYLIB
181    cmdsize:         56
182    dylib:
183      name:            24
184      timestamp:       2
185      current_version: 82115073
186      compatibility_version: 65536
187    Content:         '/usr/lib/libSystem.B.dylib'
188    ZeroPadBytes:    6
189  - cmd:             LC_FUNCTION_STARTS
190    cmdsize:         16
191    dataoff:         8264
192    datasize:        8
193  - cmd:             LC_DATA_IN_CODE
194    cmdsize:         16
195    dataoff:         8272
196    datasize:        0
197LinkEditData:
198  ExportTrie:
199    TerminalSize:    0
200    NodeOffset:      0
201    Name:            ''
202    Flags:           0x0000000000000000
203    Address:         0x0000000000000000
204    Other:           0x0000000000000000
205    ImportName:      ''
206    Children:
207      - TerminalSize:    0
208        NodeOffset:      5
209        Name:            _
210        Flags:           0x0000000000000000
211        Address:         0x0000000000000000
212        Other:           0x0000000000000000
213        ImportName:      ''
214        Children:
215          - TerminalSize:    2
216            NodeOffset:      44
217            Name:            _mh_execute_header
218            Flags:           0x0000000000000000
219            Address:         0x0000000000000000
220            Other:           0x0000000000000000
221            ImportName:      ''
222          - TerminalSize:    3
223            NodeOffset:      48
224            Name:            foo
225            Flags:           0x0000000000000000
226            Address:         0x0000000000000F70
227            Other:           0x0000000000000000
228            ImportName:      ''
229          - TerminalSize:    3
230            NodeOffset:      53
231            Name:            main
232            Flags:           0x0000000000000000
233            Address:         0x0000000000000F90
234            Other:           0x0000000000000000
235            ImportName:      ''
236          - TerminalSize:    3
237            NodeOffset:      58
238            Name:            b
239            Flags:           0x0000000000000000
240            Address:         0x0000000000001000
241            Other:           0x0000000000000000
242            ImportName:      ''
243          - TerminalSize:    3
244            NodeOffset:      63
245            Name:            a
246            Flags:           0x0000000000000000
247            Address:         0x0000000000001004
248            Other:           0x0000000000000000
249            ImportName:      ''
250  NameList:
251    - n_strx:          2
252      n_type:          0x0F
253      n_sect:          1
254      n_desc:          16
255      n_value:         4294967296
256    - n_strx:          22
257      n_type:          0x0F
258      n_sect:          4
259      n_desc:          0
260      n_value:         4294971396
261    - n_strx:          25
262      n_type:          0x0F
263      n_sect:          3
264      n_desc:          0
265      n_value:         4294971392
266    - n_strx:          28
267      n_type:          0x0F
268      n_sect:          1
269      n_desc:          0
270      n_value:         4294971248
271    - n_strx:          33
272      n_type:          0x0F
273      n_sect:          1
274      n_desc:          0
275      n_value:         4294971280
276    - n_strx:          39
277      n_type:          0x01
278      n_sect:          0
279      n_desc:          256
280      n_value:         0
281  StringTable:
282    - ' '
283    - __mh_execute_header
284    - _a
285    - _b
286    - _foo
287    - _main
288    - dyld_stub_binder
289...
290
291# CHECK: FileType: Executable (0x2)
292# CHECK: Name: __text
293# CHECK: Name: __unwind_info
294# CHECK: Name: __data
295# CHECK: Name: __common
296