Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] GDB: aarch64: Fix inferior function call if GCS is present but disabled
@ 2026-07-08  6:03 Thiago Jung Bauermann
  2026-07-08  7:50 ` Aktemur, Baris
  2026-07-19  8:57 ` Luis
  0 siblings, 2 replies; 8+ messages in thread
From: Thiago Jung Bauermann @ 2026-07-08  6:03 UTC (permalink / raw)
  To: gdb-patches; +Cc: Luis

On AArch64, even if the Guarded Control Stack feature is present on the
system the inferior may not have enabled it.

There's a bug in GDB's GCS support in that if the system supports GCS,
GDB will always push a GCS entry when doing an inferior function call
even if the inferior doesn't have it enabled.  This causes inferior
function calls to fail. E.g.:

  (gdb) p foo ()
  Can't write to Guarded Control Stack.

The error message is because the GCSPR doesn't point to a valid memory
address.

Fix by checking whether GCS is enabled in the inferior before trying to
push a GCS entry.

Regression tested on an aarch64-linux-gnu QEMU VM with GCS present.
---

GCS support first appeared in GDB 17, so if this patch is approved for
trunk is it ok to also commit it to the branch?

 gdb/aarch64-tdep.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/gdb/aarch64-tdep.c b/gdb/aarch64-tdep.c
index 886e7ce1e7b6..b4437dcccc8a 100644
--- a/gdb/aarch64-tdep.c
+++ b/gdb/aarch64-tdep.c
@@ -1934,7 +1934,11 @@ static void
 aarch64_shadow_stack_push (gdbarch *gdbarch, CORE_ADDR new_addr,
 			   regcache *regcache)
 {
-  aarch64_push_gcs_entry (regcache, new_addr);
+  bool gcs_is_enabled;
+
+  gdbarch_get_shadow_stack_pointer (gdbarch, regcache, gcs_is_enabled);
+  if (gcs_is_enabled)
+    aarch64_push_gcs_entry (regcache, new_addr);
 }
 
 /* Implement the "push_dummy_call" gdbarch method.  */

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-07-22 22:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-08  6:03 [PATCH] GDB: aarch64: Fix inferior function call if GCS is present but disabled Thiago Jung Bauermann
2026-07-08  7:50 ` Aktemur, Baris
2026-07-08 19:43   ` Thiago Jung Bauermann
2026-07-21 16:38   ` Tom Tromey
2026-07-22 20:23     ` Thiago Jung Bauermann
2026-07-22 22:27       ` Tom Tromey
2026-07-19  8:57 ` Luis
2026-07-22 19:59   ` Thiago Jung Bauermann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox