blob: eb92b33702e53a10a81c4d1ecd145730b49fd52b (
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
|
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-or-later
set -eu
elf=$1
readelf=$2
nm=$3
arch=$4
case "$arch" in
riscv) expected_machine='RISC-V' ;;
aarch64) expected_machine='AArch64' ;;
x86_64) expected_machine='Advanced Micro Devices X86-64' ;;
*) echo "ELF check: unsupported architecture: $arch" >&2; exit 2 ;;
esac
machine=$($readelf -h "$elf" | sed -n 's/^[[:space:]]*Machine:[[:space:]]*//p')
[ "$machine" = "$expected_machine" ] || {
echo "ELF check: expected machine '$expected_machine', got '$machine'" >&2
exit 1
}
entry=$($readelf -h "$elf" | sed -n 's/^[[:space:]]*Entry point address:[[:space:]]*//p')
[ -n "$entry" ] && [ "$entry" != 0x0 ] || {
echo "ELF check: kernel has no entry point" >&2
exit 1
}
undefined=$($nm -u "$elf" || true)
[ -z "$undefined" ] || {
echo "ELF check: undefined symbols:" >&2
printf '%s\n' "$undefined" >&2
exit 1
}
if $readelf -W -l "$elf" | awk '$1 == "LOAD" && $0 ~ /W/ && $0 ~ /E/ { found=1 } END { exit !found }'; then
echo "ELF check: writable and executable LOAD segment" >&2
exit 1
fi
$readelf -S "$elf" | grep -q '[.]rela[.]dyn' || {
echo "ELF check: missing relocation section .rela.dyn" >&2
exit 1
}
echo "Kernel ELF OK: $machine, entry $entry"
|