1 ## Show that if --only-section is given, llvm-objcopy removes all sections
2 ## except ones specified in the option.
4 # RUN: yaml2obj %s -o %t
6 ## Specify all sections. The output file should be the same as the input.
7 # RUN: llvm-objcopy -j __TEXT,__text -j __DATA,__data -j __TEXT,__const %t %t2
10 ## Specify one section. The output file should contain only that section.
11 # RUN: llvm-objcopy --only-section __TEXT,__text %t %t3
12 # RUN: llvm-readobj --sections --section-data --macho-segment %t3 \
13 # RUN: | FileCheck %s --check-prefix=ONLY-TEXT-SECTION
15 # ONLY-TEXT-SECTION: Sections [
16 # ONLY-TEXT-SECTION-NEXT: Section {
17 # ONLY-TEXT-SECTION-NEXT: Index: 0
18 # ONLY-TEXT-SECTION-NEXT: Name: __text (5F 5F 74 65 78 74 00 00 00 00 00 00 00 00 00 00)
19 # ONLY-TEXT-SECTION-NEXT: Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00)
20 # ONLY-TEXT-SECTION-NEXT: Address: 0x0
21 # ONLY-TEXT-SECTION-NEXT: Size: 0x4
22 # ONLY-TEXT-SECTION-NEXT: Offset: 184
23 # ONLY-TEXT-SECTION-NEXT: Alignment: 0
24 # ONLY-TEXT-SECTION-NEXT: RelocationOffset: 0x0
25 # ONLY-TEXT-SECTION-NEXT: RelocationCount: 0
26 # ONLY-TEXT-SECTION-NEXT: Type: Regular (0x0)
27 # ONLY-TEXT-SECTION-NEXT: Attributes [ (0x800004)
28 # ONLY-TEXT-SECTION-NEXT: PureInstructions (0x800000)
29 # ONLY-TEXT-SECTION-NEXT: SomeInstructions (0x4)
30 # ONLY-TEXT-SECTION-NEXT: ]
31 # ONLY-TEXT-SECTION-NEXT: Reserved1: 0x0
32 # ONLY-TEXT-SECTION-NEXT: Reserved2: 0x0
33 # ONLY-TEXT-SECTION-NEXT: Reserved3: 0x0
34 # ONLY-TEXT-SECTION-NEXT: SectionData (
35 # ONLY-TEXT-SECTION-NEXT: 0000: AABBCCDD |....|
36 # ONLY-TEXT-SECTION-NEXT: )
37 # ONLY-TEXT-SECTION-NEXT: }
38 # ONLY-TEXT-SECTION-NEXT: ]
39 # ONLY-TEXT-SECTION-NEXT: Segment {
40 # ONLY-TEXT-SECTION-NEXT: Cmd: LC_SEGMENT_64
41 # ONLY-TEXT-SECTION-NEXT: Name:
42 # ONLY-TEXT-SECTION-NEXT: Size: 152
43 # ONLY-TEXT-SECTION-NEXT: vmaddr: 0x0
44 # ONLY-TEXT-SECTION-NEXT: vmsize: 0x4
45 # ONLY-TEXT-SECTION-NEXT: fileoff: 184
46 # ONLY-TEXT-SECTION-NEXT: filesize: 4
47 # ONLY-TEXT-SECTION-NEXT: maxprot: rwx
48 # ONLY-TEXT-SECTION-NEXT: initprot: rwx
49 # ONLY-TEXT-SECTION-NEXT: nsects: 1
50 # ONLY-TEXT-SECTION-NEXT: flags: 0x0
51 # ONLY-TEXT-SECTION-NEXT: }
53 ## Remove all sections if the specified section name is not present in the input.
54 # RUN: llvm-objcopy --only-section __TEXT,__nonexistent %t %t4 2>&1
55 # RUN: llvm-readobj --sections --section-data --macho-segment %t4 \
56 # RUN: | FileCheck %s --check-prefix=NONEXISTENT-SECTION
58 # NONEXISTENT-SECTION: Sections [
59 # NONEXISTENT-SECTION-NEXT: ]
60 # NONEXISTENT-SECTION-NEXT: Segment {
61 # NONEXISTENT-SECTION-NEXT: Cmd: LC_SEGMENT_64
62 # NONEXISTENT-SECTION-NEXT: Name:
63 # NONEXISTENT-SECTION-NEXT: Size: 72
64 # NONEXISTENT-SECTION-NEXT: vmaddr: 0x0
65 # NONEXISTENT-SECTION-NEXT: vmsize: 0x0
66 # NONEXISTENT-SECTION-NEXT: fileoff: 104
67 # NONEXISTENT-SECTION-NEXT: filesize: 0
68 # NONEXISTENT-SECTION-NEXT: maxprot: rwx
69 # NONEXISTENT-SECTION-NEXT: initprot: rwx
70 # NONEXISTENT-SECTION-NEXT: nsects: 0
71 # NONEXISTENT-SECTION-NEXT: flags: 0x0
72 # NONEXISTENT-SECTION-NEXT: }
74 ## Use wildcard to specify all sections under the __TEXT segment.
75 # RUN: llvm-objcopy --only-section "__TEXT,*" %t %t5 2>&1
76 # RUN: llvm-readobj --file-header --sections %t5 \
77 # RUN: | FileCheck %s --check-prefix=WILDCARD
79 ## Make sure that it doesn't care about the segment/section name separator ",".
80 # RUN: llvm-objcopy --only-section "__TEXT*" %t %t6 2>&1
83 # WILDCARD: NumOfLoadCommands: 1
84 # WILDCARD: Sections [
86 # WILDCARD-NEXT: Name: __text (5F 5F 74 65 78 74 00 00 00 00 00 00 00 00 00 00)
88 # WILDCARD-NEXT: Name: __const (5F 5F 63 6F 6E 73 74 00 00 00 00 00 00 00 00 00)
89 # WILDCARD-NOT: Index: 2
96 cpusubtype: 0x00000003
117 addr: 0x0000000000000000
125 reserved1: 0x00000000
126 reserved2: 0x00000000
127 reserved3: 0x00000000
130 addr: 0x0000000000000004
138 reserved1: 0x00000000
139 reserved2: 0x00000000
140 reserved3: 0x00000000
143 addr: 0x0000000000000008
151 reserved1: 0x00000000
152 reserved2: 0x00000000
153 reserved3: 0x00000000