Implement support for printing stack backtraces on ARM64, make framepointer support configurable by the build system with CONFIG_FRAMEPOINTER and teach U-Boot to walk the framepointers and unwind the stack when an exception occurs. Also show all 64 bits of the exception syndrom register (ESR).
Additionally, a new global unwind_stack() function is added, this can be called from anywhere to print a backtrace which can be useful when debugging certain problems. It is now used during panic() when available to provide more useful information for debugging. A new printf format specifier is added: %pS will print a symbol name from an address, this is particularly useful for function pointers === Handling relocation === Since U-Boot relocates itself at runtime, and can be built to be position independent in the first place (effectively "relocating" itself when it first starts too), we can't really rely on gd->reloc_off. The approach taken here is to subtract CONFIG_TEXT_BASE from the address of each symbol in the lookup table (while it's being generated), then when decoding we just subtract the address of the _start label since it is always correct pre and post relocation. This allows us to avoid all the awkward maths since the symbols are always relative to 0x0 in the lookup table. Example output (CONFIG_TEXT_BASE is 0 in this case): "Synchronous Abort" handler, esr 0x0000000096000021, far 0x16dd3e2d3 elr: 0000000000028f64 lr : 00000000000344f0 (reloc) elr: 000000017dda1f64 lr : 000000017ddad4f0 x0 : 0000000000001011 x1 : 000000016dd3e2d3 x2 : 0000000000000001 x3 : 000000016dde7eb8 x4 : 000000017dda1f30 x5 : 000000016dde7ef0 x6 : 0000000000000064 x7 : 000000016dde9000 x8 : 00000000ffffffd8 x9 : 000000016dd3e238 x10: 000000000000000d x11: 0000000000000006 x12: 0000000000000001 x13: 000000016dd3d920 x14: 00000000fffffffd x15: 0000000000000002 x16: 000000017dda1f30 x17: 0000000000000000 x18: 000000016dd59c70 x19: 000000017de87788 x20: 0000000000000000 x21: 0000000000000000 x22: 000000016dde7eb0 x23: 0000000000000002 x24: 000000017de9addc x25: 0000000000000000 x26: 0000000000000000 x27: 0000000000000000 x28: 000000016dde7f10 x29: 000000016dd3e2d0 Code: a8c17bfd d65f03c0 910003e1 b2400421 (c8dffc20) Relocated base addr: 0x17dd79000 Backtrace: elr: <0x00000000028f64 R-> 0x0000017dda1f64> do_unaligned+0x34 lr: <0x000000000344f0 R-> 0x0000017ddad4f0> cmd_process+0x130 <0x0000000002b99c R-> 0x0000017dda499c> run_list_real+0x718 <0x0000000002bb28 R-> 0x0000017dda4b28> parse_stream_outer+0x14c <0x0000000002c06c R-> 0x0000017dda506c> parse_file_outer+0x34 <0x00000000033818 R-> 0x0000017ddac818> cli_loop+0x18 <0x00000000029084 R-> 0x0000017dda2084> main_loop+0x54 <0x0000000002cdec R-> 0x0000017dda5dec> board_init_r+0x3c8 <0x00000000003014 R-> 0x0000017dd7c014> relocation_return+0x4 Resetting CPU ... --- Changes in v3: - Reorder patches to try and avoid breaking bisects - Include pre/post relocation addresses for symbols - Print elr and lr in the exception case to capture the full callstack - Change print_sym to print the LR value rather than the symbol address - Make symaddr and offset optional in symbol_lookup() - Implement %pS format specifier and use it in backtrace print - Export unwind_stack() when CONFIG_FRAMEPOINTER enabled, call it from panic() - Link to v2: https://lore.kernel.org/r/20250725-b4-arm64-backtrace-symbols-v2-0-230a96650...@linaro.org Changes in v2: - Include calling function in backtrace (current LR) - Implement support for runtime symbol lookup - Use symbol lookup to print more informative backtraces when available - Adjust backtrace format and print U-Boot base address - Link to v1: https://lore.kernel.org/u-boot/20250703051951.43372-1-heinrich.schucha...@canonical.com To: Tom Rini <tr...@konsulko.com> To: Heinrich Schuchardt <heinrich.schucha...@canonical.com> Cc: Simon Glass <s...@chromium.org> Cc: Marek Vasut <marek.vasut+rene...@mailbox.org> Cc: Ben Dooks <ben.do...@codethink.co.uk> Cc: Rick Chen <r...@andestech.com> Cc: Leo <ycli...@andestech.com> Cc: Ilias Apalodimas <ilias.apalodi...@linaro.org> Cc: u-boot@lists.denx.de --- Casey Connolly (6): drop unused kallsyms support add support for symbol lookups lib: vsprintf: implement %pS format specifier arm64: implement printing backtraces with symbols lib: expose unwind_stack() and call it from panic() qcom_defconfig: enable framepointer for backtraces Heinrich Schuchardt (4): cmd/exception: missing include string.h arm64: initialize the frame pointer register Kconfig: make CONFIG_FRAMEPOINTER available on arm64 arm64: simplify interrupt code Kconfig | 26 ++ Makefile | 24 +- arch/arm/Makefile | 9 +- arch/arm/lib/crt0_64.S | 1 + arch/arm/lib/interrupts_64.c | 146 +++++++--- arch/riscv/Kconfig | 21 -- common/Makefile | 1 - common/kallsyms.c | 42 --- common/system_map.c | 8 - configs/qcom_defconfig | 1 + include/exception.h | 1 + include/symbols.h | 31 +++ lib/Kconfig | 8 + lib/panic.c | 7 + lib/symbols.c | 143 ++++++++++ lib/vsprintf.c | 25 ++ tools/Makefile | 3 + tools/symbols.c | 646 +++++++++++++++++++++++++++++++++++++++++++ 18 files changed, 1021 insertions(+), 122 deletions(-) --- base-commit: 182cb30084516c3085d2ca5dde3f105f7625d774 change-id: 20250725-b4-arm64-backtrace-symbols-af9579214288 Casey Connolly <casey.conno...@linaro.org>