From: Nadav Amit <nadav.amit@gmail.com>
To: Andrew Jones <andrew.jones@linux.dev>
Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org,
Nikos Nikoleris <nikos.nikoleris@arm.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Thomas Huth <thuth@redhat.com>, Nadav Amit <namit@vmware.com>
Subject: [kvm-unit-tests PATCH v3 2/6] lib/stack: print base addresses on relocation setups
Date: Wed, 28 Jun 2023 00:13:51 +0000 [thread overview]
Message-ID: <20230628001356.2706-4-namit@vmware.com> (raw)
In-Reply-To: <20230628001356.2706-1-namit@vmware.com>
From: Nadav Amit <namit@vmware.com>
Making sense from dumped stacks when running EFI tests is very hard due
to the relocation. Fix it by adjusting the address back to the original
address.
Introduce CONFIG_RELOC, which would be set on arm64 and on EFI configs.
Suggested-by: Andrew Jones <andrew.jones@linux.dev>
Signed-off-by: Nadav Amit <namit@vmware.com>
---
v2->v3:
* Mark PowerPC as relocatable as well [Andrew]
* Fixing incorrect Makefile [Andrew]
v1->v2:
* Introduce CONFIG_RELOC to support ARM64 [Andrew]
---
Makefile | 2 +-
arm/Makefile.arm64 | 1 +
lib/stack.c | 31 +++++++++++++++++++++++++++++--
powerpc/Makefile.common | 1 +
4 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/Makefile b/Makefile
index 307bc29..ae79059 100644
--- a/Makefile
+++ b/Makefile
@@ -40,7 +40,7 @@ OBJDIRS += $(LIBFDT_objdir)
# EFI App
ifeq ($(CONFIG_EFI),y)
-EFI_CFLAGS := -DCONFIG_EFI
+EFI_CFLAGS := -DCONFIG_EFI -DCONFIG_RELOC
# The following CFLAGS and LDFLAGS come from:
# - GNU-EFI/Makefile.defaults
# - GNU-EFI/apps/Makefile
diff --git a/arm/Makefile.arm64 b/arm/Makefile.arm64
index eada7f9..85b3348 100644
--- a/arm/Makefile.arm64
+++ b/arm/Makefile.arm64
@@ -12,6 +12,7 @@ CFLAGS += -mstrict-align
mno_outline_atomics := $(call cc-option, -mno-outline-atomics, "")
CFLAGS += $(mno_outline_atomics)
+CFLAGS += -DCONFIG_RELOC
define arch_elf_check =
$(if $(shell ! $(READELF) -rW $(1) >&/dev/null && echo "nok"),
diff --git a/lib/stack.c b/lib/stack.c
index bdb23fd..dd6bfa8 100644
--- a/lib/stack.c
+++ b/lib/stack.c
@@ -6,13 +6,38 @@
*/
#include <libcflat.h>
+#include <stdbool.h>
#include <stack.h>
#define MAX_DEPTH 20
+#ifdef CONFIG_RELOC
+extern char _text, _etext;
+
+static bool base_address(const void *rebased_addr, unsigned long *addr)
+{
+ unsigned long ra = (unsigned long)rebased_addr;
+ unsigned long start = (unsigned long)&_text;
+ unsigned long end = (unsigned long)&_etext;
+
+ if (ra < start || ra >= end)
+ return false;
+
+ *addr = ra - start;
+ return true;
+}
+#else
+static bool base_address(const void *rebased_addr, unsigned long *addr)
+{
+ *addr = (unsigned long)rebased_addr;
+ return true;
+}
+#endif
+
static void print_stack(const void **return_addrs, int depth,
bool top_is_return_address)
{
+ unsigned long addr;
int i = 0;
printf("\tSTACK:");
@@ -20,12 +45,14 @@ static void print_stack(const void **return_addrs, int depth,
/* @addr indicates a non-return address, as expected by the stack
* pretty printer script. */
if (depth > 0 && !top_is_return_address) {
- printf(" @%lx", (unsigned long) return_addrs[0]);
+ if (base_address(return_addrs[0], &addr))
+ printf(" @%lx", addr);
i++;
}
for (; i < depth; i++) {
- printf(" %lx", (unsigned long) return_addrs[i]);
+ if (base_address(return_addrs[i], &addr))
+ printf(" %lx", addr);
}
printf("\n");
}
diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common
index 8ce0034..c2e976e 100644
--- a/powerpc/Makefile.common
+++ b/powerpc/Makefile.common
@@ -24,6 +24,7 @@ CFLAGS += -ffreestanding
CFLAGS += -O2 -msoft-float -mno-altivec $(mabi_no_altivec)
CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib
CFLAGS += -Wa,-mregnames
+CFLAGS += -DCONFIG_RELOC
# We want to keep intermediate files
.PRECIOUS: %.o
--
2.34.1
next prev parent reply other threads:[~2023-06-28 0:14 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-28 0:13 [PATCH] .debug ignore - to squash with efi:keep efi Nadav Amit
2023-06-28 0:13 ` [kvm-unit-tests PATCH v3 0/6] arm64: improve debuggability Nadav Amit
2023-07-01 12:19 ` Andrew Jones
2023-06-28 0:13 ` [kvm-unit-tests PATCH v3 1/6] efi: keep efi debug information in a separate file Nadav Amit
2023-06-28 0:13 ` Nadav Amit [this message]
2023-07-01 11:34 ` [kvm-unit-tests PATCH v3 2/6] lib/stack: print base addresses on relocation setups Andrew Jones
2023-07-01 17:18 ` Nadav Amit
2023-06-28 0:13 ` [kvm-unit-tests PATCH v3 3/6] arm64: enable frame pointer and support stack unwinding Nadav Amit
2023-06-28 0:13 ` [kvm-unit-tests PATCH v3 4/6] arm64: stack: update trace stack on exception Nadav Amit
2023-06-28 0:13 ` [kvm-unit-tests PATCH v3 5/6] efi: print address of image Nadav Amit
2023-06-28 0:13 ` [kvm-unit-tests PATCH v3 6/6] arm64: dump stack on bad exception Nadav Amit
2023-06-28 8:19 ` [PATCH] .debug ignore - to squash with efi:keep efi Andrew Jones
2023-06-28 8:22 ` Andrew Jones
2023-06-28 17:30 ` Nadav Amit
2023-06-28 17:33 ` Nadav Amit
2023-06-29 7:43 ` Andrew Jones
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230628001356.2706-4-namit@vmware.com \
--to=nadav.amit@gmail.com \
--cc=andrew.jones@linux.dev \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=namit@vmware.com \
--cc=nikos.nikoleris@arm.com \
--cc=pbonzini@redhat.com \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox