Closed nmeum closed 2 years ago
On musl, libucontext uses the musl headers for structure definitions. So we should probably ask dalias.
(I would assume the issue is that _GNU_SOURCE needs to be defined though)
On musl, libucontext uses the musl headers for structure definitions. So we should probably ask dalias.
https://git.musl-libc.org/cgit/musl/commit/?id=c2518a8efb6507f1b41c3b12e03b06f8f2317a1f
I suppose libucontext could provide a definition of struct pt_regs
on PowerPC then?
I think pt_regs should come from kernel, but i’m not sure what header has it.
Seems to be defined in asm/ptrace.h
: https://github.com/torvalds/linux/blob/a3314262eede9c909a0c797f16f25f941d12c78d/arch/powerpc/include/asm/ptrace.h#L28
Would it be possible to include this Linux header from ucontext.h
on PowerPC or what would be the best approach to make the pt_regs
definition visible automatically when using libucontext on PowerPC?
As the headers from musl are used on musl, I don’t have any control over them. You could include asm/ptrace.h in the GCC-Go side of things though.
I looked into how glibc handles this. Similar to musl, glibc also seem to declare pt_regs
as an incomplete type on PowerPC [0]. So even with glibc, gcc-go would need an include of asm/ptrace.h
on PowerPC. However, it seems that some other glibc headers (like sys/user.h
) cause an implicit include of asm/ptrace.h
which is why the code linked in the issue description probably compiles on glibc [1]. I guess this is a "bug" a gcc-go then, closing this.
I am currently using libcontext with gcc-go, which uses ucontext functions to implement goroutines. In this regard, I am trying to reduce the amount of gcc-go patches required to make it work on musl systems. On the PowerPC architecture, libgo from gcc-go assumes a
regs
member to be present in the machine-specific representation of the saved context (uc_mcontext
):Unfortunately, this
regs
member does not seem to be available on libucontext, thus requiring patching gcc-go. However, libucontext seems to expose the same registers via thegp_regs
member. For example,uc_mcontext.regs->nip
seems to be accessible with libucontext asuc_mcontext.gp_regs[REG_NIP]
.I am not an expert on ucontext and it is presently unclear to me where the
uc_mcontext
fields are standardized (since POSIX does not seem to mandate those) but I am wondering if it would be possible to add theregs
member touc_mcontext
on PowerPC to make existing code (i.e. gcc-go) work without additional patches.