summaryrefslogtreecommitdiff
path: root/build-aux/lint-bin
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2025-03-01 14:53:58 -0700
committerLuke T. Shumaker <lukeshu@lukeshu.com>2025-03-01 17:25:04 -0700
commit6fedfe71cfab86aecf4168ecf35961bf88ce0438 (patch)
tree0c1d961f46881a8fb1bf46b23fdb2c927624309a /build-aux/lint-bin
parent902a7661cfed71b1f50aa95bac9345883cb435cc (diff)
lint-bin: (dry-run) lint that list of functions matches stack.c.gen
Diffstat (limited to 'build-aux/lint-bin')
-rwxr-xr-xbuild-aux/lint-bin40
1 files changed, 40 insertions, 0 deletions
diff --git a/build-aux/lint-bin b/build-aux/lint-bin
index ffc2a12..0b955de 100755
--- a/build-aux/lint-bin
+++ b/build-aux/lint-bin
@@ -18,6 +18,15 @@ shopt -s extglob
# Textual info:
# - ${elf%.elf}.dis : `objdump --section-headers ${elf}; objdump --disassemble ${elf}; picotool coprodis --quiet ${elf}`
# - ${elf}.map : `ld --print-map` info
+# - ${elf%.elf}_stack.c : `stack.c.gen`
+
+RED=$(tput setaf 1)
+RESET=$(tput sgr0)
+
+err() {
+ printf "${RED}%s${RESET}: %s\n" "$1" "$2" >&2
+ #r=1
+}
# Input is `ld --print-map` format.
#
@@ -27,6 +36,14 @@ objdump_globals() {
sed -E -n '/^ \.t?(data|bss)\./{ / 0x/{ p; D; }; N; s/\n/ /; p; }' <"$1"
}
+readelf_funcs() {
+ local in_elffile
+ in_elffile=$1
+
+ readelf --syms --wide -- "$in_elffile" |
+ awk '$4 == "FUNC" { print $8 }'
+}
+
lint_globals() {
local in_mapfile
in_mapfile=$1
@@ -72,14 +89,37 @@ lint_globals() {
} | column -t
}
+lint_stack() {
+ local in_elffile
+ in_elffile=$1
+
+ IFS=''
+ while read -r line; do
+ func=${line#$'\t'}
+ if [[ $line == $'\t'* ]]; then
+ err "$in_elffile" "function in binary but not _stack.c: ${func}"
+ else
+ err "$in_elffile" "function in _stack.c but not binary: ${func}"
+ fi
+ done < <(
+ comm -3 \
+ <(sed -En 's/^included: (.*:)?//p' "${in_elffile%.elf}_stack.c" | sort -u) \
+ <(readelf_funcs "$in_elffile" | sed 's/\.part\.[0-9]*$//' | sort -u))
+}
+
main() {
+ r=0
+
local elf
for elf in "$@"; do
{
echo 'Global variables:'
lint_globals "${elf}.map" | sed 's/^/ /'
} > "${elf%.elf}.lint.globals"
+ lint_stack "$elf" &> "${elf%.elf}.lint.stack"
done
+
+ return $r
}
main "$@"