[kvm-unit-tests PATCH v2 3/4] arm64: Better backtraces for leaf functions

Mathias Krause
2025-09-15T21:54:56Z

Similar to x86 before, ARM64 skips the stack frame setup for leaf
functions, making backtraces miss frames.

Fortunately, gcc supports forcing generating stack frames for these via
-mno-omit-leaf-frame-pointer.

Signed-off-by: Mathias Krause <minipli@grsecurity.net>
---
arm/Makefile.arm64 | 6 ++++++
1 file changed, 6 insertions(+)

diff --git a/arm/Makefile.arm64 b/arm/Makefile.arm64
index bf7ea2a36d3a..a40c830df20f 100644
--- a/arm/Makefile.arm64
+++ b/arm/Makefile.arm64
@@ -67,5 +67,11 @@ tests += $(TEST_DIR)/mte.$(exe)

include $(SRCDIR)/$(TEST_DIR)/Makefile.common

+ifneq ($(KEEP_FRAME_POINTER),)
+# Force the generation of a regular stack frame even for leaf functions to make
+# stack walking reliable.
+LATE_CFLAGS += $(call cc-option, -mno-omit-leaf-frame-pointer, "")
+endif
+
arch_clean: arm_clean
$(RM) lib/arm64/.*.d
--
2.47.3