summaryrefslogtreecommitdiff
path: root/build-aux
diff options
context:
space:
mode:
Diffstat (limited to 'build-aux')
-rwxr-xr-xbuild-aux/lint-bin63
1 files changed, 63 insertions, 0 deletions
diff --git a/build-aux/lint-bin b/build-aux/lint-bin
new file mode 100755
index 0000000..2fe8e4b
--- /dev/null
+++ b/build-aux/lint-bin
@@ -0,0 +1,63 @@
+#!/usr/bin/env bash
+# build-aux/lint-bin - Lint final binary images
+#
+# Copyright (C) 2025 Luke T. Shumaker <lukeshu@lukeshu.com>
+# SPDX-License-Identifier: AGPL-3.0-or-later
+
+set -euE -o pipefail
+
+# Output is a series of lines in the format "symbol location size
+# source". Whitespace may seem silly.
+objdump_globals() {
+ sed -E -n '/^ \.t?(data|bss)\./{ / 0x/{ p; D; }; N; s/\n/ /; p; }' <"$1"
+}
+
+lint_globals() {
+ local in_mapfile
+ in_mapfile=$1
+
+ local rel_base
+ rel_base=${in_mapfile#build/*/}
+ rel_base=${rel_base%/*}
+
+ local topdir
+ topdir=$PWD
+
+ {
+ echo 'Source Symbol Size'
+ objdump_globals "$in_mapfile" |
+ {
+ cd "$rel_base"
+ total=0
+ while read -r symbol addr size source; do
+ : "$addr"
+ case "$source" in
+ /*)
+ # libg.a(whatever.o) -> libg.a
+ source="${source%(*)}"
+ # resolve `..` components
+ source="$(realpath --canonicalize-missing --no-symlinks -- "$source")"
+ ;;
+ CMakeFiles/*.dir/*.obj)
+ # CMakeFiles/sbc_harnes_objs.dir/...
+ source="${source#CMakeFiles/*.dir/}"
+ source="${source%.obj}"
+ source="${source//__/..}"
+ source="$(realpath --canonicalize-missing --no-symlinks --relative-to="$topdir" -- "$source")"
+ ;;
+ esac
+ printf '%s %s 0x%04x\n' "$source" "$symbol" "$size"
+ total=$((total + size))
+ done
+ printf '~ Total 0x%04x\n' "$total"
+ } |
+ LC_COLLATE=C sort
+ } | column -t
+}
+
+main() {
+ echo 'Global variables:'
+ lint_globals 'build/rp2040-Release/cmd/sbc_harness/sbc_harness.elf.map' | sed 's/^/ /'
+}
+
+main "$@"