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: Chris Packham <judge.packham@gmail.com>,
	Luis <luis.machado.foss@gmail.com>, Tom Tromey <tom@tromey.com>,
	Simon Marchi <simark@simark.ca>
Subject: [PATCH v3 3/4] GDB: aarch64-linux: Move definition of struct user_gcs
Date: Tue, 17 Feb 2026 03:01:01 -0300	[thread overview]
Message-ID: <20260217060106.1906312-4-thiago.bauermann@linaro.org> (raw)
In-Reply-To: <20260217060106.1906312-1-thiago.bauermann@linaro.org>

Only native code should use struct user_gcs, so its definition should be
in a native-specific file and not in a file under gdb/arch/.

To fix this problem, create gdb/nat/aarch64-gcs-linux-ptrace.h and move
the struct user_gcs definition to it, as suggested by Luis.

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 gdb/arch/aarch64-gcs-linux.h
and use it in aarch64-linux-tdep.c, as is done for other regsets and
following a suggestion from Simon Marchi.

Suggested-by: Luis <luis.machado.foss@gmail.com>
Suggested-by: Simon Marchi <simark@simark.ca>
---
Changes since v2:
- Don't rename gdb/arch/aarch64-gcs-linux.h to gdb/arch/aarch64-linux.h,
  as suggested by Luis.
- Create gdb/nat/aarch64-gcs-linux-ptrace.h to contain definition of
  struct user_gcs, as suggested by Luis.
- Don't rename HWCAP_GCS to AARCH64_HWCAP_GCS, as suggested by Luis.
- Move definition of AARCH64_LINUX_SIZEOF_GCS_REGSET from
  gdb/aarch64-linux-tdep.h to gdb/arch/aarch64-gcs-linux.h, as suggested
  by Luis.
- Move changes to HWCAP_PACA to separate patch.

 gdb/Makefile.in                    |  1 +
 gdb/aarch64-linux-nat.c            |  1 +
 gdb/aarch64-linux-tdep.c           |  5 ++--
 gdb/arch/aarch64-gcs-linux.h       | 17 ++-----------
 gdb/nat/aarch64-gcs-linux-ptrace.h | 40 ++++++++++++++++++++++++++++++
 gdbserver/linux-aarch64-low.cc     |  1 +
 6 files changed, 48 insertions(+), 17 deletions(-)
 create mode 100644 gdb/nat/aarch64-gcs-linux-ptrace.h

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index f0f10e3946bf..0ac45bd9d326 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -1550,6 +1550,7 @@ HFILES_NO_SRCDIR = \
 	nat/aarch64-hw-point.h \
 	nat/aarch64-linux.h \
 	nat/aarch64-linux-hw-point.h \
+	nat/aarch64-gcs-linux-ptrace.h \
 	nat/aarch64-mte-linux-ptrace.h \
 	nat/aarch64-scalable-linux-ptrace.h \
 	nat/aarch64-scalable-linux-sigcontext.h \
diff --git a/gdb/aarch64-linux-nat.c b/gdb/aarch64-linux-nat.c
index 9f85d96b59ef..a49b82ca43c8 100644
--- a/gdb/aarch64-linux-nat.c
+++ b/gdb/aarch64-linux-nat.c
@@ -34,6 +34,7 @@
 #include "arch/arm.h"
 #include "nat/aarch64-linux.h"
 #include "nat/aarch64-linux-hw-point.h"
+#include "nat/aarch64-gcs-linux-ptrace.h"
 #include "nat/aarch64-scalable-linux-ptrace.h"
 
 #include "elf/external.h"
diff --git a/gdb/aarch64-linux-tdep.c b/gdb/aarch64-linux-tdep.c
index c17ccbc66220..f0935cbd67e8 100644
--- a/gdb/aarch64-linux-tdep.c
+++ b/gdb/aarch64-linux-tdep.c
@@ -1736,8 +1736,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);
     }
 }
 
diff --git a/gdb/arch/aarch64-gcs-linux.h b/gdb/arch/aarch64-gcs-linux.h
index b31fc32daa03..015a49b25976 100644
--- a/gdb/arch/aarch64-gcs-linux.h
+++ b/gdb/arch/aarch64-gcs-linux.h
@@ -20,25 +20,12 @@
 #ifndef GDB_ARCH_AARCH64_GCS_LINUX_H
 #define GDB_ARCH_AARCH64_GCS_LINUX_H
 
-#include <stdint.h>
-
 /* 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 */
+/* The GCS regset consists of 3 64-bit registers.  */
+#define AARCH64_LINUX_SIZEOF_GCS_REGSET (3 * 8)
 
 #endif /* GDB_ARCH_AARCH64_GCS_LINUX_H */
diff --git a/gdb/nat/aarch64-gcs-linux-ptrace.h b/gdb/nat/aarch64-gcs-linux-ptrace.h
new file mode 100644
index 000000000000..f45a1059cd0a
--- /dev/null
+++ b/gdb/nat/aarch64-gcs-linux-ptrace.h
@@ -0,0 +1,40 @@
+/* Common native Linux definitions for AArch64 Guarded Control Stack.
+
+   Copyright (C) 2025-2026 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   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_NAT_AARCH64_GCS_LINUX_PTRACE_H
+#define GDB_NAT_AARCH64_GCS_LINUX_PTRACE_H
+
+#include <stdint.h>
+#include <asm/ptrace.h>
+
+/* 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 */
+
+#endif /* GDB_NAT_AARCH64_GCS_LINUX_PTRACE_H */
diff --git a/gdbserver/linux-aarch64-low.cc b/gdbserver/linux-aarch64-low.cc
index 6b61f6d5a815..55e55b2df0ab 100644
--- a/gdbserver/linux-aarch64-low.cc
+++ b/gdbserver/linux-aarch64-low.cc
@@ -45,6 +45,7 @@
 #include "arch/aarch64-scalable-linux.h"
 #include "linux-aarch32-tdesc.h"
 #include "linux-aarch64-tdesc.h"
+#include "nat/aarch64-gcs-linux-ptrace.h"
 #include "nat/aarch64-mte-linux-ptrace.h"
 #include "arch/aarch64-pauth-linux.h"
 #include "nat/aarch64-scalable-linux-ptrace.h"

  parent reply	other threads:[~2026-02-17  6:02 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-17  6:00 [PATCH v3 0/4] GDB: aarch64-linux: Some header fixes Thiago Jung Bauermann
2026-02-17  6:00 ` [PATCH v3 1/4] GDB: Add gdb/arch/aarch64-pauth-linux.h Thiago Jung Bauermann
2026-02-21 12:14   ` Luis
2026-02-21 15:57     ` Simon Marchi
2026-02-22 10:06       ` Luis
2026-02-22 14:22         ` Simon Marchi
2026-02-22 15:15           ` Luis
2026-02-22 15:25             ` Simon Marchi
2026-03-03  5:00               ` Thiago Jung Bauermann
2026-02-17  6:01 ` [PATCH v3 2/4] GDB: Add gdb/arch/aarch64-fpmr-linux.h Thiago Jung Bauermann
2026-02-21 12:15   ` Luis
2026-02-17  6:01 ` Thiago Jung Bauermann [this message]
2026-02-21 12:20   ` [PATCH v3 3/4] GDB: aarch64-linux: Move definition of struct user_gcs Luis
2026-02-17  6:01 ` [PATCH v3 4/4] GDB: aarch64-linux: Fix build failure on musl systems Thiago Jung Bauermann
2026-02-21 12:23   ` Luis

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=20260217060106.1906312-4-thiago.bauermann@linaro.org \
    --to=thiago.bauermann@linaro.org \
    --cc=gdb-patches@sourceware.org \
    --cc=judge.packham@gmail.com \
    --cc=luis.machado.foss@gmail.com \
    --cc=simark@simark.ca \
    --cc=tom@tromey.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