xref: /llvm-project/llvm/test/tools/llvm-objcopy/ELF/partitions.test (revision 9e1319df7e6508795e6f643c8b50306a5046d0b5)
18d58a98cSPeter Collingbournepartitions.elf is a file containing a main partition and two loadable
28d58a98cSPeter Collingbournepartitions "part1" and "part2" (see https://lld.llvm.org/Partitions.html
38d58a98cSPeter Collingbournefor a description of partitions). This file tests that extracting the main
48d58a98cSPeter Collingbourneand loadable partitions produces a file with the correct headers and sections.
58d58a98cSPeter Collingbourne
68d58a98cSPeter CollingbourneRUN: llvm-objcopy --extract-main-partition %p/Inputs/partitions.elf %t1
78d58a98cSPeter CollingbourneRUN: llvm-objcopy --extract-partition=part1 %p/Inputs/partitions.elf %t2
88d58a98cSPeter CollingbourneRUN: llvm-objcopy --extract-partition=part2 %p/Inputs/partitions.elf %t3
98d58a98cSPeter Collingbourne
108d58a98cSPeter CollingbourneRUN: llvm-readelf --headers --sections --symbols %t1 | FileCheck --check-prefix=MAIN %s
118d58a98cSPeter CollingbourneRUN: llvm-readelf --headers --sections --symbols %t2 | FileCheck --check-prefix=PART1 %s
128d58a98cSPeter CollingbourneRUN: llvm-readelf --headers --sections --symbols %t3 | FileCheck --check-prefix=PART2 %s
138d58a98cSPeter Collingbourne
148d58a98cSPeter CollingbourneMAIN:      ELF Header:
158d58a98cSPeter CollingbourneMAIN-NEXT:   Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
168d58a98cSPeter CollingbourneMAIN-NEXT:   Class:                             ELF64
178d58a98cSPeter CollingbourneMAIN-NEXT:   Data:                              2's complement, little endian
188d58a98cSPeter CollingbourneMAIN-NEXT:   Version:                           1 (current)
198d58a98cSPeter CollingbourneMAIN-NEXT:   OS/ABI:                            UNIX - System V
20896b84acSFangrui SongMAIN-NEXT:   ABI Version:                       0
218d58a98cSPeter CollingbourneMAIN-NEXT:   Type:                              EXEC (Executable file)
228d58a98cSPeter CollingbourneMAIN-NEXT:   Machine:                           Advanced Micro Devices X86-64
238d58a98cSPeter CollingbourneMAIN-NEXT:   Version:                           0x1
248d58a98cSPeter CollingbourneMAIN-NEXT:   Entry point address:               0x201000
258d58a98cSPeter CollingbourneMAIN-NEXT:   Start of program headers:          64 (bytes into file)
268d58a98cSPeter CollingbourneMAIN-NEXT:   Start of section headers:          12488 (bytes into file)
278d58a98cSPeter CollingbourneMAIN-NEXT:   Flags:                             0x0
288d58a98cSPeter CollingbourneMAIN-NEXT:   Size of this header:               64 (bytes)
298d58a98cSPeter CollingbourneMAIN-NEXT:   Size of program headers:           56 (bytes)
308d58a98cSPeter CollingbourneMAIN-NEXT:   Number of program headers:         8
318d58a98cSPeter CollingbourneMAIN-NEXT:   Size of section headers:           64 (bytes)
328d58a98cSPeter CollingbourneMAIN-NEXT:   Number of section headers:         13
338d58a98cSPeter CollingbourneMAIN-NEXT:   Section header string table index: 11
348d58a98cSPeter Collingbourne
358d58a98cSPeter CollingbourneMAIN: Section Headers:
368d58a98cSPeter CollingbourneMAIN-NEXT:   [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
378d58a98cSPeter CollingbourneMAIN-NEXT:   [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
388d58a98cSPeter CollingbourneMAIN-NEXT:   [ 1] .dynsym           DYNSYM          0000000000200200 000200 000030 18   A  4   1  8
398d58a98cSPeter CollingbourneMAIN-NEXT:   [ 2] .gnu.hash         GNU_HASH        0000000000200230 000230 000020 00   A  1   0  8
408d58a98cSPeter CollingbourneMAIN-NEXT:   [ 3] .hash             HASH            0000000000200250 000250 000018 04   A  1   0  4
418d58a98cSPeter CollingbourneMAIN-NEXT:   [ 4] .dynstr           STRTAB          0000000000200268 000268 000014 00   A  0   0  1
428d58a98cSPeter CollingbourneMAIN-NEXT:   [ 5] .rodata           PROGBITS        000000000020027c 00027c 000018 00   A  0   0  4
438d58a98cSPeter CollingbourneMAIN-NEXT:   [ 6] .text0            PROGBITS        0000000000201000 001000 000001 00  AX  0   0  1
448d58a98cSPeter CollingbourneMAIN-NEXT:   [ 7] .dynamic          DYNAMIC         0000000000202000 002000 000080 10  WA  4   0  8
458d58a98cSPeter CollingbourneMAIN-NEXT:   [ 8] .part.end         NOBITS          0000000000209000 003000 001000 00  WA  0   0  1
468d58a98cSPeter CollingbourneMAIN-NEXT:   [ 9] .comment          PROGBITS        0000000000000000 003000 000008 01  MS  0   0  1
478d58a98cSPeter CollingbourneMAIN-NEXT:   [10] .symtab           SYMTAB          0000000000000000 003008 000048 18     12   2  8
488d58a98cSPeter CollingbourneMAIN-NEXT:   [11] .shstrtab         STRTAB          0000000000000000 003050 000060 00      0   0  1
498d58a98cSPeter CollingbourneMAIN-NEXT:   [12] .strtab           STRTAB          0000000000000000 0030b0 000011 00      0   0  1
508d58a98cSPeter Collingbourne
518d58a98cSPeter CollingbourneMAIN: Program Headers:
528d58a98cSPeter CollingbourneMAIN-NEXT:   Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
538d58a98cSPeter CollingbourneMAIN-NEXT:   PHDR           0x000040 0x0000000000200040 0x0000000000200040 0x0001c0 0x0001c0 R   0x8
548d58a98cSPeter CollingbourneMAIN-NEXT:   LOAD           0x000000 0x0000000000200000 0x0000000000200000 0x000294 0x000294 R   0x1000
558d58a98cSPeter CollingbourneMAIN-NEXT:   LOAD           0x001000 0x0000000000201000 0x0000000000201000 0x000001 0x000001 R E 0x1000
568d58a98cSPeter CollingbourneMAIN-NEXT:   LOAD           0x002000 0x0000000000202000 0x0000000000202000 0x000080 0x000080 RW  0x1000
578d58a98cSPeter CollingbourneMAIN-NEXT:   LOAD           0x003000 0x0000000000209000 0x0000000000209000 0x000000 0x001000 RW  0x1000
588d58a98cSPeter CollingbourneMAIN-NEXT:   DYNAMIC        0x002000 0x0000000000202000 0x0000000000202000 0x000080 0x000080 RW  0x8
598d58a98cSPeter CollingbourneMAIN-NEXT:   GNU_RELRO      0x002000 0x0000000000202000 0x0000000000202000 0x000080 0x001000 R   0x1
608d58a98cSPeter CollingbourneMAIN-NEXT:   GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW  0x0
618d58a98cSPeter Collingbourne
62*9e1319dfSFangrui SongMAIN: Symbol table '.dynsym' contains 2 entries:
63*9e1319dfSFangrui SongMAIN-NEXT:    Num:    Value          Size Type    Bind   Vis      Ndx Name
64*9e1319dfSFangrui SongMAIN-NEXT:      0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
65*9e1319dfSFangrui SongMAIN-NEXT:      1: 0000000000201000     0 NOTYPE  GLOBAL DEFAULT    6 _start
66*9e1319dfSFangrui Song
67*9e1319dfSFangrui SongMAIN: Symbol table '.symtab' contains 3 entries:
68*9e1319dfSFangrui SongMAIN-NEXT:    Num:    Value          Size Type    Bind   Vis      Ndx Name
69*9e1319dfSFangrui SongMAIN-NEXT:      0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
70*9e1319dfSFangrui SongMAIN-NEXT:      1: 0000000000202000     0 NOTYPE  LOCAL  HIDDEN     7 _DYNAMIC
71*9e1319dfSFangrui SongMAIN-NEXT:      2: 0000000000201000     0 NOTYPE  GLOBAL DEFAULT    6 _start
72*9e1319dfSFangrui Song
738d58a98cSPeter CollingbournePART1: ELF Header:
748d58a98cSPeter CollingbournePART1-NEXT:   Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
758d58a98cSPeter CollingbournePART1-NEXT:   Class:                             ELF64
768d58a98cSPeter CollingbournePART1-NEXT:   Data:                              2's complement, little endian
778d58a98cSPeter CollingbournePART1-NEXT:   Version:                           1 (current)
788d58a98cSPeter CollingbournePART1-NEXT:   OS/ABI:                            UNIX - System V
79896b84acSFangrui SongPART1-NEXT:   ABI Version:                       0
808d58a98cSPeter CollingbournePART1-NEXT:   Type:                              DYN (Shared object file)
818d58a98cSPeter CollingbournePART1-NEXT:   Machine:                           Advanced Micro Devices X86-64
828d58a98cSPeter CollingbournePART1-NEXT:   Version:                           0x1
838d58a98cSPeter CollingbournePART1-NEXT:   Entry point address:               0x0
848d58a98cSPeter CollingbournePART1-NEXT:   Start of program headers:          64 (bytes into file)
858d58a98cSPeter CollingbournePART1-NEXT:   Start of section headers:          8336 (bytes into file)
868d58a98cSPeter CollingbournePART1-NEXT:   Flags:                             0x0
878d58a98cSPeter CollingbournePART1-NEXT:   Size of this header:               64 (bytes)
888d58a98cSPeter CollingbournePART1-NEXT:   Size of program headers:           56 (bytes)
898d58a98cSPeter CollingbournePART1-NEXT:   Number of program headers:         7
908d58a98cSPeter CollingbournePART1-NEXT:   Size of section headers:           64 (bytes)
918d58a98cSPeter CollingbournePART1-NEXT:   Number of section headers:         11
928d58a98cSPeter CollingbournePART1-NEXT:   Section header string table index: 9
938d58a98cSPeter Collingbourne
948d58a98cSPeter CollingbournePART1: Section Headers:
958d58a98cSPeter CollingbournePART1-NEXT:   [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
968d58a98cSPeter CollingbournePART1-NEXT:   [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
978d58a98cSPeter CollingbournePART1-NEXT:   [ 1] .dynsym           DYNSYM          00000000002031c8 0001c8 000030 18   A  4   1  8
988d58a98cSPeter CollingbournePART1-NEXT:   [ 2] .gnu.hash         GNU_HASH        00000000002031f8 0001f8 000020 00   A  1   0  8
998d58a98cSPeter CollingbournePART1-NEXT:   [ 3] .hash             HASH            0000000000203218 000218 000018 04   A  1   0  4
1008d58a98cSPeter CollingbournePART1-NEXT:   [ 4] .dynstr           STRTAB          0000000000203230 000230 00000a 00   A  0   0  1
1018d58a98cSPeter CollingbournePART1-NEXT:   [ 5] .dynamic          DYNAMIC         0000000000204000 001000 000090 10  WA  4   0  8
1028d58a98cSPeter CollingbournePART1-NEXT:   [ 6] .bss1             NOBITS          0000000000205000 002000 000008 00  WA  0   0  1
1038d58a98cSPeter CollingbournePART1-NEXT:   [ 7] .comment          PROGBITS        0000000000000000 002000 000008 01  MS  0   0  1
1048d58a98cSPeter CollingbournePART1-NEXT:   [ 8] .symtab           SYMTAB          0000000000000000 002008 000030 18     10   1  8
1058d58a98cSPeter CollingbournePART1-NEXT:   [ 9] .shstrtab         STRTAB          0000000000000000 002038 00004d 00      0   0  1
1068d58a98cSPeter CollingbournePART1-NEXT:   [10] .strtab           STRTAB          0000000000000000 002085 000004 00      0   0  1
1078d58a98cSPeter Collingbourne
1088d58a98cSPeter CollingbournePART1: Program Headers:
1098d58a98cSPeter CollingbournePART1-NEXT:   Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
1108d58a98cSPeter CollingbournePART1-NEXT:   PHDR           0x000040 0x0000000000203040 0x0000000000203040 0x000188 0x000188 R   0x1
1118d58a98cSPeter CollingbournePART1-NEXT:   LOAD           0x000000 0x0000000000203000 0x0000000000203000 0x00023a 0x00023a R   0x1000
1128d58a98cSPeter CollingbournePART1-NEXT:   LOAD           0x001000 0x0000000000204000 0x0000000000204000 0x000090 0x000090 RW  0x1000
1138d58a98cSPeter CollingbournePART1-NEXT:   LOAD           0x002000 0x0000000000205000 0x0000000000205000 0x000000 0x000008 RW  0x1000
1148d58a98cSPeter CollingbournePART1-NEXT:   DYNAMIC        0x001000 0x0000000000204000 0x0000000000204000 0x000090 0x000090 RW  0x8
1158d58a98cSPeter CollingbournePART1-NEXT:   GNU_RELRO      0x001000 0x0000000000204000 0x0000000000204000 0x000090 0x001000 R   0x1
1168d58a98cSPeter CollingbournePART1-NEXT:   GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW  0x0
1178d58a98cSPeter Collingbourne
118*9e1319dfSFangrui SongPART1: Symbol table '.dynsym' contains 2 entries:
119*9e1319dfSFangrui SongPART1-NEXT:    Num:    Value          Size Type    Bind   Vis      Ndx Name
120*9e1319dfSFangrui SongPART1-NEXT:      0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
121*9e1319dfSFangrui SongPART1-NEXT:      1: 0000000000205000     0 NOTYPE  GLOBAL DEFAULT   15 g1
122*9e1319dfSFangrui Song
123*9e1319dfSFangrui SongPART1: Symbol table '.symtab' contains 2 entries:
124*9e1319dfSFangrui SongPART1-NEXT:    Num:    Value          Size Type    Bind   Vis      Ndx Name
125*9e1319dfSFangrui SongPART1-NEXT:      0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
126*9e1319dfSFangrui SongPART1-NEXT:      1: 0000000000205000     0 NOTYPE  GLOBAL DEFAULT    6 g1
127*9e1319dfSFangrui Song
1288d58a98cSPeter CollingbournePART2: ELF Header:
1298d58a98cSPeter CollingbournePART2-NEXT:   Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
1308d58a98cSPeter CollingbournePART2-NEXT:   Class:                             ELF64
1318d58a98cSPeter CollingbournePART2-NEXT:   Data:                              2's complement, little endian
1328d58a98cSPeter CollingbournePART2-NEXT:   Version:                           1 (current)
1338d58a98cSPeter CollingbournePART2-NEXT:   OS/ABI:                            UNIX - System V
134896b84acSFangrui SongPART2-NEXT:   ABI Version:                       0
1358d58a98cSPeter CollingbournePART2-NEXT:   Type:                              DYN (Shared object file)
1368d58a98cSPeter CollingbournePART2-NEXT:   Machine:                           Advanced Micro Devices X86-64
1378d58a98cSPeter CollingbournePART2-NEXT:   Version:                           0x1
1388d58a98cSPeter CollingbournePART2-NEXT:   Entry point address:               0x0
1398d58a98cSPeter CollingbournePART2-NEXT:   Start of program headers:          64 (bytes into file)
1408d58a98cSPeter CollingbournePART2-NEXT:   Start of section headers:          8336 (bytes into file)
1418d58a98cSPeter CollingbournePART2-NEXT:   Flags:                             0x0
1428d58a98cSPeter CollingbournePART2-NEXT:   Size of this header:               64 (bytes)
1438d58a98cSPeter CollingbournePART2-NEXT:   Size of program headers:           56 (bytes)
1448d58a98cSPeter CollingbournePART2-NEXT:   Number of program headers:         7
1458d58a98cSPeter CollingbournePART2-NEXT:   Size of section headers:           64 (bytes)
1468d58a98cSPeter CollingbournePART2-NEXT:   Number of section headers:         11
1478d58a98cSPeter CollingbournePART2-NEXT:   Section header string table index: 9
1488d58a98cSPeter Collingbourne
1498d58a98cSPeter CollingbournePART2: Section Headers:
1508d58a98cSPeter CollingbournePART2-NEXT:   [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
1518d58a98cSPeter CollingbournePART2-NEXT:   [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
1528d58a98cSPeter CollingbournePART2-NEXT:   [ 1] .dynsym           DYNSYM          00000000002061c8 0001c8 000030 18   A  4   1  8
1538d58a98cSPeter CollingbournePART2-NEXT:   [ 2] .gnu.hash         GNU_HASH        00000000002061f8 0001f8 000020 00   A  1   0  8
1548d58a98cSPeter CollingbournePART2-NEXT:   [ 3] .hash             HASH            0000000000206218 000218 000018 04   A  1   0  4
1558d58a98cSPeter CollingbournePART2-NEXT:   [ 4] .dynstr           STRTAB          0000000000206230 000230 00000a 00   A  0   0  1
1568d58a98cSPeter CollingbournePART2-NEXT:   [ 5] .dynamic          DYNAMIC         0000000000207000 001000 000090 10  WA  4   0  8
1578d58a98cSPeter CollingbournePART2-NEXT:   [ 6] .bss2             NOBITS          0000000000208000 002000 000010 00  WA  0   0  1
1588d58a98cSPeter CollingbournePART2-NEXT:   [ 7] .comment          PROGBITS        0000000000000000 002000 000008 01  MS  0   0  1
1598d58a98cSPeter CollingbournePART2-NEXT:   [ 8] .symtab           SYMTAB          0000000000000000 002008 000030 18     10   1  8
1608d58a98cSPeter CollingbournePART2-NEXT:   [ 9] .shstrtab         STRTAB          0000000000000000 002038 00004d 00      0   0  1
1618d58a98cSPeter CollingbournePART2-NEXT:   [10] .strtab           STRTAB          0000000000000000 002085 000004 00      0   0  1
1628d58a98cSPeter Collingbourne
1638d58a98cSPeter CollingbournePART2: Program Headers:
1648d58a98cSPeter CollingbournePART2-NEXT:   Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
1658d58a98cSPeter CollingbournePART2-NEXT:   PHDR           0x000040 0x0000000000206040 0x0000000000206040 0x000188 0x000188 R   0x1
1668d58a98cSPeter CollingbournePART2-NEXT:   LOAD           0x000000 0x0000000000206000 0x0000000000206000 0x00023a 0x00023a R   0x1000
1678d58a98cSPeter CollingbournePART2-NEXT:   LOAD           0x001000 0x0000000000207000 0x0000000000207000 0x000090 0x000090 RW  0x1000
1688d58a98cSPeter CollingbournePART2-NEXT:   LOAD           0x002000 0x0000000000208000 0x0000000000208000 0x000000 0x000010 RW  0x1000
1698d58a98cSPeter CollingbournePART2-NEXT:   DYNAMIC        0x001000 0x0000000000207000 0x0000000000207000 0x000090 0x000090 RW  0x8
1708d58a98cSPeter CollingbournePART2-NEXT:   GNU_RELRO      0x001000 0x0000000000207000 0x0000000000207000 0x000090 0x001000 R   0x1
1718d58a98cSPeter CollingbournePART2-NEXT:   GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW  0x0
1728d58a98cSPeter Collingbourne
173*9e1319dfSFangrui SongPART2: Symbol table '.dynsym' contains 2 entries:
174*9e1319dfSFangrui SongPART2-NEXT:    Num:    Value          Size Type    Bind   Vis      Ndx Name
175*9e1319dfSFangrui SongPART2-NEXT:      0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
176*9e1319dfSFangrui SongPART2-NEXT:      1: 0000000000208000     0 NOTYPE  GLOBAL DEFAULT   23 g2
177*9e1319dfSFangrui Song
178*9e1319dfSFangrui SongPART2: Symbol table '.symtab' contains 2 entries:
179*9e1319dfSFangrui SongPART2-NEXT:    Num:    Value          Size Type    Bind   Vis      Ndx Name
180*9e1319dfSFangrui SongPART2-NEXT:      0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
181*9e1319dfSFangrui SongPART2-NEXT:      1: 0000000000208000     0 NOTYPE  GLOBAL DEFAULT    6 g2
182*9e1319dfSFangrui Song
1838d58a98cSPeter CollingbourneRUN: not llvm-objcopy --extract-partition=part3 %p/Inputs/partitions.elf %t4 2>&1 | FileCheck --check-prefix=ERROR1 %s
1848d58a98cSPeter CollingbourneERROR1: error: could not find partition named 'part3'
1858d58a98cSPeter Collingbourne
1868d58a98cSPeter CollingbourneRUN: not llvm-objcopy --extract-main-partition --extract-partition=part2 %p/Inputs/partitions.elf %t4 2>&1 | FileCheck --check-prefix=ERROR2 %s
1878d58a98cSPeter CollingbourneERROR2: error: cannot specify --extract-partition together with --extract-main-partition
188