xref: /llvm-project/llvm/test/tools/llvm-objcopy/MachO/add-section-32.test (revision e60a760b7da970b6eeabc26faa9e065ec7cec1a8)
1## Show that llvm-objcopy adds a new section into a 32-bit object file if
2## --add-section is given.
3
4# RUN: yaml2obj %s -o %t
5# RUN: echo -n abcdefg > %t.data
6
7## Case 1: Add a new section into an existing segment.
8# RUN: llvm-objcopy --add-section __TEXT,__bar=%t.data %t %t.out1
9# RUN: llvm-readobj --sections --section-data %t.out1 \
10# RUN:   | FileCheck %s --check-prefixes=COMMON,CASE1
11
12## Case 2: Add a new section into a nonexistent segment.
13# RUN: llvm-objcopy --add-section __FOO,__bar=%t.data %t %t.out2
14# RUN: llvm-readobj --sections --section-data %t.out2 \
15# RUN:   | FileCheck %s --check-prefixes=COMMON,CASE2
16
17## Case 3: Add a new section into an existing segment using /dev/null as an input.
18# RUN: llvm-objcopy --add-section __TEXT,__bar=/dev/null %t %t.out3
19# RUN: llvm-readobj --sections --section-data %t.out3 \
20# RUN:   | FileCheck %s --check-prefixes=COMMON,CASE3
21
22--- !mach-o
23FileHeader:
24  magic:           0xFEEDFACE
25  cputype:         0x00000007
26  cpusubtype:      0x00000003
27  filetype:        0x00000001
28  ncmds:           1
29  sizeofcmds:      124
30  flags:           0x00002000
31LoadCommands:
32  - cmd:             LC_SEGMENT
33    cmdsize:         124
34    segname:         __TEXT
35    vmaddr:          0
36    vmsize:          4
37    fileoff:         184
38    filesize:        4
39    maxprot:         7
40    initprot:        7
41    nsects:          1
42    flags:           0
43    Sections:
44      - sectname:        __text
45        segname:         __TEXT
46        addr:            0x0000000000000000
47        content:         'AABBCCDD'
48        size:            4
49        offset:          184
50        align:           0
51        reloff:          0x00000000
52        nreloc:          0
53        flags:           0x80000400
54        reserved1:       0x00000000
55        reserved2:       0x00000000
56        reserved3:       0x00000000
57
58# COMMON:         Index: 0
59# COMMON-NEXT:    Name: __text (5F 5F 74 65 78 74 00 00 00 00 00 00 00 00 00 00)
60# COMMON-NEXT:    Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00)
61# COMMON-NEXT:    Address: 0x0
62# COMMON-NEXT:    Size: 0x4
63# COMMON-NEXT:    Offset:
64# COMMON-NEXT:    Alignment: 0
65# COMMON-NEXT:    RelocationOffset: 0x0
66# COMMON-NEXT:    RelocationCount: 0
67# COMMON-NEXT:    Type: Regular (0x0)
68# COMMON-NEXT:    Attributes [ (0x800004)
69# COMMON-NEXT:      PureInstructions (0x800000)
70# COMMON-NEXT:      SomeInstructions (0x4)
71# COMMON-NEXT:    ]
72# COMMON-NEXT:    Reserved1: 0x0
73# COMMON-NEXT:    Reserved2: 0x0
74# COMMON-NEXT:    SectionData (
75# COMMON-NEXT:      0000: AABBCCDD                             |....|
76# COMMON-NEXT:    )
77
78# COMMON:         Index: 1
79# COMMON-NEXT:    Name: __bar (5F 5F 62 61 72 00 00 00 00 00 00 00 00 00 00 00)
80
81# CASE1-NEXT:     Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00)
82# CASE1-NEXT:     Address: 0x4
83# CASE1-NEXT:     Size: 0x7
84# CASE1-NEXT:     Offset: 224
85
86# CASE2-NEXT:     Segment: __FOO (5F 5F 46 4F 4F 00 00 00 00 00 00 00 00 00 00 00)
87# CASE2-NEXT:     Address: 0x98
88# CASE2-NEXT:     Size: 0x7
89# CASE2-NEXT:     Offset: 280
90
91# CASE3-NEXT:     Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00)
92# CASE3-NEXT:     Address: 0x4
93# CASE3-NEXT:     Size: 0x0
94# CASE3-NEXT:     Offset: 224
95
96# COMMON-NEXT:    Alignment: 0
97# COMMON-NEXT:    RelocationOffset: 0x0
98# COMMON-NEXT:    RelocationCount: 0
99# COMMON-NEXT:    Type: Regular (0x0)
100# COMMON-NEXT:    Attributes [ (0x0)
101# COMMON-NEXT:    ]
102# COMMON-NEXT:    Reserved1: 0x0
103# COMMON-NEXT:    Reserved2: 0x0
104
105# CASE1-NEXT:     SectionData (
106# CASE1-NEXT:       0000: 61626364 656667                      |abcdefg|
107# CASE1-NEXT:     )
108
109# CASE2-NEXT:     SectionData (
110# CASE2-NEXT:       0000: 61626364 656667                      |abcdefg|
111# CASE2-NEXT:     )
112
113# CASE3-NEXT:     SectionData (
114# CASE3-NEXT:     )
115