Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Luis <luis.machado.foss@gmail.com>
To: Thiago Jung Bauermann <thiago.bauermann@linaro.org>,
	gdb-patches@sourceware.org
Cc: Chris Packham <judge.packham@gmail.com>,
	Tom Tromey <tom@tromey.com>, Simon Marchi <simark@simark.ca>
Subject: Re: [PATCH v3 4/4] GDB: aarch64-linux: Fix build failure on musl systems
Date: Sat, 21 Feb 2026 12:23:26 +0000	[thread overview]
Message-ID: <ba673d34-ec43-40f1-a65d-e5ebcac57c33@gmail.com> (raw)
In-Reply-To: <20260217060106.1906312-5-thiago.bauermann@linaro.org>

On 17/02/2026 06:01, Thiago Jung Bauermann wrote:
> 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:48:
>    /home/bauermann/src/binutils-gdb/gdbserver/../gdb/nat/aarch64-gcs-linux-ptrace.h:31:8: error: redefinition of 'struct user_gcs'
>       31 | struct user_gcs
>          |        ^~~~~~~~
>    In file included from /home/bauermann/src/binutils-gdb/gdbserver/linux-aarch64-low.cc:35:
>    /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>
> ---
> Changes since v2:
> - It's the same patch except that the header changed is
>    gdb/nat/aarch64-gcs-linux-ptrace.h rather than gdb/nat/aarch64-linux.h,
>    which doesn't exist in this version of the patch series.
> 
>   gdb/nat/aarch64-gcs-linux-ptrace.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-gcs-linux-ptrace.h b/gdb/nat/aarch64-gcs-linux-ptrace.h
> index f45a1059cd0a..f3dda08a1d27 100644
> --- a/gdb/nat/aarch64-gcs-linux-ptrace.h
> +++ b/gdb/nat/aarch64-gcs-linux-ptrace.h
> @@ -23,8 +23,7 @@
>   #include <stdint.h>
>   #include <asm/ptrace.h>
>   
> -/* 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).  */
>   
> @@ -35,6 +34,6 @@ struct user_gcs
>     uint64_t gcspr_el0;
>   };
>   
> -#endif /* GCS_MAGIC */
> +#endif /* HAVE_STRUCT_USER_GCS */
>   
>   #endif /* GDB_NAT_AARCH64_GCS_LINUX_PTRACE_H */
> 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
>   

Thanks. Still looks OK to me. I'd like a second approval from Tom or Simon.

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

      reply	other threads:[~2026-02-21 12:23 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 ` [PATCH v3 3/4] GDB: aarch64-linux: Move definition of struct user_gcs Thiago Jung Bauermann
2026-02-21 12:20   ` 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 [this message]

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=ba673d34-ec43-40f1-a65d-e5ebcac57c33@gmail.com \
    --to=luis.machado.foss@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=judge.packham@gmail.com \
    --cc=simark@simark.ca \
    --cc=thiago.bauermann@linaro.org \
    --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