xref: /llvm-project/llvm/test/tools/llvm-objcopy/MachO/dump-section.test (revision d72a8a4dd5baad1fd90f4e13fdb6b585afea4657)
1## Show that llvm-objcopy extracts section contents into files specified by
2## --dump-section.
3
4# RUN: yaml2obj %s -o %t
5
6## Extract section contents into files.
7# RUN: llvm-objcopy --dump-section __TEXT,__text=%t.dump.text \
8# RUN:   --dump-section __DATA,__data=%t.dump.data %t
9# RUN: od -t x1 %t.dump.text | FileCheck %s --check-prefix=TEXT-CONTENT
10# RUN: wc -c %t.dump.text | FileCheck %s --check-prefix=TEXT-SIZE
11# RUN: od -t x1 %t.dump.data | FileCheck %s --check-prefix=DATA-CONTENT
12# RUN: wc -c %t.dump.data | FileCheck %s --check-prefix=DATA-SIZE
13
14# TEXT-CONTENT: 0000000 aa bb cc dd
15# TEXT-SIZE: 4
16# DATA-CONTENT: 0000000 ee ff ee ff
17# DATA-SIZE: 4
18
19## Error case: A non-existent section name.
20# RUN: not llvm-objcopy --dump-section __TEXT,__foo=%t.no-such-section %t 2>&1 \
21# RUN:   | FileCheck %s -DINPUT=%t --check-prefix=NO-SUCH-SECTION
22# NO-SUCH-SECTION: error: '[[INPUT]]': section '__TEXT,__foo' not found
23
24--- !mach-o
25FileHeader:
26  magic:           0xFEEDFACF
27  cputype:         0x01000007
28  cpusubtype:      0x00000003
29  filetype:        0x00000001
30  ncmds:           1
31  sizeofcmds:      312
32  flags:           0x00002000
33  reserved:        0x00000000
34LoadCommands:
35  - cmd:             LC_SEGMENT_64
36    cmdsize:         312
37    segname:         ''
38    vmaddr:          0
39    vmsize:          12
40    fileoff:         344
41    filesize:        12
42    maxprot:         7
43    initprot:        7
44    nsects:          3
45    flags:           0
46    Sections:
47      - sectname:        __text
48        segname:         __TEXT
49        addr:            0x0000000000000000
50        content:         'AABBCCDD'
51        size:            4
52        offset:          344
53        align:           0
54        reloff:          0x00000000
55        nreloc:          0
56        flags:           0x80000400
57        reserved1:       0x00000000
58        reserved2:       0x00000000
59      - sectname:        __data
60        segname:         __DATA
61        addr:            0x0000000000000004
62        content:         'EEFFEEFF'
63        size:            4
64        offset:          348
65        align:           0
66        reloff:          0x00000000
67        nreloc:          0
68        flags:           0x00000000
69        reserved1:       0x00000000
70        reserved2:       0x00000000
71      - sectname:        __const
72        segname:         __TEXT
73        addr:            0x0000000000000008
74        content:         'EEFFEEFF'
75        size:            4
76        offset:          352
77        align:           0
78        reloff:          0x00000000
79        nreloc:          0
80        flags:           0x00000000
81        reserved1:       0x00000000
82        reserved2:       0x00000000
83