]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
GDB: aarch64: Fix inferior function call if GCS is present but disabled
authorThiago Jung Bauermann <thiago.bauermann@linaro.org>
Wed, 8 Jul 2026 17:48:54 +0000 (14:48 -0300)
committerThiago Jung Bauermann <thiago.bauermann@linaro.org>
Wed, 22 Jul 2026 19:34:48 +0000 (16:34 -0300)
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.

Approved-By: Luis Machado <luis.machado.foss@gmail.com>
gdb/aarch64-tdep.c

index a84da1fd59eb94ee792a633b8aeb371091dc7bca..950ad4f6aaeb592161a3ccc1da8f469b762d0ad2 100644 (file)
@@ -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;
+
+  (void) 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.  */