![]() |
|
Message-ID: <20250723150235.GG1827@brightrain.aerifal.cx> Date: Wed, 23 Jul 2025 11:02:36 -0400 From: Rich Felker <dalias@...c.org> To: J. Neuschäfer <j.neuschaefer@....net> Cc: musl@...ts.openwall.com, Ariadne Conill <ariadne@...eferenced.org> Subject: Re: musl/arch/sh: Inconsistency between greg_t (int) and mcontext_t.gregs (unsigned long[]); libucontext fails to build On Wed, Jul 23, 2025 at 04:48:45PM +0200, J. Neuschäfer wrote: > Hello, > > I recently tried to build libucontext on top of musl-libc for sh4, and > ran into the following problem: > > arch/sh/makecontext.c: In function ‘libucontext_makecontext’: > arch/sh/makecontext.c:45:14: error: assignment to ‘libucontext_greg_t *’ {aka ‘int *’} from incompatible pointer type ‘long unsigned int *’ [-Wincompatible-pointer-types] > 45 | regp = &ucp->uc_mcontext.gregs[4]; > | ^ > make: *** [Makefile:155: arch/sh/makecontext.o] Error 1 > > > The corresponding code in libucontext is: > > void > libucontext_makecontext(libucontext_ucontext_t *ucp, void (*func)(void), int argc, ...) > { > libucontext_greg_t *sp, *regp; > [...] > regp = &ucp->uc_mcontext.gregs[4]; > [...] > } > > The issue is that libucontext expects mcontext_t.gregs to use the same type as > greg_t (which seems reasonable to expect), but musl-libc doesn't do that: > > typedef int greg_t, gregset_t[16]; > [...] > unsigned long gregs[16]; > > > Should this be fixed in musl or in libucontext? I'm not sure. It probably depends on whether there's a good historical reason these differ. For the mcontext members it looks like glibc has them as int rather than long, but still unsigned, so they also have a signedness mismatch which should not implicitly convert, but at least it would be well-defined accessing thru the mismatched type if the pointer conversion were explicit (e.g. adding a (void *) cast). We probably should do something to improve the situation here, but I think the easiest immediate fix would just be getting rid of the useless intermediate var regp in libucontext and doing something like: ucp->uc_mcontext.gregs[4+i] = va_arg(va, libucontext_greg_t); instead of: *regp++ = va_arg(va, libucontext_greg_t); In general, it's probably a bad idea to use pointers to members of arch-specific structures where there's no clear authoritative answer for what the exact types of the members are supposed to be. 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.