xref: /llvm-project/llvm/test/tools/llvm-objcopy/MachO/segments-vmsize.test (revision c0da287c30c9f511ccb07fdd42c997be2caea9ec)
1# RUN: yaml2obj %s -o %t
2
3## The binary used in this test can be built (on OSX) as follows:
4## main.c:
5##   __attribute__((used)) static int a[1021];
6##   __attribute__((used)) static char b = 1;
7##   int main() {
8##     return 0;
9##   }
10## build command:
11##   clang -fno-exceptions -fno-unwind-tables main.c -o main.exe
12## Note, that the variable "b" (whose size is 1) is placed into __DATA,__data section,
13## the array "a" (whose size is 4 * 1021 = 4084) is placed into __DATA,__bss and
14## __DATA,__bss is 16-byte aligned. In this case the total vmsize narrowly crosses
15## the border of one page (4096) and the final value should be equal to 8192.
16
17# RUN: llvm-objcopy %t %t.copy
18# RUN: cmp %t %t.copy
19
20## This additionally verifies that the binary created by llvm-objcopy/yaml2obj is valid.
21# RUN: llvm-readobj --sections %t.copy
22
23--- !mach-o
24FileHeader:
25  magic:           0xFEEDFACF
26  cputype:         0x01000007
27  cpusubtype:      0x80000003
28  filetype:        0x00000002
29  ncmds:           15
30  sizeofcmds:      976
31  flags:           0x00200085
32  reserved:        0x00000000
33LoadCommands:
34  - cmd:             LC_SEGMENT_64
35    cmdsize:         72
36    segname:         __PAGEZERO
37    vmaddr:          0
38    vmsize:          4294967296
39    fileoff:         0
40    filesize:        0
41    maxprot:         0
42    initprot:        0
43    nsects:          0
44    flags:           0
45  - cmd:             LC_SEGMENT_64
46    cmdsize:         232
47    segname:         __TEXT
48    vmaddr:          4294967296
49    vmsize:          4096
50    fileoff:         0
51    filesize:        4096
52    maxprot:         5
53    initprot:        5
54    nsects:          2
55    flags:           0
56    Sections:
57      - sectname:        __text
58        segname:         __TEXT
59        addr:            0x0000000100000FA0
60        size:            15
61        offset:          0x00000FA0
62        align:           4
63        reloff:          0x00000000
64        nreloc:          0
65        flags:           0x80000400
66        reserved1:       0x00000000
67        reserved2:       0x00000000
68        reserved3:       0x00000000
69        content:         554889E531C0C745FC000000005DC3
70      - sectname:        __unwind_info
71        segname:         __TEXT
72        addr:            0x0000000100000FB0
73        size:            72
74        offset:          0x00000FB0
75        align:           2
76        reloff:          0x00000000
77        nreloc:          0
78        flags:           0x00000000
79        reserved1:       0x00000000
80        reserved2:       0x00000000
81        reserved3:       0x00000000
82        content:         010000001C000000000000001C000000000000001C00000002000000A00F00003400000034000000B00F00000000000034000000030000000C000100100001000000000000000000
83  - cmd:             LC_SEGMENT_64
84    cmdsize:         232
85    segname:         __DATA
86    vmaddr:          4294971392
87    vmsize:          8192
88    fileoff:         4096
89    filesize:        4096
90    maxprot:         3
91    initprot:        3
92    nsects:          2
93    flags:           0
94    Sections:
95      - sectname:        __data
96        segname:         __DATA
97        addr:            0x0000000100001000
98        size:            1
99        offset:          0x00001000
100        align:           0
101        reloff:          0x00000000
102        nreloc:          0
103        flags:           0x00000000
104        reserved1:       0x00000000
105        reserved2:       0x00000000
106        reserved3:       0x00000000
107        content:         '01'
108      - sectname:        __bss
109        segname:         __DATA
110        addr:            0x0000000100001010
111        size:            4084
112        offset:          0x00000000
113        align:           4
114        reloff:          0x00000000
115        nreloc:          0
116        flags:           0x00000001
117        reserved1:       0x00000000
118        reserved2:       0x00000000
119        reserved3:       0x00000000
120  - cmd:             LC_SEGMENT_64
121    cmdsize:         72
122    segname:         __LINKEDIT
123    vmaddr:          4294979584
124    vmsize:          4096
125    fileoff:         8192
126    filesize:        128
127    maxprot:         1
128    initprot:        1
129    nsects:          0
130    flags:           0
131  - cmd:             LC_DYLD_INFO_ONLY
132    cmdsize:         48
133    rebase_off:      0
134    rebase_size:     0
135    bind_off:        0
136    bind_size:       0
137    weak_bind_off:   0
138    weak_bind_size:  0
139    lazy_bind_off:   0
140    lazy_bind_size:  0
141    export_off:      8192
142    export_size:     48
143  - cmd:             LC_SYMTAB
144    cmdsize:         24
145    symoff:          8248
146    nsyms:           2
147    stroff:          8280
148    strsize:         40
149  - cmd:             LC_DYSYMTAB
150    cmdsize:         80
151    ilocalsym:       0
152    nlocalsym:       0
153    iextdefsym:      0
154    nextdefsym:      1
155    iundefsym:       1
156    nundefsym:       1
157    tocoff:          0
158    ntoc:            0
159    modtaboff:       0
160    nmodtab:         0
161    extrefsymoff:    0
162    nextrefsyms:     0
163    indirectsymoff:  0
164    nindirectsyms:   0
165    extreloff:       0
166    nextrel:         0
167    locreloff:       0
168    nlocrel:         0
169  - cmd:             LC_LOAD_DYLINKER
170    cmdsize:         32
171    name:            12
172    Content:         '/usr/lib/dyld'
173    ZeroPadBytes:    7
174  - cmd:             LC_UUID
175    cmdsize:         24
176    uuid:            11362E8D-D70B-33B3-96F8-A70ADF2583C4
177  - cmd:             LC_BUILD_VERSION
178    cmdsize:         32
179    platform:        1
180    minos:           658944
181    sdk:             658944
182    ntools:          1
183    Tools:
184      - tool:            3
185        version:         34734080
186  - cmd:             LC_SOURCE_VERSION
187    cmdsize:         16
188    version:         0
189  - cmd:             LC_MAIN
190    cmdsize:         24
191    entryoff:        4000
192    stacksize:       0
193  - cmd:             LC_LOAD_DYLIB
194    cmdsize:         56
195    dylib:
196      name:            24
197      timestamp:       2
198      current_version: 82115073
199      compatibility_version: 65536
200    Content:         '/usr/lib/libSystem.B.dylib'
201    ZeroPadBytes:    6
202  - cmd:             LC_FUNCTION_STARTS
203    cmdsize:         16
204    dataoff:         8240
205    datasize:        8
206  - cmd:             LC_DATA_IN_CODE
207    cmdsize:         16
208    dataoff:         8248
209    datasize:        0
210LinkEditData:
211  ExportTrie:
212    TerminalSize:    0
213    NodeOffset:      0
214    Name:            ''
215    Flags:           0x0000000000000000
216    Address:         0x0000000000000000
217    Other:           0x0000000000000000
218    ImportName:      ''
219    Children:
220      - TerminalSize:    0
221        NodeOffset:      5
222        Name:            _
223        Flags:           0x0000000000000000
224        Address:         0x0000000000000000
225        Other:           0x0000000000000000
226        ImportName:      ''
227        Children:
228          - TerminalSize:    2
229            NodeOffset:      33
230            Name:            _mh_execute_header
231            Flags:           0x0000000000000000
232            Address:         0x0000000000000000
233            Other:           0x0000000000000000
234            ImportName:      ''
235          - TerminalSize:    3
236            NodeOffset:      37
237            Name:            main
238            Flags:           0x0000000000000000
239            Address:         0x0000000000000FA0
240            Other:           0x0000000000000000
241            ImportName:      ''
242  NameList:
243    - n_strx:          19
244      n_type:          0x0F
245      n_sect:          1
246      n_desc:          16
247      n_value:         4294967296
248    - n_strx:          2
249      n_type:          0x01
250      n_sect:          0
251      n_desc:          256
252      n_value:         0
253  StringTable:
254    - ' '
255    - dyld_stub_binder
256    - __mh_execute_header
257    - ''
258...
259