blob: 94142ebf81ef58c904929841574188b6171475e2 (
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
#!/bin/sh
set -eu
: "${PACKAGE_VERSION:?}"
: "${CPU_AS:?}" "${CPU_LD:?}" "${CPU_AR:?}" "${CPU_OBJDUMP:?}"
TMP=${TMPDIR:-/tmp}/libmcpu-objdump-$$
trap 'rm -rf "$TMP"' EXIT HUP INT TERM
mkdir -p "$TMP"
cat > "$TMP/unit.s" <<'EOS'
.global entry
.global data_global
.extern external_function
.text
entry:
SETF CF
CLRF AF
CLRCPUF
CLRMPUF
LDI r64@0x00000, 41
CALL local_helper
CALL external_function
RET
local_helper:
LDI r64@0x00008, 1
IADD r64@0x00000, r64@0x00000, r64@0x00008
RET
.data
data_global:
.integer 64, 7
data_pointer:
.ptr data_global
EOS
cat > "$TMP/dyn.s" <<'EOS'
.global dyn_api
.global dyn_data
.text
dyn_api:
CALL local_dyn
RET
local_dyn:
LDI r64@0x00008, 2
RET
.data
dyn_data:
.integer 64, 9
EOS
cat > "$TMP/a.s" <<'EOS'
.global archive_a
.text
archive_a:
RET
EOS
cat > "$TMP/b.s" <<'EOS'
.global archive_b
.text
archive_b:
RET
EOS
"$CPU_AS" -o "$TMP/unit.o" "$TMP/unit.s"
"$CPU_AS" -o "$TMP/dyn.o" "$TMP/dyn.s"
"$CPU_AS" -o "$TMP/a.o" "$TMP/a.s"
"$CPU_AS" -o "$TMP/b.o" "$TMP/b.s"
"$CPU_LD" --shared --soname=libobjdump.so.1 -o "$TMP/libobjdump.so" "$TMP/dyn.o"
"$CPU_AR" rcs "$TMP/libobjdump.a" "$TMP/a.o" "$TMP/b.o"
"$CPU_OBJDUMP" -h "$TMP/unit.o" > "$TMP/headers.txt"
grep -q '^Sections:$' "$TMP/headers.txt"
grep -q '\.text' "$TMP/headers.txt"
grep -q '\.data' "$TMP/headers.txt"
grep -q 'PROGBITS.*CODE' "$TMP/headers.txt"
"$CPU_OBJDUMP" -t "$TMP/unit.o" > "$TMP/symbols.txt"
grep -q '^SYMBOL TABLE:$' "$TMP/symbols.txt"
grep -q ' entry$' "$TMP/symbols.txt"
grep -q ' local_helper$' "$TMP/symbols.txt"
grep -q ' data_global$' "$TMP/symbols.txt"
grep -q ' external_function$' "$TMP/symbols.txt"
"$CPU_OBJDUMP" -r "$TMP/unit.o" > "$TMP/relocs.txt"
grep -q 'RELOCATION RECORDS FOR \[.text\]' "$TMP/relocs.txt"
grep -q 'R_MCPU_CODE64.*local_helper' "$TMP/relocs.txt"
grep -q 'R_MCPU_CODE64.*external_function' "$TMP/relocs.txt"
"$CPU_OBJDUMP" -d -r "$TMP/unit.o" > "$TMP/disasm.txt"
grep -q 'Disassembly of section .text:' "$TMP/disasm.txt"
grep -q '<entry>:' "$TMP/disasm.txt"
grep -q '<local_helper>:' "$TMP/disasm.txt"
grep -q 'SETF.*CF' "$TMP/disasm.txt"
grep -q 'CLRF.*AF' "$TMP/disasm.txt"
grep -q 'CLRCPUF' "$TMP/disasm.txt"
grep -q 'CLRMPUF' "$TMP/disasm.txt"
grep -q 'LDI.*r64@0x00000, 41' "$TMP/disasm.txt"
grep -q 'CALL.*<local_helper>' "$TMP/disasm.txt"
grep -q 'CALL.*<external_function>' "$TMP/disasm.txt"
grep -q 'R_MCPU_CODE64.*local_helper' "$TMP/disasm.txt"
# -r remains complete with -d: non-executable-section relocations are
# printed separately while .text relocations stay next to instructions.
grep -q 'RELOCATION RECORDS FOR \[.data\]' "$TMP/disasm.txt"
grep -q 'R_MCPU_PTR64_DATA.*data_global' "$TMP/disasm.txt"
"$CPU_OBJDUMP" -s -j .data "$TMP/unit.o" > "$TMP/data.txt"
grep -q 'Contents of section .data:' "$TMP/data.txt"
if grep -q 'Contents of section .text:' "$TMP/data.txt"; then
echo "mcpu-objdump -j .data unexpectedly displayed .text contents" >&2
exit 1
fi
"$CPU_OBJDUMP" -D -j .data "$TMP/unit.o" > "$TMP/all-data.txt"
grep -q 'Disassembly of section .data:' "$TMP/all-data.txt"
"$CPU_OBJDUMP" -T "$TMP/libobjdump.so" > "$TMP/dynamic.txt"
grep -q '^DYNAMIC SYMBOL TABLE:$' "$TMP/dynamic.txt"
grep -q ' dyn_api$' "$TMP/dynamic.txt"
grep -q ' dyn_data$' "$TMP/dynamic.txt"
"$CPU_OBJDUMP" -d -r "$TMP/libobjdump.so" > "$TMP/dynamic-disasm.txt"
grep -q '<dyn_api>:' "$TMP/dynamic-disasm.txt"
grep -q 'CALL.*<.L\$0\$0>' "$TMP/dynamic-disasm.txt"
grep -q 'R_MCPU_CODE64.*.L\$0\$0' "$TMP/dynamic-disasm.txt"
"$CPU_OBJDUMP" -t "$TMP/libobjdump.a" > "$TMP/archive.txt"
grep -F "$TMP/libobjdump.a(a.o):" "$TMP/archive.txt" >/dev/null
grep -F "$TMP/libobjdump.a(b.o):" "$TMP/archive.txt" >/dev/null
grep -q ' archive_a$' "$TMP/archive.txt"
grep -q ' archive_b$' "$TMP/archive.txt"
# Grouped short options and attached -j argument are accepted.
"$CPU_OBJDUMP" -hdr -j.text "$TMP/unit.o" > "$TMP/grouped.txt"
grep -q 'Sections:' "$TMP/grouped.txt"
grep -q 'Disassembly of section .text:' "$TMP/grouped.txt"
grep -q 'R_MCPU_CODE64' "$TMP/grouped.txt"
# Missing/invalid input remains a hard error.
dd if=/dev/zero of="$TMP/bad" bs=256 count=1 2>/dev/null
if "$CPU_OBJDUMP" -h "$TMP/bad" > /dev/null 2> "$TMP/bad.err"; then
echo "mcpu-objdump unexpectedly accepted a non-MELF file" >&2
exit 1
fi
grep -q 'not a MELF file' "$TMP/bad.err"
if "$CPU_OBJDUMP" "$TMP/unit.o" > /dev/null 2> "$TMP/no-option.err"; then
echo "mcpu-objdump unexpectedly accepted no display option" >&2
exit 1
fi
grep -q 'at least one display option is required' "$TMP/no-option.err"
"$CPU_OBJDUMP" --help | grep -q -- '--disassemble-all'
"$CPU_OBJDUMP" --help | grep -q -- '--dynamic-syms'
"$CPU_OBJDUMP" --help | grep -q -- '--section=NAME'
"$CPU_OBJDUMP" --version | grep -Fq "$PACKAGE_VERSION"
|