Ping.

Summary: Fix build of libgo on PPC with musl libc and libucontext by
explicitly including the Linux header defining `struct pt_regs` instead of
relying on other libc headers to include it implicitly.

See: https://gcc.gnu.org/pipermail/gcc-patches/2022-January/587520.html

If the patch needs to be revised further please let me know. This patch has
been applied at Alpine Linux downstream (which uses musl libc) for a while, I
have not tested it on other systems.

Greetings,
Sören

Sören Tempel <soe...@soeren-tempel.net> wrote:
> Both glibc and musl libc declare pt_regs as an incomplete type. This
> type has to be completed by inclusion of another header. On Linux, the
> asm/ptrace.h header file provides this type definition. Without
> including this header file, it is not possible to access the regs member
> of the mcontext_t struct as done in libgo/runtime/go-signal.c. On glibc,
> other headers (e.g. sys/user.h) include asm/ptrace.h but on musl
> asm/ptrace.h is not included by other headers and thus the
> aforementioned files do not compile without an explicit include of
> asm/ptrace.h:
> 
>       libgo/runtime/go-signal.c: In function 'getSiginfo':
>       libgo/runtime/go-signal.c:227:63: error: invalid use of undefined type 
> 'struct pt_regs'
>         227 |         ret.sigpc = 
> ((ucontext_t*)(context))->uc_mcontext.regs->nip;
>             |
> 
> See also:
> 
> * 
> https://git.musl-libc.org/cgit/musl/commit/?id=c2518a8efb6507f1b41c3b12e03b06f8f2317a1f
> * https://github.com/kaniini/libucontext/issues/36
> 
> Signed-off-by: Sören Tempel <soe...@soeren-tempel.net>
> 
> ChangeLog:
> 
>       * libgo/runtime/go-signal.c: Include asm/ptrace.h for the
>         definition of pt_regs (used by mcontext_t) on PowerPC.
> ---
>  libgo/runtime/go-signal.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/libgo/runtime/go-signal.c b/libgo/runtime/go-signal.c
> index d30d1603adc..fc01e04e4a1 100644
> --- a/libgo/runtime/go-signal.c
> +++ b/libgo/runtime/go-signal.c
> @@ -10,6 +10,12 @@
>  #include <sys/time.h>
>  #include <ucontext.h>
>  
> +// On PowerPC, ucontext.h uses a pt_regs struct as an incomplete
> +// type. This type must be completed by including asm/ptrace.h.
> +#ifdef __PPC__
> +#include <asm/ptrace.h>
> +#endif
> +
>  #include "runtime.h"
>  
>  #ifndef SA_RESTART

Reply via email to