From 6fedfe71cfab86aecf4168ecf35961bf88ce0438 Mon Sep 17 00:00:00 2001 From: "Luke T. Shumaker" Date: Sat, 1 Mar 2025 14:53:58 -0700 Subject: lint-bin: (dry-run) lint that list of functions matches stack.c.gen --- build-aux/lint-bin | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'build-aux/lint-bin') 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 "$@" -- cgit v1.2.3-2-g168b