summaryrefslogtreecommitdiff
path: root/build-aux
diff options
context:
space:
mode:
Diffstat (limited to 'build-aux')
-rwxr-xr-xbuild-aux/lint-bin36
1 files changed, 29 insertions, 7 deletions
diff --git a/build-aux/lint-bin b/build-aux/lint-bin
index 2fe8e4b..ffc2a12 100755
--- a/build-aux/lint-bin
+++ b/build-aux/lint-bin
@@ -5,7 +5,22 @@
# SPDX-License-Identifier: AGPL-3.0-or-later
set -euE -o pipefail
+shopt -s extglob
+# There are several exisi files we can use:
+#
+# Binaries:
+# - ${elf} : firmware image with debug symbols and relocationd data
+# - ${elf%.elf}.bin : raw firmware image
+# - ${elf%.elf}.hex : .bin as Intel HEX
+# - ${elf%.elf}.uf2 : .bin as USB Flashing Format (UF2)
+#
+# Textual info:
+# - ${elf%.elf}.dis : `objdump --section-headers ${elf}; objdump --disassemble ${elf}; picotool coprodis --quiet ${elf}`
+# - ${elf}.map : `ld --print-map` info
+
+# Input is `ld --print-map` format.
+#
# Output is a series of lines in the format "symbol location size
# source". Whitespace may seem silly.
objdump_globals() {
@@ -30,7 +45,9 @@ lint_globals() {
cd "$rel_base"
total=0
while read -r symbol addr size source; do
- : "$addr"
+ if (( addr == 0 )); then
+ continue
+ fi
case "$source" in
/*)
# libg.a(whatever.o) -> libg.a
@@ -38,26 +55,31 @@ lint_globals() {
# resolve `..` components
source="$(realpath --canonicalize-missing --no-symlinks -- "$source")"
;;
- CMakeFiles/*.dir/*.obj)
+ CMakeFiles/*.dir/*.@(obj|o))
# CMakeFiles/sbc_harnes_objs.dir/...
source="${source#CMakeFiles/*.dir/}"
- source="${source%.obj}"
+ source="${source%.@(obj|o)}"
source="${source//__/..}"
source="$(realpath --canonicalize-missing --no-symlinks --relative-to="$topdir" -- "$source")"
;;
esac
- printf '%s %s 0x%04x\n' "$source" "$symbol" "$size"
+ printf "%s %s 0x%04x (%'d)\n" "$source" "$symbol" "$size" "$size"
total=$((total + size))
done
- printf '~ Total 0x%04x\n' "$total"
+ printf "~ Total 0x%04x (%'d)\n" "$total" "$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/^/ /'
+ local elf
+ for elf in "$@"; do
+ {
+ echo 'Global variables:'
+ lint_globals "${elf}.map" | sed 's/^/ /'
+ } > "${elf%.elf}.lint.globals"
+ done
}
main "$@"