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