tools/testing/selftests/arm64/gcs/gcs-util.h | 1 + 1 file changed, 1 insertion(+)
Building on Debian sid with GCC 15 fails:
CC libc-gcs
libc-gcs.c: In function 'ptrace_read_write':
libc-gcs.c:142:25: error: storage size of 'child_gcs' isn't known
142 | struct user_gcs child_gcs;
| ^~~~~~~~~
libc-gcs.c:142:25: warning: unused variable 'child_gcs' [-Wunused-variable]
For GCC-15, NT_ARM_GCS is defined in the libc header, causing gcs-util.h
to skip its fallback definition of struct user_gcs. This leads to the
compiler error.
Fix this by including <asm/ptrace.h> to provide the proper definition.
Fixes: a505a52b4e29 ("kselftest/arm64: Add a GCS test program built with the system libc")
Signed-off-by: Leo Yan <leo.yan@arm.com>
---
Changes in v2:
- Refined commit log (Mark Brown).
- Moving header to gcs-util.h (Mark Brown).
- Link to v1: https://lore.kernel.org/r/20260422-selftests_arm64_gcc15-v1-1-0d919ea5ac5f@arm.com
---
tools/testing/selftests/arm64/gcs/gcs-util.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/tools/testing/selftests/arm64/gcs/gcs-util.h b/tools/testing/selftests/arm64/gcs/gcs-util.h
index c99a6b39ac147b4efbc9b5fbadb43daf4da2c85e..f583d4dbd0bfd964e08cf40b3951664c70bb031a 100644
--- a/tools/testing/selftests/arm64/gcs/gcs-util.h
+++ b/tools/testing/selftests/arm64/gcs/gcs-util.h
@@ -7,6 +7,7 @@
#define GCS_UTIL_H
#include <stdbool.h>
+#include <asm/ptrace.h>
#ifndef __NR_map_shadow_stack
#define __NR_map_shadow_stack 453
---
base-commit: 4ee64205ffaa587e8114d84a67ac721399ccb369
change-id: 20260421-selftests_arm64_gcc15-15f6f6d07dd8
Best regards,
--
Leo Yan <leo.yan@arm.com>
On Wed, Apr 22, 2026 at 06:42:54PM +0100, Leo Yan wrote: > Building on Debian sid with GCC 15 fails: > > CC libc-gcs > libc-gcs.c: In function 'ptrace_read_write': > libc-gcs.c:142:25: error: storage size of 'child_gcs' isn't known > 142 | struct user_gcs child_gcs; > | ^~~~~~~~~ > libc-gcs.c:142:25: warning: unused variable 'child_gcs' [-Wunused-variable] > > For GCC-15, NT_ARM_GCS is defined in the libc header, causing gcs-util.h > to skip its fallback definition of struct user_gcs. This leads to the > compiler error. > > Fix this by including <asm/ptrace.h> to provide the proper definition. This is not caused by GCC-15 as it doesn't provide these headers. AFAICT on Debian we have NT_ARM_GCS coming from glibc and user_gcs from the kernel asm/ptrace.h uapi header (linux-libc-dev). We also have NT_ARM_GCS in linux/elf.h as part of the kernel headers. While the kernel exposed the macro and structure in the same commit, I don't think it is required distros to align the glibc macro with the linux headers. Glibc does not even use the kernel's linux/elf.h for the macros, it just adds the definitions when they turn up in a released kernel. So you can have a glibc that defines NT_ARM_GCS but a linux-libc-dev package that is not up to date to include struct user_gcs. I think a better fix is to always define struct user_gcs and only conditionally define NT_ARM_GCS (IOW, move the #endif higher). -- Catalin
On Fri, Apr 24, 2026 at 04:51:24PM +0100, Catalin Marinas wrote: > On Wed, Apr 22, 2026 at 06:42:54PM +0100, Leo Yan wrote: > > Building on Debian sid with GCC 15 fails: > I think a better fix is to always define struct user_gcs and only > conditionally define NT_ARM_GCS (IOW, move the #endif higher). I've not actually double checked that everything is wired up properly but I believe these days this should actually pick up asm/ptrace.h from the headers_install target so a current kernel copy. We ought to be able to remove the local definition of struct user_gcs I think, there's still some weirdness with the NT_ definitions I can't remember but the struct should be fine.
On Fri, Apr 24, 2026 at 05:07:42PM +0100, Mark Brown wrote: > On Fri, Apr 24, 2026 at 04:51:24PM +0100, Catalin Marinas wrote: > > On Wed, Apr 22, 2026 at 06:42:54PM +0100, Leo Yan wrote: > > > > Building on Debian sid with GCC 15 fails: > > > I think a better fix is to always define struct user_gcs and only > > conditionally define NT_ARM_GCS (IOW, move the #endif higher). > > I've not actually double checked that everything is wired up properly > but I believe these days this should actually pick up asm/ptrace.h from > the headers_install target so a current kernel copy. We ought to be > able to remove the local definition of struct user_gcs I think, there's > still some weirdness with the NT_ definitions I can't remember but the > struct should be fine. OK, so it does look like it picks the kernel uapi/asm/ptrace.h. It builds fine on Debian stable (no GCS anywhere) with including asm/ptrace.h and removing struct user_gcs. But I think we should include asm/ptrace.h in libc-gcs.h and not the gcs-util.h header (for NT_ARM_GCS it's fine to keep in gcs-util.h). -- Catalin
On Fri, Apr 24, 2026 at 05:44:16PM +0100, Catalin Marinas wrote: > OK, so it does look like it picks the kernel uapi/asm/ptrace.h. It > builds fine on Debian stable (no GCS anywhere) with including > asm/ptrace.h and removing struct user_gcs. > But I think we should include asm/ptrace.h in libc-gcs.h and not the > gcs-util.h header (for NT_ARM_GCS it's fine to keep in gcs-util.h). It's not glibc specific so it seems reasonable to keep it in gcs-util.h, even though we don't currently have any nolibc stuff that uses ptrace. That said this isn't particularly strongly held opinion so I don't *really* mind either way.
On Fri, Apr 24, 2026 at 06:09:01PM +0100, Mark Brown wrote:
> On Fri, Apr 24, 2026 at 05:44:16PM +0100, Catalin Marinas wrote:
>
> > OK, so it does look like it picks the kernel uapi/asm/ptrace.h. It
> > builds fine on Debian stable (no GCS anywhere) with including
> > asm/ptrace.h and removing struct user_gcs.
kselftest has the GCC option: "-isystem $(top_srcdir)/usr/include",
So asm/ptrace.h does come from kernel's usr/include/asm/ptrace.h.
NT_ARM_GCS comes from /usr/aarch64-linux-gnu/include/elf.h.
> > But I think we should include asm/ptrace.h in libc-gcs.h and not the
> > gcs-util.h header (for NT_ARM_GCS it's fine to keep in gcs-util.h).
>
> It's not glibc specific so it seems reasonable to keep it in gcs-util.h,
> even though we don't currently have any nolibc stuff that uses ptrace.
> That said this isn't particularly strongly held opinion so I don't
> *really* mind either way.
Does below change make sense to you?
Subject: [PATCH] kselftest/arm64: Include <asm/ptrace.h> for user_gcs definition
kselftest includes kernel uAPI headers with option:
-isystem $(top_srcdir)/usr/include
Include <asm/ptrace.h> in libc-gcs.c for the definition of struct
user_gcs from the uAPI headers, and remove the redundant
definition in gcs-util.h.
Fixes: a505a52b4e29 ("kselftest/arm64: Add a GCS test program built with the system libc")
Signed-off-by: Leo Yan <leo.yan@arm.com>
---
tools/testing/selftests/arm64/gcs/gcs-util.h | 6 ------
tools/testing/selftests/arm64/gcs/libc-gcs.c | 1 +
2 files changed, 1 insertion(+), 6 deletions(-)
diff --git a/tools/testing/selftests/arm64/gcs/gcs-util.h b/tools/testing/selftests/arm64/gcs/gcs-util.h
index c99a6b39ac14..7a81bb07ed4b 100644
--- a/tools/testing/selftests/arm64/gcs/gcs-util.h
+++ b/tools/testing/selftests/arm64/gcs/gcs-util.h
@@ -18,12 +18,6 @@
#ifndef NT_ARM_GCS
#define NT_ARM_GCS 0x410
-
-struct user_gcs {
- __u64 features_enabled;
- __u64 features_locked;
- __u64 gcspr_el0;
-};
#endif
/* Shadow Stack/Guarded Control Stack interface */
diff --git a/tools/testing/selftests/arm64/gcs/libc-gcs.c b/tools/testing/selftests/arm64/gcs/libc-gcs.c
index 17b2fabfec38..72e82bfbecc9 100644
--- a/tools/testing/selftests/arm64/gcs/libc-gcs.c
+++ b/tools/testing/selftests/arm64/gcs/libc-gcs.c
@@ -16,6 +16,7 @@
#include <asm/hwcap.h>
#include <asm/mman.h>
+#include <asm/ptrace.h>
#include <linux/compiler.h>
--
2.34.1
On Tue, Apr 28, 2026 at 11:15:13AM +0100, Leo Yan wrote: > > It's not glibc specific so it seems reasonable to keep it in gcs-util.h, > > even though we don't currently have any nolibc stuff that uses ptrace. > > That said this isn't particularly strongly held opinion so I don't > > *really* mind either way. > Does below change make sense to you? That looks fine to me.
On Wed, Apr 22, 2026 at 06:42:54PM +0100, Leo Yan wrote: > For GCC-15, NT_ARM_GCS is defined in the libc header, causing gcs-util.h > to skip its fallback definition of struct user_gcs. This leads to the > compiler error. > Fix this by including <asm/ptrace.h> to provide the proper definition. > +++ b/tools/testing/selftests/arm64/gcs/gcs-util.h > @@ -7,6 +7,7 @@ > #define GCS_UTIL_H > > #include <stdbool.h> > +#include <asm/ptrace.h> > > #ifndef __NR_map_shadow_stack > #define __NR_map_shadow_stack 453 Reviewed-by: Mark Brown <broonie@kernel.org>
© 2016 - 2026 Red Hat, Inc.