summaryrefslogtreecommitdiff
path: root/tests/run-getphdrnum.sh
blob: 889cdaf1e8e6391bd382fd2175ff60fa95a266d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#! /bin/sh

# testfile-phdrs.elf generated with python3 script
# import struct
# import sys
# 
# phnum = 66000
# 
# sys.stdout.buffer.write(
#     struct.pack(
#         "<16BHHIQQQIHHHHHH",
#         # EI_MAG
#         *b"\x7fELF",
#         # EI_CLASS = ELFCLASS64
#         2,
#         # EI_DATA = ELFDATA2LSB
#         1,
#         # EI_VERSION
#         1,
#         # EI_OSABI = ELFOSABI_SYSV
#         0,
#         # EI_ABIVERSION
#         0,
#         # EI_PAD
#         *bytes(7),
#         # e_type = ET_CORE
#         4,
#         # e_machine = EM_X86_64
#         62,
#         # e_version
#         1,
#         # e_entry
#         0,
#         # e_phoff = sizeof(Elf64_Ehdr) + sizeof(Elf64_Shdr)
#         128,
#         # e_shoff = sizeof(Elf64_Ehdr)
#         64,
#         # e_flags
#         0,
#         # e_ehsize
#         64,
#         # e_phentsize
#         56,
#         # e_phnum = PN_XNUM
#         0xFFFF,
#         # e_shentsize
#         64,
#         # e_shnum
#         1,
#         # e_shstrndx
#         0,
#     )
# )
# 
# sys.stdout.buffer.write(
#     struct.pack(
#         "<IIQQQQIIQQ",
#         # sh_name
#         0,
#         # sh_type = SHT_NULL
#         0,
#         # sh_flags
#         0,
#         # sh_addr
#         0,
#         # sh_offset
#         0,
#         # sh_size
#         0,
#         # sh_link
#         0,
#         # sh_info
#         phnum,
#         # sh_addralign
#         0,
#         # sh_entsize
#         0,
#     )
# )
# 
# for i in range(phnum):
#     sys.stdout.buffer.write(
#         struct.pack(
#             "<IIQQQQQQ",
#             # p_type = PT_LOAD
#             1,
#             # p_flags = PF_X|PF_W|PF_R
#             0x7,
#             # p_offset
#             0,
#             # p_vaddr
#             # i * 4096,
#             4096,
#             # p_paddr
#             0,
#             # p_filesz
#             0,
#             # p_memsz
#             4096,
#             # p_align
#             0,
#         )
#     )

. $srcdir/test-subr.sh

testfiles testfile-phdrs.elf

testrun_compare ${abs_top_builddir}/src/readelf -h testfile-phdrs.elf<<\EOF
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
  Class:                             ELF64
  Data:                              2's complement, little endian
  Ident Version:                     1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              CORE (Core file)
  Machine:                           AMD x86-64
  Version:                           1 (current)
  Entry point address:               0
  Start of program headers:          128 (bytes into file)
  Start of section headers:          64 (bytes into file)
  Flags:                             
  Size of this header:               64 (bytes)
  Size of program header entries:    56 (bytes)
  Number of program headers entries: 65535 (66000 in [0].sh_info)
  Size of section header entries:    64 (bytes)
  Number of section headers entries: 1
  Section header string table index: 0

EOF

testrun_compare ${abs_builddir}/getphdrnum testfile-phdrs.elf<<\EOF
66000
EOF

exit 0