Skip to content

ARM64: add symbol name lookup and print a backtrace on exception

Caleb Connolly u-boot 2 versions – New

Get series with b4
b4 am [email protected] change-id 20240710-arm64-backtrace-2926f764dbdc

Versions newest first

  1. v2 Latest3 patches 0 repliesNew
  2. v1 RFC3 patches 6 repliesSuperseded

Changes in v2 from the cover letter

- Remove unused last_fp pointer
- Apply Tom's suggestions (cleanup hunks, don't guard unwind_stack()).
- Link to v1: https://lore.kernel.org/r/[email protected]

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3drop unused kallsyms supportMakefile common/Makefile common/kallsyms.c +1 more+0 -630 replies
2/3add support for symbol lookupsMakefile include/symbols.h lib/Kconfig +3 more+816 -10 replies
3/3arm64: unwind stack on exceptionarch/arm/include/asm/ptrace.h arch/arm/lib/interrupts_64.c+77 -00 replies

Reviews trailers per patch

1 of 3 patches has a Reviewed-by or Acked-by.

PatchTom RiniIlias Apalodimas
1/3R-b R-b
2/3
3/3

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/3] ARM64: add symbol name lookup and print a backtrace on exception

U-Boot already emits frame pointers on ARM64, but lacks the code to parse them, as well as a mechanism for looking up symbol names at runtime.

There was some (seemingly?) leftover code for symbols lookups in common/kallsyms.c and associated parts in the makefile, however it appears to be entirely unused and unsupported. It relied on generating one long string of all symbol addresses and names.

The approach taken here is instead largely based on the implementation in the Xen hypervisor, it performs basic compression using non-ASCII bytes to tokenize repeated string segments which can later be expanded back out at runtime.

This is then utilized in the ARM64 interrupt handling routine to dump a backtrace in the show_regs() debug function. As well as providing a general purpose unwind_stack() function which can be used for debugging.

== 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 this label address is updated to make U-Boot position independent and during relocation, it allows us to avoid re-implementing the relocation state handling stuff in the symbol decoder.

== Size ==

By default this feature is off, and will not effect the size of U-Boot binaries. The generated symbols object file is ~85k with the (fairly hefty) qcom_defconfig, so there is certainly a cost to be taken into account.

I hope that this implementation can be later extended for other platforms. However this is currently beyond my (skill, time) capabilities.

---
Changes in v2:
- Remove unused last_fp pointer
- Apply Tom's suggestions (cleanup hunks, don't guard unwind_stack()).
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Caleb Connolly (3):
drop unused kallsyms support
add support for symbol lookups
arm64: unwind stack on exception

 Makefile                      |  24 +-
 arch/arm/include/asm/ptrace.h |   2 +
 arch/arm/lib/interrupts_64.c  |  75 +++++
 common/Makefile               |   1 -
 common/kallsyms.c             |  43 ---
 common/system_map.c           |   8 -
 include/symbols.h             |  19 ++
 lib/Kconfig                   |   8 +
 lib/symbols.c                 | 126 ++++++++
 tools/Makefile                |   3 +
 tools/symbols.c               | 646 ++++++++++++++++++++++++++++++++++++++++++
 11 files changed, 892 insertions(+), 63 deletions(-)

---
change-id: 20240710-arm64-backtrace-2926f764dbdc
base-commit: 13f9c5668411aa18ef64846d5bc86e9e6be52082

// Caleb (they/them)