|
Message-ID: <20190212183222.GN23599@brightrain.aerifal.cx> Date: Tue, 12 Feb 2019 13:32:22 -0500 From: Rich Felker <dalias@...c.org> To: musl@...ts.openwall.com Subject: Re: [PATCH] powerpc64: use a type for mcontext_t regs field On Tue, Feb 12, 2019 at 01:24:09PM -0500, David Edelsohn wrote: > On Tue, Feb 12, 2019 at 1:21 PM Rich Felker <dalias@...c.org> wrote: > > > > On Tue, Feb 12, 2019 at 01:17:34PM -0500, David Edelsohn wrote: > > > On Tue, Feb 12, 2019 at 12:23 PM Rich Felker <dalias@...c.org> wrote: > > > > > > > > On Tue, Feb 12, 2019 at 12:05:17PM -0500, David Edelsohn wrote: > > > > > On Tue, Feb 12, 2019 at 11:18 AM Rich Felker <dalias@...c.org> wrote: > > > > > > > > > > > > On Tue, Feb 12, 2019 at 09:35:22AM -0600, A. Wilcox wrote: > > > > > > > GCC Go dereferences `regs` for `nip`. Without this change, compilation > > > > > > > fails with the following message: > > > > > > > > > > > > > > .../../../libgo/runtime/go-signal.c: In function ‘getSiginfo’: > > > > > > > .../../../libgo/runtime/go-signal.c:225:56: warning: dereferencing ‘void *’ pointer > > > > > > > ret.sigpc = ((ucontext_t*)(context))->uc_mcontext.regs->nip; > > > > > > > ^~ > > > > > > > .../../../libgo/runtime/go-signal.c:225:56: error: request for member ‘nip’ in something not a structure or union > > > > > > > --- > > > > > > > arch/powerpc64/bits/signal.h | 4 +++- > > > > > > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > > > > > > > > > > > diff --git a/arch/powerpc64/bits/signal.h b/arch/powerpc64/bits/signal.h > > > > > > > index 34693a68..6736c69a 100644 > > > > > > > --- a/arch/powerpc64/bits/signal.h > > > > > > > +++ b/arch/powerpc64/bits/signal.h > > > > > > > @@ -8,6 +8,8 @@ > > > > > > > > > > > > > > #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) > > > > > > > > > > > > > > +#include <bits/user.h> > > > > > > > + > > > > > > > > > > > > This is almost surely not right. You can never use a bits/* header > > > > > > except from the corresponding public header that includes it. They do > > > > > > not have multiple-inclusion guards and are not designed to be usable > > > > > > independently. And including sys/user.h is also almost surely wrong > > > > > > since it's a problematic header you don't want getting included > > > > > > (conflicts with linux/*.h stuff). > > > > > > > > > > > > > typedef unsigned long greg_t, gregset_t[48]; > > > > > > > > > > > > > > typedef struct { > > > > > > > @@ -29,7 +31,7 @@ typedef struct sigcontext { > > > > > > > int _pad0; > > > > > > > unsigned long handler; > > > > > > > unsigned long oldmask; > > > > > > > - void *regs; > > > > > > > + struct pt_regs *regs; > > > > > > > gregset_t gp_regs; > > > > > > > fpregset_t fp_regs; > > > > > > > vrregset_t *v_regs; > > > > > > > -- > > > > > > > 2.19.2 > > > > > > > > > > > > Do you know if there's a reason Go is trying to use this regs member > > > > > > rather than gp_regs? I think that's the real issue here. > > > > > > > > > > Apparently GCCGo runtime has dependencies on GLibc and has not been > > > > > ported to Musl Libc. The GCCGo runtime is trying to obtain the PC for > > > > > a signal. > > > > > > > > > > #ifdef __PPC__ > > > > > #ifdef __linux__ > > > > > ret.sigpc = ((ucontext_t*)(context))->uc_mcontext.regs->nip; > > > > > #endif > > > > > #ifdef _AIX > > > > > ret.sigpc = ((ucontext_t*)(context))->uc_mcontext.jmp_context.iar; > > > > > #endif > > > > > #endif > > > > > > > > > > The program counter is not part of gp_regs. > > > > > > > > Yes it is, as musl already depends on having access to the program > > > > counter for thread cancellation. See arch/powerpc64/pthread_arch.h: > > > > > > > > // the kernel calls the ip "nip", it's the first saved value after the 32 > > > > // GPRs. > > > > #define MC_PC gp_regs[32] > > > > > > Apparently Ian Taylor now is aware of this and investigating a > > > solution -- possibly another ifdef in the above for PPC Musl Libc. > > > > This is not a public #define that you could #ifdef on. It's part of > > musl thread implementation internals and only present in the musl > > source tree, not anywhere installed. I just showed it to demonstrate > > that the NIP register (as well as 15 other registers that are just not > > the 32 numbered GPRs) is part of the gp_regs array. > > I meant that it appears this should be fixed in GCC Go runtime -- > somehow -- not in Musl Libc referring to nip. GCC Go apparently will > need another case for Musl Libc and somehow know to reference > gp_regs[32], or some other way to know about the internals of Musl > Libc and access the program counter. This is not knowledge of musl internals. Both accessing a pt_regs struct pointed to by the regs member, and accessing gp_regs[32], are part of the kernel ABI for powerpc64 mcontext_t. musl simply does not expose the struct pt_regs type here because there's no safe way to get a definition that doesn't clash with kernel headers, so I suggested using the alternate way that *also works on glibc*. I can't see any reason to make this change conditional on musl. I think it would also be acceptable to change the void * to struct pt_regs * in musl's mcontext_t, but then it would be a pointer to incomplete type unless you also include sys/user.h. Generally, user.h is an awful header you want to avoid unless you have no choice, though, so I think it's highly preferable for gccgo *not* to use it, even if we do make this change, and instead use the gp_regs NIP slot that avoids touching anything from user.h. Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.