1partitions.elf is a file containing a main partition and two loadable
2partitions "part1" and "part2" (see https://lld.llvm.org/Partitions.html
3for a description of partitions). This file tests that extracting the main
4and loadable partitions produces a file with the correct headers and sections.
5
6RUN: llvm-objcopy --extract-main-partition %p/Inputs/partitions.elf %t1
7RUN: llvm-objcopy --extract-partition=part1 %p/Inputs/partitions.elf %t2
8RUN: llvm-objcopy --extract-partition=part2 %p/Inputs/partitions.elf %t3
9
10RUN: llvm-readelf --headers --sections --symbols %t1 | FileCheck --check-prefix=MAIN %s
11RUN: llvm-readelf --headers --sections --symbols %t2 | FileCheck --check-prefix=PART1 %s
12RUN: llvm-readelf --headers --sections --symbols %t3 | FileCheck --check-prefix=PART2 %s
13
14MAIN:      ELF Header:
15MAIN-NEXT:   Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
16MAIN-NEXT:   Class:                             ELF64
17MAIN-NEXT:   Data:                              2's complement, little endian
18MAIN-NEXT:   Version:                           1 (current)
19MAIN-NEXT:   OS/ABI:                            UNIX - System V
20MAIN-NEXT:   ABI Version:                       0
21MAIN-NEXT:   Type:                              EXEC (Executable file)
22MAIN-NEXT:   Machine:                           Advanced Micro Devices X86-64
23MAIN-NEXT:   Version:                           0x1
24MAIN-NEXT:   Entry point address:               0x201000
25MAIN-NEXT:   Start of program headers:          64 (bytes into file)
26MAIN-NEXT:   Start of section headers:          12488 (bytes into file)
27MAIN-NEXT:   Flags:                             0x0
28MAIN-NEXT:   Size of this header:               64 (bytes)
29MAIN-NEXT:   Size of program headers:           56 (bytes)
30MAIN-NEXT:   Number of program headers:         8
31MAIN-NEXT:   Size of section headers:           64 (bytes)
32MAIN-NEXT:   Number of section headers:         13
33MAIN-NEXT:   Section header string table index: 11
34
35MAIN: Section Headers:
36MAIN-NEXT:   [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
37MAIN-NEXT:   [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
38MAIN-NEXT:   [ 1] .dynsym           DYNSYM          0000000000200200 000200 000030 18   A  4   1  8
39MAIN-NEXT:   [ 2] .gnu.hash         GNU_HASH        0000000000200230 000230 000020 00   A  1   0  8
40MAIN-NEXT:   [ 3] .hash             HASH            0000000000200250 000250 000018 04   A  1   0  4
41MAIN-NEXT:   [ 4] .dynstr           STRTAB          0000000000200268 000268 000014 00   A  0   0  1
42MAIN-NEXT:   [ 5] .rodata           PROGBITS        000000000020027c 00027c 000018 00   A  0   0  4
43MAIN-NEXT:   [ 6] .text0            PROGBITS        0000000000201000 001000 000001 00  AX  0   0  1
44MAIN-NEXT:   [ 7] .dynamic          DYNAMIC         0000000000202000 002000 000080 10  WA  4   0  8
45MAIN-NEXT:   [ 8] .part.end         NOBITS          0000000000209000 003000 001000 00  WA  0   0  1
46MAIN-NEXT:   [ 9] .comment          PROGBITS        0000000000000000 003000 000008 01  MS  0   0  1
47MAIN-NEXT:   [10] .symtab           SYMTAB          0000000000000000 003008 000048 18     12   2  8
48MAIN-NEXT:   [11] .shstrtab         STRTAB          0000000000000000 003050 000060 00      0   0  1
49MAIN-NEXT:   [12] .strtab           STRTAB          0000000000000000 0030b0 000011 00      0   0  1
50
51MAIN: Program Headers:
52MAIN-NEXT:   Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
53MAIN-NEXT:   PHDR           0x000040 0x0000000000200040 0x0000000000200040 0x0001c0 0x0001c0 R   0x8
54MAIN-NEXT:   LOAD           0x000000 0x0000000000200000 0x0000000000200000 0x000294 0x000294 R   0x1000
55MAIN-NEXT:   LOAD           0x001000 0x0000000000201000 0x0000000000201000 0x000001 0x000001 R E 0x1000
56MAIN-NEXT:   LOAD           0x002000 0x0000000000202000 0x0000000000202000 0x000080 0x000080 RW  0x1000
57MAIN-NEXT:   LOAD           0x003000 0x0000000000209000 0x0000000000209000 0x000000 0x001000 RW  0x1000
58MAIN-NEXT:   DYNAMIC        0x002000 0x0000000000202000 0x0000000000202000 0x000080 0x000080 RW  0x8
59MAIN-NEXT:   GNU_RELRO      0x002000 0x0000000000202000 0x0000000000202000 0x000080 0x001000 R   0x1
60MAIN-NEXT:   GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW  0x0
61
62MAIN: Symbol table '.dynsym' contains 2 entries:
63MAIN-NEXT:    Num:    Value          Size Type    Bind   Vis      Ndx Name
64MAIN-NEXT:      0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
65MAIN-NEXT:      1: 0000000000201000     0 NOTYPE  GLOBAL DEFAULT    6 _start
66
67MAIN: Symbol table '.symtab' contains 3 entries:
68MAIN-NEXT:    Num:    Value          Size Type    Bind   Vis      Ndx Name
69MAIN-NEXT:      0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
70MAIN-NEXT:      1: 0000000000202000     0 NOTYPE  LOCAL  HIDDEN     7 _DYNAMIC
71MAIN-NEXT:      2: 0000000000201000     0 NOTYPE  GLOBAL DEFAULT    6 _start
72
73PART1: ELF Header:
74PART1-NEXT:   Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
75PART1-NEXT:   Class:                             ELF64
76PART1-NEXT:   Data:                              2's complement, little endian
77PART1-NEXT:   Version:                           1 (current)
78PART1-NEXT:   OS/ABI:                            UNIX - System V
79PART1-NEXT:   ABI Version:                       0
80PART1-NEXT:   Type:                              DYN (Shared object file)
81PART1-NEXT:   Machine:                           Advanced Micro Devices X86-64
82PART1-NEXT:   Version:                           0x1
83PART1-NEXT:   Entry point address:               0x0
84PART1-NEXT:   Start of program headers:          64 (bytes into file)
85PART1-NEXT:   Start of section headers:          8336 (bytes into file)
86PART1-NEXT:   Flags:                             0x0
87PART1-NEXT:   Size of this header:               64 (bytes)
88PART1-NEXT:   Size of program headers:           56 (bytes)
89PART1-NEXT:   Number of program headers:         7
90PART1-NEXT:   Size of section headers:           64 (bytes)
91PART1-NEXT:   Number of section headers:         11
92PART1-NEXT:   Section header string table index: 9
93
94PART1: Section Headers:
95PART1-NEXT:   [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
96PART1-NEXT:   [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
97PART1-NEXT:   [ 1] .dynsym           DYNSYM          00000000002031c8 0001c8 000030 18   A  4   1  8
98PART1-NEXT:   [ 2] .gnu.hash         GNU_HASH        00000000002031f8 0001f8 000020 00   A  1   0  8
99PART1-NEXT:   [ 3] .hash             HASH            0000000000203218 000218 000018 04   A  1   0  4
100PART1-NEXT:   [ 4] .dynstr           STRTAB          0000000000203230 000230 00000a 00   A  0   0  1
101PART1-NEXT:   [ 5] .dynamic          DYNAMIC         0000000000204000 001000 000090 10  WA  4   0  8
102PART1-NEXT:   [ 6] .bss1             NOBITS          0000000000205000 002000 000008 00  WA  0   0  1
103PART1-NEXT:   [ 7] .comment          PROGBITS        0000000000000000 002000 000008 01  MS  0   0  1
104PART1-NEXT:   [ 8] .symtab           SYMTAB          0000000000000000 002008 000030 18     10   1  8
105PART1-NEXT:   [ 9] .shstrtab         STRTAB          0000000000000000 002038 00004d 00      0   0  1
106PART1-NEXT:   [10] .strtab           STRTAB          0000000000000000 002085 000004 00      0   0  1
107
108PART1: Program Headers:
109PART1-NEXT:   Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
110PART1-NEXT:   PHDR           0x000040 0x0000000000203040 0x0000000000203040 0x000188 0x000188 R   0x1
111PART1-NEXT:   LOAD           0x000000 0x0000000000203000 0x0000000000203000 0x00023a 0x00023a R   0x1000
112PART1-NEXT:   LOAD           0x001000 0x0000000000204000 0x0000000000204000 0x000090 0x000090 RW  0x1000
113PART1-NEXT:   LOAD           0x002000 0x0000000000205000 0x0000000000205000 0x000000 0x000008 RW  0x1000
114PART1-NEXT:   DYNAMIC        0x001000 0x0000000000204000 0x0000000000204000 0x000090 0x000090 RW  0x8
115PART1-NEXT:   GNU_RELRO      0x001000 0x0000000000204000 0x0000000000204000 0x000090 0x001000 R   0x1
116PART1-NEXT:   GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW  0x0
117
118PART1: Symbol table '.dynsym' contains 2 entries:
119PART1-NEXT:    Num:    Value          Size Type    Bind   Vis      Ndx Name
120PART1-NEXT:      0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
121PART1-NEXT:      1: 0000000000205000     0 NOTYPE  GLOBAL DEFAULT   15 g1
122
123PART1: Symbol table '.symtab' contains 2 entries:
124PART1-NEXT:    Num:    Value          Size Type    Bind   Vis      Ndx Name
125PART1-NEXT:      0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
126PART1-NEXT:      1: 0000000000205000     0 NOTYPE  GLOBAL DEFAULT    6 g1
127
128PART2: ELF Header:
129PART2-NEXT:   Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
130PART2-NEXT:   Class:                             ELF64
131PART2-NEXT:   Data:                              2's complement, little endian
132PART2-NEXT:   Version:                           1 (current)
133PART2-NEXT:   OS/ABI:                            UNIX - System V
134PART2-NEXT:   ABI Version:                       0
135PART2-NEXT:   Type:                              DYN (Shared object file)
136PART2-NEXT:   Machine:                           Advanced Micro Devices X86-64
137PART2-NEXT:   Version:                           0x1
138PART2-NEXT:   Entry point address:               0x0
139PART2-NEXT:   Start of program headers:          64 (bytes into file)
140PART2-NEXT:   Start of section headers:          8336 (bytes into file)
141PART2-NEXT:   Flags:                             0x0
142PART2-NEXT:   Size of this header:               64 (bytes)
143PART2-NEXT:   Size of program headers:           56 (bytes)
144PART2-NEXT:   Number of program headers:         7
145PART2-NEXT:   Size of section headers:           64 (bytes)
146PART2-NEXT:   Number of section headers:         11
147PART2-NEXT:   Section header string table index: 9
148
149PART2: Section Headers:
150PART2-NEXT:   [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
151PART2-NEXT:   [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
152PART2-NEXT:   [ 1] .dynsym           DYNSYM          00000000002061c8 0001c8 000030 18   A  4   1  8
153PART2-NEXT:   [ 2] .gnu.hash         GNU_HASH        00000000002061f8 0001f8 000020 00   A  1   0  8
154PART2-NEXT:   [ 3] .hash             HASH            0000000000206218 000218 000018 04   A  1   0  4
155PART2-NEXT:   [ 4] .dynstr           STRTAB          0000000000206230 000230 00000a 00   A  0   0  1
156PART2-NEXT:   [ 5] .dynamic          DYNAMIC         0000000000207000 001000 000090 10  WA  4   0  8
157PART2-NEXT:   [ 6] .bss2             NOBITS          0000000000208000 002000 000010 00  WA  0   0  1
158PART2-NEXT:   [ 7] .comment          PROGBITS        0000000000000000 002000 000008 01  MS  0   0  1
159PART2-NEXT:   [ 8] .symtab           SYMTAB          0000000000000000 002008 000030 18     10   1  8
160PART2-NEXT:   [ 9] .shstrtab         STRTAB          0000000000000000 002038 00004d 00      0   0  1
161PART2-NEXT:   [10] .strtab           STRTAB          0000000000000000 002085 000004 00      0   0  1
162
163PART2: Program Headers:
164PART2-NEXT:   Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
165PART2-NEXT:   PHDR           0x000040 0x0000000000206040 0x0000000000206040 0x000188 0x000188 R   0x1
166PART2-NEXT:   LOAD           0x000000 0x0000000000206000 0x0000000000206000 0x00023a 0x00023a R   0x1000
167PART2-NEXT:   LOAD           0x001000 0x0000000000207000 0x0000000000207000 0x000090 0x000090 RW  0x1000
168PART2-NEXT:   LOAD           0x002000 0x0000000000208000 0x0000000000208000 0x000000 0x000010 RW  0x1000
169PART2-NEXT:   DYNAMIC        0x001000 0x0000000000207000 0x0000000000207000 0x000090 0x000090 RW  0x8
170PART2-NEXT:   GNU_RELRO      0x001000 0x0000000000207000 0x0000000000207000 0x000090 0x001000 R   0x1
171PART2-NEXT:   GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW  0x0
172
173PART2: Symbol table '.dynsym' contains 2 entries:
174PART2-NEXT:    Num:    Value          Size Type    Bind   Vis      Ndx Name
175PART2-NEXT:      0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
176PART2-NEXT:      1: 0000000000208000     0 NOTYPE  GLOBAL DEFAULT   23 g2
177
178PART2: Symbol table '.symtab' contains 2 entries:
179PART2-NEXT:    Num:    Value          Size Type    Bind   Vis      Ndx Name
180PART2-NEXT:      0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
181PART2-NEXT:      1: 0000000000208000     0 NOTYPE  GLOBAL DEFAULT    6 g2
182
183RUN: not llvm-objcopy --extract-partition=part3 %p/Inputs/partitions.elf %t4 2>&1 | FileCheck --check-prefix=ERROR1 %s
184ERROR1: error: could not find partition named 'part3'
185
186RUN: not llvm-objcopy --extract-main-partition --extract-partition=part2 %p/Inputs/partitions.elf %t4 2>&1 | FileCheck --check-prefix=ERROR2 %s
187ERROR2: error: cannot specify --extract-partition together with --extract-main-partition
188