Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH v2 0/2] GDB: aarch64-linux: Some header fixes
@ 2026-02-14  4:54 Thiago Jung Bauermann
  2026-02-14  4:54 ` [PATCH v2 1/2] GDB: aarch64-linux: Reorganize gdb/arch/aarch64-gcs-linux.h Thiago Jung Bauermann
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Thiago Jung Bauermann @ 2026-02-14  4:54 UTC (permalink / raw)
  To: gdb-patches; +Cc: Chris Packham, Luis, Tom Tromey, Simon Marchi

Patch 2 fixes the problem that I set out to fix in v1¹.

Patch 1 grew out of Simon's patch review, where he noted that files in
gdb/arch/ shouldn't depend on arch-specific include files.

Thiago Jung Bauermann (2):
  GDB: aarch64-linux: Reorganize gdb/arch/aarch64-gcs-linux.h
  GDB: aarch64-linux: Fix build failure on musl systems

 gdb/Makefile.in                               |  2 +-
 gdb/aarch64-linux-nat.c                       |  4 +--
 gdb/aarch64-linux-tdep.c                      |  9 ++---
 gdb/aarch64-linux-tdep.h                      |  6 ++--
 .../{aarch64-gcs-linux.h => aarch64-linux.h}  | 30 ++++------------
 gdb/nat/aarch64-linux.h                       | 15 ++++++++
 gdbserver/linux-aarch64-low.cc                |  7 ++--
 gdbsupport/config.in                          |  3 ++
 gdbsupport/configure                          | 36 +++++++++++++++++++
 gdbsupport/configure.ac                       | 19 ++++++++++
 10 files changed, 93 insertions(+), 38 deletions(-)
 rename gdb/arch/{aarch64-gcs-linux.h => aarch64-linux.h} (61%)

¹ https://inbox.sourceware.org/gdb-patches/20260211045853.1436881-1-thiago.bauermann@linaro.org/

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

* [PATCH v2 1/2] GDB: aarch64-linux: Reorganize gdb/arch/aarch64-gcs-linux.h
  2026-02-14  4:54 [PATCH v2 0/2] GDB: aarch64-linux: Some header fixes Thiago Jung Bauermann
@ 2026-02-14  4:54 ` Thiago Jung Bauermann
  2026-02-14  9:38   ` Luis
  2026-02-14 14:29   ` Simon Marchi
  2026-02-14  4:54 ` [PATCH v2 2/2] GDB: aarch64-linux: Fix build failure on musl systems Thiago Jung Bauermann
  2026-02-14 14:30 ` [PATCH v2 0/2] GDB: aarch64-linux: Some header fixes Simon Marchi
  2 siblings, 2 replies; 10+ messages in thread
From: Thiago Jung Bauermann @ 2026-02-14  4:54 UTC (permalink / raw)
  To: gdb-patches; +Cc: Chris Packham, Luis, Tom Tromey, Simon Marchi

This file implicitly depends on aarch64-linux's <asm/sigcontext.h> for
the definition of GCS_MAGIC and on its <bits/hwcap.h> for the definition
of HWCAP_GCS, but files on gdb/arch/ shouldn't depend on include files
specific to the architecture.

Regarding GCS_MAGIC and struct user_gcs, move that code section to
gdb/nat/aarch64-linux.h which can rely on <asm/sigcontext.h> and
<asm/ptrace.h>.

To fix the use of struct user_gcs in gdb/aarch64-linuxt-dep.c, define a
macro with the size of the GCS regset in aarch64-linux-tdep.h and use it
in aarch64-linux-tdep.c, as is done for other regsets and following a
suggestion from Simon Marchi.

Regarding HWCAP_GCS, rename it to AARCH64_HWCAP_GCS to ensure that it
won't conflict with any system header definition and define it
unconditionally, following the example of AARCH64_HWCAP_PACA.

Renaming HWCAP_GCS also avoids a potential (and I would say unlikely)
problem on non-AArch64 systems: naming conflict if by coincidence they have
an unrelated hardware capability bit also named HWCAP_GCS.

Finally, I noticed that AARCH64_HWCAP_PACA is duplicated in GDB and
gdbserver files, so consolidate them in the same header and rename it to
gdb/arch/aarch64-linux.h since it isn't just about GCS anymore.
---

As I mentioned on v1's email thread, this patch opens a small can of worms,
since other gdb/arch/aarch64*.h do the same kind of thing (mostly with
HWCAP macros but also a few others).

Perhaps I'm going too far with the HWCAP_GCS renaming and the current
handling of it is fine?

 gdb/Makefile.in                               |  2 +-
 gdb/aarch64-linux-nat.c                       |  4 +--
 gdb/aarch64-linux-tdep.c                      |  9 +++---
 gdb/aarch64-linux-tdep.h                      |  6 ++--
 .../{aarch64-gcs-linux.h => aarch64-linux.h}  | 30 +++++--------------
 gdb/nat/aarch64-linux.h                       | 16 ++++++++++
 gdbserver/linux-aarch64-low.cc                |  7 ++---
 7 files changed, 36 insertions(+), 38 deletions(-)
 rename gdb/arch/{aarch64-gcs-linux.h => aarch64-linux.h} (61%)

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 2aa95be968ac..fd47c613966a 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1301,7 +1301,7 @@ HFILES_NO_SRCDIR = \
 	amdgpu-tdep.h \
 	annotate.h \
 	arch/aarch32.h \
-	arch/aarch64-gcs-linux.h \
+	arch/aarch64-linux.h \
 	arch/aarch64.h \
 	arch/aarch64-insn.h \
 	arch/aarch64-mte.h \
diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
index 028de981588b..b2dd192a7b56 100644
--- a/gdb/aarch64-linux-nat.c
+++ b/gdb/aarch64-linux-nat.c
@@ -51,7 +51,7 @@
 #include "gdb_proc_service.h"
 #include "arch-utils.h"
 
-#include "arch/aarch64-gcs-linux.h"
+#include "arch/aarch64-linux.h"
 #include "arch/aarch64-mte-linux.h"
 
 #include "nat/aarch64-mte-linux-ptrace.h"
@@ -1013,7 +1013,7 @@ aarch64_linux_nat_target::read_description ()
      active or not.  */
   features.vq = aarch64_sve_get_vq (tid);
   features.pauth = hwcap & AARCH64_HWCAP_PACA;
-  features.gcs = features.gcs_linux = hwcap & HWCAP_GCS;
+  features.gcs = features.gcs_linux = hwcap & AARCH64_HWCAP_GCS;
   features.mte = hwcap2 & HWCAP2_MTE;
   features.tls = aarch64_tls_register_count (tid);
   /* SME feature check.  */
diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c
index b85c25ecae1d..33e1b411ff1d 100644
--- a/gdb/aarch64-linux-tdep.c
+++ b/gdb/aarch64-linux-tdep.c
@@ -51,7 +51,7 @@
 #include "record-full.h"
 #include "linux-record.h"
 
-#include "arch/aarch64-gcs-linux.h"
+#include "arch/aarch64-linux.h"
 #include "arch/aarch64-mte.h"
 #include "arch/aarch64-mte-linux.h"
 #include "arch/aarch64-scalable-linux.h"
@@ -1734,8 +1734,9 @@ aarch64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
 	  gcs_regmap, regcache_supply_regset, regcache_collect_regset
 	};
 
-      cb (".reg-aarch-gcs", sizeof (user_gcs), sizeof (user_gcs),
-	  &aarch64_linux_gcs_regset, "GCS registers", cb_data);
+      cb (".reg-aarch-gcs", AARCH64_LINUX_SIZEOF_GCS_REGSET,
+	  AARCH64_LINUX_SIZEOF_GCS_REGSET, &aarch64_linux_gcs_regset,
+	  "GCS registers", cb_data);
     }
 }
 
@@ -1761,7 +1762,7 @@ aarch64_linux_core_read_description (struct gdbarch *gdbarch,
      length.  */
   features.vq = aarch64_linux_core_read_vq_from_sections (gdbarch, abfd);
   features.pauth = hwcap & AARCH64_HWCAP_PACA;
-  features.gcs = features.gcs_linux = hwcap & HWCAP_GCS;
+  features.gcs = features.gcs_linux = hwcap & AARCH64_HWCAP_GCS;
   features.mte = hwcap2 & HWCAP2_MTE;
   features.fpmr = hwcap2 & HWCAP2_FPMR;
 
diff --git a/gdb/aarch64-linux-tdep.h b/gdb/aarch64-linux-tdep.h
index e926687ff6eb..f247d6aa72cd 100644
--- a/gdb/aarch64-linux-tdep.h
+++ b/gdb/aarch64-linux-tdep.h
@@ -39,10 +39,10 @@
 /* The MTE regset consists of a 64-bit register.  */
 #define AARCH64_LINUX_SIZEOF_MTE_REGSET (8)
 
+/* The GCS regset consists of 3 64-bit registers.  */
+#define AARCH64_LINUX_SIZEOF_GCS_REGSET (3 * 8)
+
 extern const struct regset aarch64_linux_gregset;
 extern const struct regset aarch64_linux_fpregset;
 
-/* Matches HWCAP_PACA in kernel header arch/arm64/include/uapi/asm/hwcap.h.  */
-#define AARCH64_HWCAP_PACA (1 << 30)
-
 #endif /* GDB_AARCH64_LINUX_TDEP_H */
diff --git a/gdb/arch/aarch64-gcs-linux.h b/gdb/arch/aarch64-linux.h
similarity index 61%
rename from gdb/arch/aarch64-gcs-linux.h
rename to gdb/arch/aarch64-linux.h
index b31fc32daa03..a33c082a0318 100644
--- a/gdb/arch/aarch64-gcs-linux.h
+++ b/gdb/arch/aarch64-linux.h
@@ -1,4 +1,4 @@
-/* Common Linux target-dependent definitions for AArch64 GCS
+/* Common Linux target-dependent definitions for AArch64 running Linux.
 
    Copyright (C) 2025-2026 Free Software Foundation, Inc.
 
@@ -17,28 +17,12 @@
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
-#ifndef GDB_ARCH_AARCH64_GCS_LINUX_H
-#define GDB_ARCH_AARCH64_GCS_LINUX_H
-
-#include <stdint.h>
+#ifndef GDB_ARCH_AARCH64_LINUX_H
+#define GDB_ARCH_AARCH64_LINUX_H
 
+/* Matches HWCAP_PACA in kernel header arch/arm64/include/uapi/asm/hwcap.h.  */
+#define AARCH64_HWCAP_PACA (1 << 30)
 /* Feature check for Guarded Control Stack.  */
-#ifndef HWCAP_GCS
-#define HWCAP_GCS (1ULL << 32)
-#endif
-
-/* Make sure we only define these if the kernel header doesn't.  */
-#ifndef GCS_MAGIC
-
-/* GCS state (NT_ARM_GCS).  */
-
-struct user_gcs
-{
-  uint64_t features_enabled;
-  uint64_t features_locked;
-  uint64_t gcspr_el0;
-};
-
-#endif /* GCS_MAGIC */
+#define AARCH64_HWCAP_GCS (1ULL << 32)
 
-#endif /* GDB_ARCH_AARCH64_GCS_LINUX_H */
+#endif /* GDB_ARCH_AARCH64_LINUX_H */
diff --git a/gdb/nat/aarch64-linux.h b/gdb/nat/aarch64-linux.h
index bb5381eba3ef..f7c09aa112bf 100644
--- a/gdb/nat/aarch64-linux.h
+++ b/gdb/nat/aarch64-linux.h
@@ -19,7 +19,9 @@
 #ifndef GDB_NAT_AARCH64_LINUX_H
 #define GDB_NAT_AARCH64_LINUX_H
 
+#include <stdint.h>
 #include <signal.h>
+#include <asm/ptrace.h>
 
 /* Defines ps_err_e, struct ps_prochandle.  */
 #include "gdb_proc_service.h"
@@ -113,6 +115,20 @@ typedef struct compat_siginfo
 #define cpt_si_band _sifields._sigpoll._band
 #define cpt_si_fd _sifields._sigpoll._fd
 
+/* Make sure we only define these if the kernel header doesn't.  */
+#ifndef GCS_MAGIC
+
+/* GCS state (NT_ARM_GCS).  */
+
+struct user_gcs
+{
+  uint64_t features_enabled;
+  uint64_t features_locked;
+  uint64_t gcspr_el0;
+};
+
+#endif /* GCS_MAGIC */
+
 void aarch64_siginfo_from_compat_siginfo (siginfo_t *to,
 					    compat_siginfo_t *from);
 void aarch64_compat_siginfo_from_siginfo (compat_siginfo_t *to,
diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc
index b19e605f55d6..60ea50f609cc 100644
--- a/gdbserver/linux-aarch64-low.cc
+++ b/gdbserver/linux-aarch64-low.cc
@@ -39,7 +39,7 @@
 
 #include "gdb_proc_service.h"
 #include "arch/aarch64.h"
-#include "arch/aarch64-gcs-linux.h"
+#include "arch/aarch64-linux.h"
 #include "arch/aarch64-mte-linux.h"
 #include "arch/aarch64-scalable-linux.h"
 #include "linux-aarch32-tdesc.h"
@@ -984,9 +984,6 @@ aarch64_adjust_register_sets (const struct aarch64_features &features)
     }
 }
 
-/* Matches HWCAP_PACA in kernel header arch/arm64/include/uapi/asm/hwcap.h.  */
-#define AARCH64_HWCAP_PACA (1 << 30)
-
 /* Implementation of linux target ops method "low_arch_setup".  */
 
 void
@@ -1009,7 +1006,7 @@ aarch64_target::low_arch_setup ()
       /* A-profile MTE is 64-bit only.  */
       features.mte = linux_get_hwcap2 (pid, 8) & HWCAP2_MTE;
       features.tls = aarch64_tls_register_count (tid);
-      features.gcs = features.gcs_linux = linux_get_hwcap (pid, 8) & HWCAP_GCS;
+      features.gcs = features.gcs_linux = linux_get_hwcap (pid, 8) & AARCH64_HWCAP_GCS;
       features.fpmr = linux_get_hwcap2 (pid, 8) & HWCAP2_FPMR;
 
       /* Scalable Matrix Extension feature and size check.  */

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

* [PATCH v2 2/2] GDB: aarch64-linux: Fix build failure on musl systems
  2026-02-14  4:54 [PATCH v2 0/2] GDB: aarch64-linux: Some header fixes Thiago Jung Bauermann
  2026-02-14  4:54 ` [PATCH v2 1/2] GDB: aarch64-linux: Reorganize gdb/arch/aarch64-gcs-linux.h Thiago Jung Bauermann
@ 2026-02-14  4:54 ` Thiago Jung Bauermann
  2026-02-14 14:30 ` [PATCH v2 0/2] GDB: aarch64-linux: Some header fixes Simon Marchi
  2 siblings, 0 replies; 10+ messages in thread
From: Thiago Jung Bauermann @ 2026-02-14  4:54 UTC (permalink / raw)
  To: gdb-patches; +Cc: Chris Packham, Luis, Tom Tromey, Simon Marchi

When building against musl (e.g. on Alpine Linux), the following error
happens:

    CXX    linux-aarch64-low.o
  In file included from /home/bauermann/src/binutils-gdb/gdbserver/linux-aarch64-low.cc:23:
  /home/bauermann/src/binutils-gdb/gdbserver/../gdb/nat/aarch64-linux.h:123:8: error: redefinition of 'struct user_gcs'
    123 | struct user_gcs
        |        ^~~~~~~~
  In file included from /home/bauermann/src/binutils-gdb/gdbserver/../gdb/nat/aarch64-linux.h:24:
  /usr/include/asm/ptrace.h:329:8: note: previous definition of 'struct user_gcs'
    329 | struct user_gcs {
        |        ^~~~~~~~
  make[2]: *** [Makefile:565: linux-aarch64-low.o] Error 1

aarch64-linux-tdep.c fails to build in the same way.  This happens
because aarch64-linux.h uses GCS_MAGIC to see whether the system
headers have GCS-related definitions.  The problem is that GCS_MAGIC is
defined in <asm/sigcontext.h> while struct gcs_user is defined in
<asm/ptrace.h>.  It's fine on glibc systems because in the set of system
headers that linux-aarch64-low.cc and aarch64-linux-tdep.c include,
<asm/sigcontext.h> ends up being included implicitly as well.  This
doesn't happen when using musl's headers though.

There isn't a macro in <asm/ptrace.h> whose presence is correlated with
the presence of the struct user_gcs definition, so a configure check is
needed to detect it and conditionally define the struct.

Note that there's another build issue with musl, described in
PR gdb/33747 affecting compilation of gdb/ser-unix.c.  In order to be
able to test this patch, I applied the patch in comment 11 there.

Tested with a native build on an Alpine Linux aarch64 system, and also
verified that all gdb.arch/aarch64-gcs*.exp tests pass on it.

Co-authored-by: Chris Packham <judge.packham@gmail.com>
---
 gdb/nat/aarch64-linux.h |  5 ++---
 gdbsupport/config.in    |  3 +++
 gdbsupport/configure    | 36 ++++++++++++++++++++++++++++++++++++
 gdbsupport/configure.ac | 19 +++++++++++++++++++
 4 files changed, 60 insertions(+), 3 deletions(-)

diff --git a/gdb/nat/aarch64-linux.h b/gdb/nat/aarch64-linux.h
index f7c09aa112bf..0f1fa093d003 100644
--- a/gdb/nat/aarch64-linux.h
+++ b/gdb/nat/aarch64-linux.h
@@ -115,8 +115,7 @@ typedef struct compat_siginfo
 #define cpt_si_band _sifields._sigpoll._band
 #define cpt_si_fd _sifields._sigpoll._fd
 
-/* Make sure we only define these if the kernel header doesn't.  */
-#ifndef GCS_MAGIC
+#ifndef HAVE_STRUCT_USER_GCS
 
 /* GCS state (NT_ARM_GCS).  */
 
@@ -127,7 +126,7 @@ struct user_gcs
   uint64_t gcspr_el0;
 };
 
-#endif /* GCS_MAGIC */
+#endif /* HAVE_STRUCT_USER_GCS */
 
 void aarch64_siginfo_from_compat_siginfo (siginfo_t *to,
 					    compat_siginfo_t *from);
diff --git a/gdbsupport/config.in b/gdbsupport/config.in
index 0beacf22c057..2957ee0f0301 100644
--- a/gdbsupport/config.in
+++ b/gdbsupport/config.in
@@ -271,6 +271,9 @@
 /* Define to 1 if `st_blocks' is a member of `struct stat'. */
 #undef HAVE_STRUCT_STAT_ST_BLOCKS
 
+/* Define to 1 if your system has struct user_gcs. */
+#undef HAVE_STRUCT_USER_GCS
+
 /* Define to 1 if you have the <sys/param.h> header file. */
 #undef HAVE_SYS_PARAM_H
 
diff --git a/gdbsupport/configure b/gdbsupport/configure
index 05ad00f48c4f..584a80ef8255 100755
--- a/gdbsupport/configure
+++ b/gdbsupport/configure
@@ -14307,6 +14307,42 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 
 
+# Check for `struct user_gcs`
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for struct user_gcs" >&5
+$as_echo_n "checking for struct user_gcs... " >&6; }
+if ${gdb_cv_struct_user_gcs+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+#include <sys/ptrace.h>
+	 #include <asm/ptrace.h>
+int
+main ()
+{
+struct user_gcs u;
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  gdb_cv_struct_user_gcs=yes
+else
+  gdb_cv_struct_user_gcs=no
+
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gdb_cv_struct_user_gcs" >&5
+$as_echo "$gdb_cv_struct_user_gcs" >&6; }
+if test "$gdb_cv_struct_user_gcs" = yes; then
+
+$as_echo "#define HAVE_STRUCT_USER_GCS 1" >>confdefs.h
+
+fi
+
 # Set the 'development' global.
 . $srcdir/../bfd/development.sh
 
diff --git a/gdbsupport/configure.ac b/gdbsupport/configure.ac
index 5491b8f3f10a..6c06832f0913 100644
--- a/gdbsupport/configure.ac
+++ b/gdbsupport/configure.ac
@@ -68,6 +68,25 @@ GDB_AC_PTRACE
 AM_GDB_COMPILER_TYPE
 AM_GDB_WARNINGS
 
+# Check for `struct user_gcs`
+AC_CACHE_CHECK(
+  [for struct user_gcs],
+  [gdb_cv_struct_user_gcs],
+  [AC_COMPILE_IFELSE(
+     [AC_LANG_PROGRAM(
+	[#include <sys/ptrace.h>
+	 #include <asm/ptrace.h>],
+	[struct user_gcs u;]
+      )],
+     [gdb_cv_struct_user_gcs=yes],
+     [gdb_cv_struct_user_gcs=no]
+  )]
+)
+if test "$gdb_cv_struct_user_gcs" = yes; then
+  AC_DEFINE(HAVE_STRUCT_USER_GCS, 1,
+	    [Define to 1 if your system has struct user_gcs.])
+fi
+
 # Set the 'development' global.
 . $srcdir/../bfd/development.sh
 

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

* Re: [PATCH v2 1/2] GDB: aarch64-linux: Reorganize gdb/arch/aarch64-gcs-linux.h
  2026-02-14  4:54 ` [PATCH v2 1/2] GDB: aarch64-linux: Reorganize gdb/arch/aarch64-gcs-linux.h Thiago Jung Bauermann
@ 2026-02-14  9:38   ` Luis
  2026-02-17  5:21     ` Thiago Jung Bauermann
  2026-02-14 14:29   ` Simon Marchi
  1 sibling, 1 reply; 10+ messages in thread
From: Luis @ 2026-02-14  9:38 UTC (permalink / raw)
  To: Thiago Jung Bauermann, gdb-patches
  Cc: Chris Packham, Tom Tromey, Simon Marchi

Hi,

First, aarch64's code could really use a refactoring in terms of 
cleaning up the headers and splitting things into their own files. With 
that said, we don´t need to do that now, but would be nice to do it 
eventually.

On 14/02/2026 04:54, Thiago Jung Bauermann wrote:
> This file implicitly depends on aarch64-linux's <asm/sigcontext.h> for
> the definition of GCS_MAGIC and on its <bits/hwcap.h> for the definition
> of HWCAP_GCS, but files on gdb/arch/ shouldn't depend on include files
> specific to the architecture.
> 
> Regarding GCS_MAGIC and struct user_gcs, move that code section to
> gdb/nat/aarch64-linux.h which can rely on <asm/sigcontext.h> and
> <asm/ptrace.h>.
> 
> To fix the use of struct user_gcs in gdb/aarch64-linuxt-dep.c, define a
> macro with the size of the GCS regset in aarch64-linux-tdep.h and use it
> in aarch64-linux-tdep.c, as is done for other regsets and following a
> suggestion from Simon Marchi.
> 
> Regarding HWCAP_GCS, rename it to AARCH64_HWCAP_GCS to ensure that it
> won't conflict with any system header definition and define it
> unconditionally, following the example of AARCH64_HWCAP_PACA.
> 
> Renaming HWCAP_GCS also avoids a potential (and I would say unlikely)
> problem on non-AArch64 systems: naming conflict if by coincidence they have
> an unrelated hardware capability bit also named HWCAP_GCS.
> 
> Finally, I noticed that AARCH64_HWCAP_PACA is duplicated in GDB and
> gdbserver files, so consolidate them in the same header and rename it to
> gdb/arch/aarch64-linux.h since it isn't just about GCS anymore.
> ---
> 
> As I mentioned on v1's email thread, this patch opens a small can of worms,
> since other gdb/arch/aarch64*.h do the same kind of thing (mostly with
> HWCAP macros but also a few others).
> 
> Perhaps I'm going too far with the HWCAP_GCS renaming and the current
> handling of it is fine?
> 
>   gdb/Makefile.in                               |  2 +-
>   gdb/aarch64-linux-nat.c                       |  4 +--
>   gdb/aarch64-linux-tdep.c                      |  9 +++---
>   gdb/aarch64-linux-tdep.h                      |  6 ++--
>   .../{aarch64-gcs-linux.h => aarch64-linux.h}  | 30 +++++--------------
>   gdb/nat/aarch64-linux.h                       | 16 ++++++++++
>   gdbserver/linux-aarch64-low.cc                |  7 ++---
>   7 files changed, 36 insertions(+), 38 deletions(-)
>   rename gdb/arch/{aarch64-gcs-linux.h => aarch64-linux.h} (61%)
> 
> diff --git a/gdb/Makefile.in b/gdb/Makefile.in
> index 2aa95be968ac..fd47c613966a 100644
> --- a/gdb/Makefile.in
> +++ b/gdb/Makefile.in
> @@ -1301,7 +1301,7 @@ HFILES_NO_SRCDIR = \
>   	amdgpu-tdep.h \
>   	annotate.h \
>   	arch/aarch32.h \
> -	arch/aarch64-gcs-linux.h \
> +	arch/aarch64-linux.h \

If there is anything feature-specific about things in aarch64-linux.h, 
I´d rather have a new featute-specific file here.

>   	arch/aarch64.h \
>   	arch/aarch64-insn.h \
>   	arch/aarch64-mte.h \
> diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
> index 028de981588b..b2dd192a7b56 100644
> --- a/gdb/aarch64-linux-nat.c
> +++ b/gdb/aarch64-linux-nat.c
> @@ -51,7 +51,7 @@
>   #include "gdb_proc_service.h"
>   #include "arch-utils.h"
>   
> -#include "arch/aarch64-gcs-linux.h"
> +#include "arch/aarch64-linux.h"

Likewise above.

>   #include "arch/aarch64-mte-linux.h"
>   
>   #include "nat/aarch64-mte-linux-ptrace.h"
> @@ -1013,7 +1013,7 @@ aarch64_linux_nat_target::read_description ()
>        active or not.  */
>     features.vq = aarch64_sve_get_vq (tid);
>     features.pauth = hwcap & AARCH64_HWCAP_PACA;
> -  features.gcs = features.gcs_linux = hwcap & HWCAP_GCS;
> +  features.gcs = features.gcs_linux = hwcap & AARCH64_HWCAP_GCS;
>     features.mte = hwcap2 & HWCAP2_MTE;
>     features.tls = aarch64_tls_register_count (tid);
>     /* SME feature check.  */
> diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c
> index b85c25ecae1d..33e1b411ff1d 100644
> --- a/gdb/aarch64-linux-tdep.c
> +++ b/gdb/aarch64-linux-tdep.c
> @@ -51,7 +51,7 @@
>   #include "record-full.h"
>   #include "linux-record.h"
>   
> -#include "arch/aarch64-gcs-linux.h"
> +#include "arch/aarch64-linux.h"

Likewise here.

 >   #include "arch/aarch64-mte.h">   #include "arch/aarch64-mte-linux.h"
>   #include "arch/aarch64-scalable-linux.h"
> @@ -1734,8 +1734,9 @@ aarch64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
>   	  gcs_regmap, regcache_supply_regset, regcache_collect_regset
>   	};
>   
> -      cb (".reg-aarch-gcs", sizeof (user_gcs), sizeof (user_gcs),
> -	  &aarch64_linux_gcs_regset, "GCS registers", cb_data);
> +      cb (".reg-aarch-gcs", AARCH64_LINUX_SIZEOF_GCS_REGSET,
> +	  AARCH64_LINUX_SIZEOF_GCS_REGSET, &aarch64_linux_gcs_regset,
> +	  "GCS registers", cb_data);
>       }
>   }
>   
> @@ -1761,7 +1762,7 @@ aarch64_linux_core_read_description (struct gdbarch *gdbarch,
>        length.  */
>     features.vq = aarch64_linux_core_read_vq_from_sections (gdbarch, abfd);
>     features.pauth = hwcap & AARCH64_HWCAP_PACA;
> -  features.gcs = features.gcs_linux = hwcap & HWCAP_GCS;
> +  features.gcs = features.gcs_linux = hwcap & AARCH64_HWCAP_GCS;
>     features.mte = hwcap2 & HWCAP2_MTE;
>     features.fpmr = hwcap2 & HWCAP2_FPMR;
>   
> diff --git a/gdb/aarch64-linux-tdep.h b/gdb/aarch64-linux-tdep.h
> index e926687ff6eb..f247d6aa72cd 100644
> --- a/gdb/aarch64-linux-tdep.h
> +++ b/gdb/aarch64-linux-tdep.h
> @@ -39,10 +39,10 @@
>   /* The MTE regset consists of a 64-bit register.  */
>   #define AARCH64_LINUX_SIZEOF_MTE_REGSET (8)
>   
> +/* The GCS regset consists of 3 64-bit registers.  */
> +#define AARCH64_LINUX_SIZEOF_GCS_REGSET (3 * 8)
> +

The above is the kind of feature-specific data we should put into 
arch/aarch64-linux-<feature>.[c|h]. At the moment not all of it follows 
this particular pattern, and that's annoying. But we should strive to 
clean it up.

>   extern const struct regset aarch64_linux_gregset;
>   extern const struct regset aarch64_linux_fpregset;
>   
> -/* Matches HWCAP_PACA in kernel header arch/arm64/include/uapi/asm/hwcap.h.  */
> -#define AARCH64_HWCAP_PACA (1 << 30)
> -

The above is older code, and that bit is likely available out there. We 
should do the same treatment to it as the others. That is, if it is not 
defined, define it. Otherwise use whatever is defined.

>   #endif /* GDB_AARCH64_LINUX_TDEP_H */
> diff --git a/gdb/arch/aarch64-gcs-linux.h b/gdb/arch/aarch64-linux.h
> similarity index 61%
> rename from gdb/arch/aarch64-gcs-linux.h
> rename to gdb/arch/aarch64-linux.h
> index b31fc32daa03..a33c082a0318 100644
> --- a/gdb/arch/aarch64-gcs-linux.h
> +++ b/gdb/arch/aarch64-linux.h
> @@ -1,4 +1,4 @@
> -/* Common Linux target-dependent definitions for AArch64 GCS
> +/* Common Linux target-dependent definitions for AArch64 running Linux.
 >   >      Copyright (C) 2025-2026 Free Software Foundation, Inc.
>   
> @@ -17,28 +17,12 @@
>      You should have received a copy of the GNU General Public License
>      along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
>   
> -#ifndef GDB_ARCH_AARCH64_GCS_LINUX_H
> -#define GDB_ARCH_AARCH64_GCS_LINUX_H
> -
> -#include <stdint.h>
> +#ifndef GDB_ARCH_AARCH64_LINUX_H
> +#define GDB_ARCH_AARCH64_LINUX_H
>   
> +/* Matches HWCAP_PACA in kernel header arch/arm64/include/uapi/asm/hwcap.h.  */
> +#define AARCH64_HWCAP_PACA (1 << 30)

We should either move all of the definitions to arch/aarch64-linux.h or 
move them to their own separate feature files. See mte/sve/sme for instance.

>   /* Feature check for Guarded Control Stack.  */
> -#ifndef HWCAP_GCS
> -#define HWCAP_GCS (1ULL << 32)
> -#endif
> -
> -/* Make sure we only define these if the kernel header doesn't.  */
> -#ifndef GCS_MAGIC
> -
> -/* GCS state (NT_ARM_GCS).  */
> -
> -struct user_gcs
> -{
> -  uint64_t features_enabled;
> -  uint64_t features_locked;
> -  uint64_t gcspr_el0;
> -};
> -
> -#endif /* GCS_MAGIC */
> +#define AARCH64_HWCAP_GCS (1ULL << 32)
>   
> -#endif /* GDB_ARCH_AARCH64_GCS_LINUX_H */
> +#endif /* GDB_ARCH_AARCH64_LINUX_H */
> diff --git a/gdb/nat/aarch64-linux.h b/gdb/nat/aarch64-linux.h
> index bb5381eba3ef..f7c09aa112bf 100644
> --- a/gdb/nat/aarch64-linux.h
> +++ b/gdb/nat/aarch64-linux.h
> @@ -19,7 +19,9 @@
>   #ifndef GDB_NAT_AARCH64_LINUX_H
>   #define GDB_NAT_AARCH64_LINUX_H
>   
> +#include <stdint.h>
>   #include <signal.h>
> +#include <asm/ptrace.h>
>   
>   /* Defines ps_err_e, struct ps_prochandle.  */
>   #include "gdb_proc_service.h"
> @@ -113,6 +115,20 @@ typedef struct compat_siginfo
>   #define cpt_si_band _sifields._sigpoll._band
>   #define cpt_si_fd _sifields._sigpoll._fd
>   
> +/* Make sure we only define these if the kernel header doesn't.  */
> +#ifndef GCS_MAGIC
> +
> +/* GCS state (NT_ARM_GCS).  */
> +
> +struct user_gcs
> +{
> +  uint64_t features_enabled;
> +  uint64_t features_locked;
> +  uint64_t gcspr_el0;
> +};
> +
> +#endif /* GCS_MAGIC */
> +

To keep things clean I´d define the above in a separare file for the 
feature. See gdb/nat/aarch64-mte-linux-ptrace.[h|c] for instance.


>   void aarch64_siginfo_from_compat_siginfo (siginfo_t *to,
>   					    compat_siginfo_t *from);
>   void aarch64_compat_siginfo_from_siginfo (compat_siginfo_t *to,
> diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc
> index b19e605f55d6..60ea50f609cc 100644
> --- a/gdbserver/linux-aarch64-low.cc
> +++ b/gdbserver/linux-aarch64-low.cc
> @@ -39,7 +39,7 @@
>   
>   #include "gdb_proc_service.h"
>   #include "arch/aarch64.h"
> -#include "arch/aarch64-gcs-linux.h"
> +#include "arch/aarch64-linux.h"

See the comment below about having per-feature files. I think having 
per-feature files is less work at this point.

>   #include "arch/aarch64-mte-linux.h"
>   #include "arch/aarch64-scalable-linux.h"
>   #include "linux-aarch32-tdesc.h"
> @@ -984,9 +984,6 @@ aarch64_adjust_register_sets (const struct aarch64_features &features)
>       }
>   }
>   
> -/* Matches HWCAP_PACA in kernel header arch/arm64/include/uapi/asm/hwcap.h.  */
> -#define AARCH64_HWCAP_PACA (1 << 30)
> -
>   /* Implementation of linux target ops method "low_arch_setup".  */
>   
>   void
> @@ -1009,7 +1006,7 @@ aarch64_target::low_arch_setup ()
>         /* A-profile MTE is 64-bit only.  */
>         features.mte = linux_get_hwcap2 (pid, 8) & HWCAP2_MTE;
>         features.tls = aarch64_tls_register_count (tid);
> -      features.gcs = features.gcs_linux = linux_get_hwcap (pid, 8) & HWCAP_GCS;
> +      features.gcs = features.gcs_linux = linux_get_hwcap (pid, 8) & AARCH64_HWCAP_GCS;
>         features.fpmr = linux_get_hwcap2 (pid, 8) & HWCAP2_FPMR;
>   
>         /* Scalable Matrix Extension feature and size check.  */

Checking arch/aarch64.h, HWCAP2_FPMR looks out of place as well. So 
yeah, overall these files need a bit of a cleanup.

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

* Re: [PATCH v2 1/2] GDB: aarch64-linux: Reorganize gdb/arch/aarch64-gcs-linux.h
  2026-02-14  4:54 ` [PATCH v2 1/2] GDB: aarch64-linux: Reorganize gdb/arch/aarch64-gcs-linux.h Thiago Jung Bauermann
  2026-02-14  9:38   ` Luis
@ 2026-02-14 14:29   ` Simon Marchi
  2026-02-17  5:10     ` Thiago Jung Bauermann
  1 sibling, 1 reply; 10+ messages in thread
From: Simon Marchi @ 2026-02-14 14:29 UTC (permalink / raw)
  To: Thiago Jung Bauermann, gdb-patches; +Cc: Chris Packham, Luis, Tom Tromey

> diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
> index 028de981588b..b2dd192a7b56 100644
> --- a/gdb/aarch64-linux-nat.c
> +++ b/gdb/aarch64-linux-nat.c
> @@ -51,7 +51,7 @@
>  #include "gdb_proc_service.h"
>  #include "arch-utils.h"
>  
> -#include "arch/aarch64-gcs-linux.h"
> +#include "arch/aarch64-linux.h"
>  #include "arch/aarch64-mte-linux.h"
>  
>  #include "nat/aarch64-mte-linux-ptrace.h"
> @@ -1013,7 +1013,7 @@ aarch64_linux_nat_target::read_description ()
>       active or not.  */
>    features.vq = aarch64_sve_get_vq (tid);
>    features.pauth = hwcap & AARCH64_HWCAP_PACA;
> -  features.gcs = features.gcs_linux = hwcap & HWCAP_GCS;

This one could stay HWCAP_GCS, but I don't have a preference.

If we want to ensure / prove they are the same, we could add asserts
like this in the nat/ header:

  static_assert (AARCH64_HWCAP_GCS == HWCAP_GCS);

That assert would only be checked when compiling natively for an aarch64
system (where HWCAP_GCS is available), but it's better than nothing.

Simon

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

* Re: [PATCH v2 0/2] GDB: aarch64-linux: Some header fixes
  2026-02-14  4:54 [PATCH v2 0/2] GDB: aarch64-linux: Some header fixes Thiago Jung Bauermann
  2026-02-14  4:54 ` [PATCH v2 1/2] GDB: aarch64-linux: Reorganize gdb/arch/aarch64-gcs-linux.h Thiago Jung Bauermann
  2026-02-14  4:54 ` [PATCH v2 2/2] GDB: aarch64-linux: Fix build failure on musl systems Thiago Jung Bauermann
@ 2026-02-14 14:30 ` Simon Marchi
  2026-02-17  5:11   ` Thiago Jung Bauermann
  2 siblings, 1 reply; 10+ messages in thread
From: Simon Marchi @ 2026-02-14 14:30 UTC (permalink / raw)
  To: Thiago Jung Bauermann, gdb-patches; +Cc: Chris Packham, Luis, Tom Tromey



On 2026-02-13 23:54, Thiago Jung Bauermann wrote:
> Patch 2 fixes the problem that I set out to fix in v1¹.
> 
> Patch 1 grew out of Simon's patch review, where he noted that files in
> gdb/arch/ shouldn't depend on arch-specific include files.
> 
> Thiago Jung Bauermann (2):
>   GDB: aarch64-linux: Reorganize gdb/arch/aarch64-gcs-linux.h
>   GDB: aarch64-linux: Fix build failure on musl systems
> 
>  gdb/Makefile.in                               |  2 +-
>  gdb/aarch64-linux-nat.c                       |  4 +--
>  gdb/aarch64-linux-tdep.c                      |  9 ++---
>  gdb/aarch64-linux-tdep.h                      |  6 ++--
>  .../{aarch64-gcs-linux.h => aarch64-linux.h}  | 30 ++++------------
>  gdb/nat/aarch64-linux.h                       | 15 ++++++++
>  gdbserver/linux-aarch64-low.cc                |  7 ++--
>  gdbsupport/config.in                          |  3 ++
>  gdbsupport/configure                          | 36 +++++++++++++++++++
>  gdbsupport/configure.ac                       | 19 ++++++++++
>  10 files changed, 93 insertions(+), 38 deletions(-)
>  rename gdb/arch/{aarch64-gcs-linux.h => aarch64-linux.h} (61%)
> 
> ¹ https://inbox.sourceware.org/gdb-patches/20260211045853.1436881-1-thiago.bauermann@linaro.org/

From my point of view, these changes are going the right direction, but
I will let Luis handle the review and approval.

Simon

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

* Re: [PATCH v2 1/2] GDB: aarch64-linux: Reorganize gdb/arch/aarch64-gcs-linux.h
  2026-02-14 14:29   ` Simon Marchi
@ 2026-02-17  5:10     ` Thiago Jung Bauermann
  2026-02-17 15:35       ` Simon Marchi
  0 siblings, 1 reply; 10+ messages in thread
From: Thiago Jung Bauermann @ 2026-02-17  5:10 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches, Chris Packham, Luis, Tom Tromey

Simon Marchi <simark@simark.ca> writes:

>> diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
>> index 028de981588b..b2dd192a7b56 100644
>> --- a/gdb/aarch64-linux-nat.c
>> +++ b/gdb/aarch64-linux-nat.c
>> @@ -51,7 +51,7 @@
>>  #include "gdb_proc_service.h"
>>  #include "arch-utils.h"
>>  
>> -#include "arch/aarch64-gcs-linux.h"
>> +#include "arch/aarch64-linux.h"
>>  #include "arch/aarch64-mte-linux.h"
>>  
>>  #include "nat/aarch64-mte-linux-ptrace.h"
>> @@ -1013,7 +1013,7 @@ aarch64_linux_nat_target::read_description ()
>>       active or not.  */
>>    features.vq = aarch64_sve_get_vq (tid);
>>    features.pauth = hwcap & AARCH64_HWCAP_PACA;
>> -  features.gcs = features.gcs_linux = hwcap & HWCAP_GCS;
>
> This one could stay HWCAP_GCS, but I don't have a preference.

Luis prefers keeping it as HWCAP_GCS (and also renaming
AARCH64_HWCAP_PACA to HWCAP_PACA), so that's what I'm doing for v3.

> If we want to ensure / prove they are the same, we could add asserts
> like this in the nat/ header:
>
>   static_assert (AARCH64_HWCAP_GCS == HWCAP_GCS);
>
> That assert would only be checked when compiling natively for an aarch64
> system (where HWCAP_GCS is available), but it's better than nothing.

I mentioned this concern mostly for completeness, TBH. IMO it's not
worth adding this assert unless we're actually bitten by this problem
(which AFAIK hasn't happened yet).

-- 
Thiago

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

* Re: [PATCH v2 0/2] GDB: aarch64-linux: Some header fixes
  2026-02-14 14:30 ` [PATCH v2 0/2] GDB: aarch64-linux: Some header fixes Simon Marchi
@ 2026-02-17  5:11   ` Thiago Jung Bauermann
  0 siblings, 0 replies; 10+ messages in thread
From: Thiago Jung Bauermann @ 2026-02-17  5:11 UTC (permalink / raw)
  To: Simon Marchi; +Cc: gdb-patches, Chris Packham, Luis, Tom Tromey

Simon Marchi <simark@simark.ca> writes:

> On 2026-02-13 23:54, Thiago Jung Bauermann wrote:
>> Patch 2 fixes the problem that I set out to fix in v1¹.
>> 
>> Patch 1 grew out of Simon's patch review, where he noted that files in
>> gdb/arch/ shouldn't depend on arch-specific include files.
>> 
>> Thiago Jung Bauermann (2):
>>   GDB: aarch64-linux: Reorganize gdb/arch/aarch64-gcs-linux.h
>>   GDB: aarch64-linux: Fix build failure on musl systems
>> 
>>  gdb/Makefile.in                               |  2 +-
>>  gdb/aarch64-linux-nat.c                       |  4 +--
>>  gdb/aarch64-linux-tdep.c                      |  9 ++---
>>  gdb/aarch64-linux-tdep.h                      |  6 ++--
>>  .../{aarch64-gcs-linux.h => aarch64-linux.h}  | 30 ++++------------
>>  gdb/nat/aarch64-linux.h                       | 15 ++++++++
>>  gdbserver/linux-aarch64-low.cc                |  7 ++--
>>  gdbsupport/config.in                          |  3 ++
>>  gdbsupport/configure                          | 36 +++++++++++++++++++
>>  gdbsupport/configure.ac                       | 19 ++++++++++
>>  10 files changed, 93 insertions(+), 38 deletions(-)
>>  rename gdb/arch/{aarch64-gcs-linux.h => aarch64-linux.h} (61%)
>> 
>> ¹ https://inbox.sourceware.org/gdb-patches/20260211045853.1436881-1-thiago.bauermann@linaro.org/
>
> From my point of view, these changes are going the right direction, but
> I will let Luis handle the review and approval.

Nice. Thank you for your review!

-- 
Thiago

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

* Re: [PATCH v2 1/2] GDB: aarch64-linux: Reorganize gdb/arch/aarch64-gcs-linux.h
  2026-02-14  9:38   ` Luis
@ 2026-02-17  5:21     ` Thiago Jung Bauermann
  0 siblings, 0 replies; 10+ messages in thread
From: Thiago Jung Bauermann @ 2026-02-17  5:21 UTC (permalink / raw)
  To: Luis; +Cc: gdb-patches, Chris Packham, Tom Tromey, Simon Marchi

Hello,

Luis <luis.machado.foss@gmail.com> writes:

> Hi,
>
> First, aarch64's code could really use a refactoring in terms of cleaning up the headers
> and splitting things into their own files. With that said, we don´t need to do that now,
> but would be nice to do it eventually.

Ok. I cleaned up the things you pointed out in this review, at least.

> On 14/02/2026 04:54, Thiago Jung Bauermann wrote:
>> This file implicitly depends on aarch64-linux's <asm/sigcontext.h> for
>> the definition of GCS_MAGIC and on its <bits/hwcap.h> for the definition
>> of HWCAP_GCS, but files on gdb/arch/ shouldn't depend on include files
>> specific to the architecture.
>> Regarding GCS_MAGIC and struct user_gcs, move that code section to
>> gdb/nat/aarch64-linux.h which can rely on <asm/sigcontext.h> and
>> <asm/ptrace.h>.
>> To fix the use of struct user_gcs in gdb/aarch64-linuxt-dep.c, define a
>> macro with the size of the GCS regset in aarch64-linux-tdep.h and use it
>> in aarch64-linux-tdep.c, as is done for other regsets and following a
>> suggestion from Simon Marchi.
>> Regarding HWCAP_GCS, rename it to AARCH64_HWCAP_GCS to ensure that it
>> won't conflict with any system header definition and define it
>> unconditionally, following the example of AARCH64_HWCAP_PACA.
>> Renaming HWCAP_GCS also avoids a potential (and I would say unlikely)
>> problem on non-AArch64 systems: naming conflict if by coincidence they have
>> an unrelated hardware capability bit also named HWCAP_GCS.
>> Finally, I noticed that AARCH64_HWCAP_PACA is duplicated in GDB and
>> gdbserver files, so consolidate them in the same header and rename it to
>> gdb/arch/aarch64-linux.h since it isn't just about GCS anymore.
>> ---
>> As I mentioned on v1's email thread, this patch opens a small can of worms,
>> since other gdb/arch/aarch64*.h do the same kind of thing (mostly with
>> HWCAP macros but also a few others).
>> Perhaps I'm going too far with the HWCAP_GCS renaming and the current
>> handling of it is fine?
>>   gdb/Makefile.in                               |  2 +-
>>   gdb/aarch64-linux-nat.c                       |  4 +--
>>   gdb/aarch64-linux-tdep.c                      |  9 +++---
>>   gdb/aarch64-linux-tdep.h                      |  6 ++--
>>   .../{aarch64-gcs-linux.h => aarch64-linux.h}  | 30 +++++--------------
>>   gdb/nat/aarch64-linux.h                       | 16 ++++++++++
>>   gdbserver/linux-aarch64-low.cc                |  7 ++---
>>   7 files changed, 36 insertions(+), 38 deletions(-)
>>   rename gdb/arch/{aarch64-gcs-linux.h => aarch64-linux.h} (61%)
>> diff --git a/gdb/Makefile.in b/gdb/Makefile.in
>> index 2aa95be968ac..fd47c613966a 100644
>> --- a/gdb/Makefile.in
>> +++ b/gdb/Makefile.in
>> @@ -1301,7 +1301,7 @@ HFILES_NO_SRCDIR = \
>>   	amdgpu-tdep.h \
>>   	annotate.h \
>>   	arch/aarch32.h \
>> -	arch/aarch64-gcs-linux.h \
>> +	arch/aarch64-linux.h \
>
> If there is anything feature-specific about things in aarch64-linux.h, I´d rather have a
> new featute-specific file here.

Ok. For v3 I kept arch/aarch64-gcs-linux.h and there's no
arch/aarch64-linux.h anymore.

>>   	arch/aarch64.h \
>>   	arch/aarch64-insn.h \
>>   	arch/aarch64-mte.h \
>> diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
>> index 028de981588b..b2dd192a7b56 100644
>> --- a/gdb/aarch64-linux-nat.c
>> +++ b/gdb/aarch64-linux-nat.c
>> @@ -51,7 +51,7 @@
>>   #include "gdb_proc_service.h"
>>   #include "arch-utils.h"
>>   -#include "arch/aarch64-gcs-linux.h"
>> +#include "arch/aarch64-linux.h"
>
> Likewise above.
>
>>   #include "arch/aarch64-mte-linux.h"
>>     #include "nat/aarch64-mte-linux-ptrace.h"
>> @@ -1013,7 +1013,7 @@ aarch64_linux_nat_target::read_description ()
>>        active or not.  */
>>     features.vq = aarch64_sve_get_vq (tid);
>>     features.pauth = hwcap & AARCH64_HWCAP_PACA;
>> -  features.gcs = features.gcs_linux = hwcap & HWCAP_GCS;
>> +  features.gcs = features.gcs_linux = hwcap & AARCH64_HWCAP_GCS;
>>     features.mte = hwcap2 & HWCAP2_MTE;
>>     features.tls = aarch64_tls_register_count (tid);
>>     /* SME feature check.  */
>> diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c
>> index b85c25ecae1d..33e1b411ff1d 100644
>> --- a/gdb/aarch64-linux-tdep.c
>> +++ b/gdb/aarch64-linux-tdep.c
>> @@ -51,7 +51,7 @@
>>   #include "record-full.h"
>>   #include "linux-record.h"
>>   -#include "arch/aarch64-gcs-linux.h"
>> +#include "arch/aarch64-linux.h"
>
> Likewise here.
>
>>   #include "arch/aarch64-mte.h">   #include "arch/aarch64-mte-linux.h"
>>   #include "arch/aarch64-scalable-linux.h"
>> @@ -1734,8 +1734,9 @@ aarch64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
>>   	  gcs_regmap, regcache_supply_regset, regcache_collect_regset
>>   	};
>>   -      cb (".reg-aarch-gcs", sizeof (user_gcs), sizeof (user_gcs),
>> -	  &aarch64_linux_gcs_regset, "GCS registers", cb_data);
>> +      cb (".reg-aarch-gcs", AARCH64_LINUX_SIZEOF_GCS_REGSET,
>> +	  AARCH64_LINUX_SIZEOF_GCS_REGSET, &aarch64_linux_gcs_regset,
>> +	  "GCS registers", cb_data);
>>       }
>>   }
>>   @@ -1761,7 +1762,7 @@ aarch64_linux_core_read_description (struct gdbarch *gdbarch,
>>        length.  */
>>     features.vq = aarch64_linux_core_read_vq_from_sections (gdbarch, abfd);
>>     features.pauth = hwcap & AARCH64_HWCAP_PACA;
>> -  features.gcs = features.gcs_linux = hwcap & HWCAP_GCS;
>> +  features.gcs = features.gcs_linux = hwcap & AARCH64_HWCAP_GCS;
>>     features.mte = hwcap2 & HWCAP2_MTE;
>>     features.fpmr = hwcap2 & HWCAP2_FPMR;
>>   diff --git a/gdb/aarch64-linux-tdep.h b/gdb/aarch64-linux-tdep.h
>> index e926687ff6eb..f247d6aa72cd 100644
>> --- a/gdb/aarch64-linux-tdep.h
>> +++ b/gdb/aarch64-linux-tdep.h
>> @@ -39,10 +39,10 @@
>>   /* The MTE regset consists of a 64-bit register.  */
>>   #define AARCH64_LINUX_SIZEOF_MTE_REGSET (8)
>>   +/* The GCS regset consists of 3 64-bit registers.  */
>> +#define AARCH64_LINUX_SIZEOF_GCS_REGSET (3 * 8)
>> +
>
> The above is the kind of feature-specific data we should put into
> arch/aarch64-linux-<feature>.[c|h]. At the moment not all of it follows this particular
> pattern, and that's annoying. But we should strive to clean it up.

Ok, in v3 I moved this constant to gdb/arch/aarch64-gcs-linux.h.

>>   extern const struct regset aarch64_linux_gregset;
>>   extern const struct regset aarch64_linux_fpregset;
>>   -/* Matches HWCAP_PACA in kernel header arch/arm64/include/uapi/asm/hwcap.h.  */
>> -#define AARCH64_HWCAP_PACA (1 << 30)
>> -
>
> The above is older code, and that bit is likely available out there. We should do the same
> treatment to it as the others. That is, if it is not defined, define it. Otherwise use
> whatever is defined.

Ok. In v3 I added a patch renaming this to HWCAP_PACA and moving it to
gdb/arch/aarch64-pauth-linux.h.

>>   #endif /* GDB_AARCH64_LINUX_TDEP_H */
>> diff --git a/gdb/arch/aarch64-gcs-linux.h b/gdb/arch/aarch64-linux.h
>> similarity index 61%
>> rename from gdb/arch/aarch64-gcs-linux.h
>> rename to gdb/arch/aarch64-linux.h
>> index b31fc32daa03..a33c082a0318 100644
>> --- a/gdb/arch/aarch64-gcs-linux.h
>> +++ b/gdb/arch/aarch64-linux.h
>> @@ -1,4 +1,4 @@
>> -/* Common Linux target-dependent definitions for AArch64 GCS
>> +/* Common Linux target-dependent definitions for AArch64 running Linux.
>>   >      Copyright (C) 2025-2026 Free Software Foundation, Inc.
>>   @@ -17,28 +17,12 @@
>>      You should have received a copy of the GNU General Public License
>>      along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
>>   -#ifndef GDB_ARCH_AARCH64_GCS_LINUX_H
>> -#define GDB_ARCH_AARCH64_GCS_LINUX_H
>> -
>> -#include <stdint.h>
>> +#ifndef GDB_ARCH_AARCH64_LINUX_H
>> +#define GDB_ARCH_AARCH64_LINUX_H
>>   +/* Matches HWCAP_PACA in kernel header arch/arm64/include/uapi/asm/hwcap.h.  */
>> +#define AARCH64_HWCAP_PACA (1 << 30)
>
> We should either move all of the definitions to arch/aarch64-linux.h or move them to their
> own separate feature files. See mte/sve/sme for instance.

I chose the separate feature files option, as you suggested below.

>>   /* Feature check for Guarded Control Stack.  */
>> -#ifndef HWCAP_GCS
>> -#define HWCAP_GCS (1ULL << 32)
>> -#endif
>> -
>> -/* Make sure we only define these if the kernel header doesn't.  */
>> -#ifndef GCS_MAGIC
>> -
>> -/* GCS state (NT_ARM_GCS).  */
>> -
>> -struct user_gcs
>> -{
>> -  uint64_t features_enabled;
>> -  uint64_t features_locked;
>> -  uint64_t gcspr_el0;
>> -};
>> -
>> -#endif /* GCS_MAGIC */
>> +#define AARCH64_HWCAP_GCS (1ULL << 32)
>>   -#endif /* GDB_ARCH_AARCH64_GCS_LINUX_H */
>> +#endif /* GDB_ARCH_AARCH64_LINUX_H */
>> diff --git a/gdb/nat/aarch64-linux.h b/gdb/nat/aarch64-linux.h
>> index bb5381eba3ef..f7c09aa112bf 100644
>> --- a/gdb/nat/aarch64-linux.h
>> +++ b/gdb/nat/aarch64-linux.h
>> @@ -19,7 +19,9 @@
>>   #ifndef GDB_NAT_AARCH64_LINUX_H
>>   #define GDB_NAT_AARCH64_LINUX_H
>>   +#include <stdint.h>
>>   #include <signal.h>
>> +#include <asm/ptrace.h>
>>     /* Defines ps_err_e, struct ps_prochandle.  */
>>   #include "gdb_proc_service.h"
>> @@ -113,6 +115,20 @@ typedef struct compat_siginfo
>>   #define cpt_si_band _sifields._sigpoll._band
>>   #define cpt_si_fd _sifields._sigpoll._fd
>>   +/* Make sure we only define these if the kernel header doesn't.  */
>> +#ifndef GCS_MAGIC
>> +
>> +/* GCS state (NT_ARM_GCS).  */
>> +
>> +struct user_gcs
>> +{
>> +  uint64_t features_enabled;
>> +  uint64_t features_locked;
>> +  uint64_t gcspr_el0;
>> +};
>> +
>> +#endif /* GCS_MAGIC */
>> +
>
> To keep things clean I´d define the above in a separare file for the feature. See
> gdb/nat/aarch64-mte-linux-ptrace.[h|c] for instance.

Ok. In v3 I created gdb/nat/aarch64-gcs-linux-ptrace.h and moved the
struct user_gcs definition to it.

>>   void aarch64_siginfo_from_compat_siginfo (siginfo_t *to,
>>   					    compat_siginfo_t *from);
>>   void aarch64_compat_siginfo_from_siginfo (compat_siginfo_t *to,
>> diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc
>> index b19e605f55d6..60ea50f609cc 100644
>> --- a/gdbserver/linux-aarch64-low.cc
>> +++ b/gdbserver/linux-aarch64-low.cc
>> @@ -39,7 +39,7 @@
>>     #include "gdb_proc_service.h"
>>   #include "arch/aarch64.h"
>> -#include "arch/aarch64-gcs-linux.h"
>> +#include "arch/aarch64-linux.h"
>
> See the comment below about having per-feature files. I think having per-feature files is
> less work at this point.

Agreed.

>>   #include "arch/aarch64-mte-linux.h"
>>   #include "arch/aarch64-scalable-linux.h"
>>   #include "linux-aarch32-tdesc.h"
>> @@ -984,9 +984,6 @@ aarch64_adjust_register_sets (const struct aarch64_features &features)
>>       }
>>   }
>>   -/* Matches HWCAP_PACA in kernel header arch/arm64/include/uapi/asm/hwcap.h.  */
>> -#define AARCH64_HWCAP_PACA (1 << 30)
>> -
>>   /* Implementation of linux target ops method "low_arch_setup".  */
>>     void
>> @@ -1009,7 +1006,7 @@ aarch64_target::low_arch_setup ()
>>         /* A-profile MTE is 64-bit only.  */
>>         features.mte = linux_get_hwcap2 (pid, 8) & HWCAP2_MTE;
>>         features.tls = aarch64_tls_register_count (tid);
>> -      features.gcs = features.gcs_linux = linux_get_hwcap (pid, 8) & HWCAP_GCS;
>> +      features.gcs = features.gcs_linux = linux_get_hwcap (pid, 8) & AARCH64_HWCAP_GCS;
>>         features.fpmr = linux_get_hwcap2 (pid, 8) & HWCAP2_FPMR;
>>           /* Scalable Matrix Extension feature and size check.  */
>
> Checking arch/aarch64.h, HWCAP2_FPMR looks out of place as well. So yeah, overall these
> files need a bit of a cleanup.

Ok. In v3 I added a patch moving it to gdb/arch/aarch64-fpmr-linux.h.

-- 
Thiago

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

* Re: [PATCH v2 1/2] GDB: aarch64-linux: Reorganize gdb/arch/aarch64-gcs-linux.h
  2026-02-17  5:10     ` Thiago Jung Bauermann
@ 2026-02-17 15:35       ` Simon Marchi
  0 siblings, 0 replies; 10+ messages in thread
From: Simon Marchi @ 2026-02-17 15:35 UTC (permalink / raw)
  To: Thiago Jung Bauermann; +Cc: gdb-patches, Chris Packham, Luis, Tom Tromey



On 2026-02-17 00:10, Thiago Jung Bauermann wrote:
> Simon Marchi <simark@simark.ca> writes:
> 
>>> diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
>>> index 028de981588b..b2dd192a7b56 100644
>>> --- a/gdb/aarch64-linux-nat.c
>>> +++ b/gdb/aarch64-linux-nat.c
>>> @@ -51,7 +51,7 @@
>>>  #include "gdb_proc_service.h"
>>>  #include "arch-utils.h"
>>>  
>>> -#include "arch/aarch64-gcs-linux.h"
>>> +#include "arch/aarch64-linux.h"
>>>  #include "arch/aarch64-mte-linux.h"
>>>  
>>>  #include "nat/aarch64-mte-linux-ptrace.h"
>>> @@ -1013,7 +1013,7 @@ aarch64_linux_nat_target::read_description ()
>>>       active or not.  */
>>>    features.vq = aarch64_sve_get_vq (tid);
>>>    features.pauth = hwcap & AARCH64_HWCAP_PACA;
>>> -  features.gcs = features.gcs_linux = hwcap & HWCAP_GCS;
>>
>> This one could stay HWCAP_GCS, but I don't have a preference.
> 
> Luis prefers keeping it as HWCAP_GCS (and also renaming
> AARCH64_HWCAP_PACA to HWCAP_PACA), so that's what I'm doing for v3.
> 
>> If we want to ensure / prove they are the same, we could add asserts
>> like this in the nat/ header:
>>
>>   static_assert (AARCH64_HWCAP_GCS == HWCAP_GCS);
>>
>> That assert would only be checked when compiling natively for an aarch64
>> system (where HWCAP_GCS is available), but it's better than nothing.
> 
> I mentioned this concern mostly for completeness, TBH. IMO it's not
> worth adding this assert unless we're actually bitten by this problem
> (which AFAIK hasn't happened yet).

I wouldn't expect it to really catch mistakes, it would be more for
self-documentation.

Simon

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

end of thread, other threads:[~2026-02-17 15:35 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-14  4:54 [PATCH v2 0/2] GDB: aarch64-linux: Some header fixes Thiago Jung Bauermann
2026-02-14  4:54 ` [PATCH v2 1/2] GDB: aarch64-linux: Reorganize gdb/arch/aarch64-gcs-linux.h Thiago Jung Bauermann
2026-02-14  9:38   ` Luis
2026-02-17  5:21     ` Thiago Jung Bauermann
2026-02-14 14:29   ` Simon Marchi
2026-02-17  5:10     ` Thiago Jung Bauermann
2026-02-17 15:35       ` Simon Marchi
2026-02-14  4:54 ` [PATCH v2 2/2] GDB: aarch64-linux: Fix build failure on musl systems Thiago Jung Bauermann
2026-02-14 14:30 ` [PATCH v2 0/2] GDB: aarch64-linux: Some header fixes Simon Marchi
2026-02-17  5:11   ` 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