Thanks.

Approved-By: Luis Machado <luis.machado.foss@gmail.com>

On Wed, Mar 4, 2026, 01:27 Thiago Jung Bauermann <thiago.bauermann@linaro.org> wrote:
Thiago Jung Bauermann <thiago.bauermann@linaro.org> writes:

> 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.
>
> Also, move the HWCAP_GCS definition to
> gdb/nat/aarch64-gcs-linux-ptrace.h and create an AARCH64_HWCAP_GCS
> definition in gdb/arch/aarch64-gcs-linux.h for use by target-dependent
> code.
>
> Similarly, move the SEGV_CPERR and PR_SHADOW_STACK_{ENABLE,WRITE,PUSH}
> definitions, which were added by the GCS patches and are only used by
> aarch64-linux target-dependent code, to gdb/arch/aarch64-gcs-linux.h
> with an AARCH64_ prefix and adjust users.
>
> Finally, I noticed that gdb/aarch64-linux-nat.c and
> gdbserver/linux-aarch64-low.cc don't need anything from the
> arch/aarch64-gcs-linux.h header, so make them not include it.
>
> Suggested-by: Luis <luis.machado.foss@gmail.com>
> Suggested-by: Simon Marchi <simark@simark.ca>

As Simon mentioned in his review, this commit message wrongly references
gdb/nat/aarch64-gcs-linux-ptrace.h.  I forgot to adjust the text after I
decided to rename the file to gdb/nat/aarch64-gcs-linux.h.  Fixed locally.


> diff --git a/gdb/nat/aarch64-gcs-linux.h b/gdb/nat/aarch64-gcs-linux.h
> new file mode 100644
> index 000000000000..ddf8342a4284
> --- /dev/null
> +++ b/gdb/nat/aarch64-gcs-linux.h
> @@ -0,0 +1,45 @@
> +/* 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_H
> +#define GDB_NAT_AARCH64_GCS_LINUX_H
> +
> +#include <stdint.h>
> +#include <asm/ptrace.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 */
> +
> +#endif /* GDB_NAT_AARCH64_GCS_LINUX_H */

As with previous patches, I amended this one locally with:

diff --git a/gdb/nat/aarch64-gcs-linux.h b/gdb/nat/aarch64-gcs-linux.h
index ddf8342a4284..79e6dcaaaf18 100644
--- a/gdb/nat/aarch64-gcs-linux.h
+++ b/gdb/nat/aarch64-gcs-linux.h
@@ -21,6 +21,7 @@
 #define GDB_NAT_AARCH64_GCS_LINUX_H

 #include <stdint.h>
+#include <asm/hwcap.h>
 #include <asm/ptrace.h>

 /* Feature check for Guarded Control Stack.  */

--
Thiago