Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
To: gdb-patches@sourceware.org
Cc: Luis <luis.machado.foss@gmail.com>
Subject: [PATCH] GDB: aarch64: Fix inferior function call if GCS is present but disabled
Date: Wed,  8 Jul 2026 03:03:31 -0300	[thread overview]
Message-ID: <20260708060331.347616-1-thiago.bauermann@linaro.org> (raw)

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.  */

             reply	other threads:[~2026-07-08  6:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-08  6:03 Thiago Jung Bauermann [this message]
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

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=20260708060331.347616-1-thiago.bauermann@linaro.org \
    --to=thiago.bauermann@linaro.org \
    --cc=gdb-patches@sourceware.org \
    --cc=luis.machado.foss@gmail.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