public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug go/113143] New: Remove usage of ucontext.h
@ 2023-12-26 3:43 kallisti5 at unixzen dot com
2023-12-26 3:48 ` [Bug go/113143] " kallisti5 at unixzen dot com
` (11 more replies)
0 siblings, 12 replies; 13+ messages in thread
From: kallisti5 at unixzen dot com @ 2023-12-26 3:43 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113143
Bug ID: 113143
Summary: Remove usage of ucontext.h
Product: gcc
Version: 13.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: go
Assignee: ian at airs dot com
Reporter: kallisti5 at unixzen dot com
Target Milestone: ---
libgo/sysinfo.c references #include <ucontext.h> which breaks the libgo build
on strict POSIX compliance platforms.
ucontext.h was removed in issue 7, and types were migrated to signal.h.
Old 2004 spec:
https://pubs.opengroup.org/onlinepubs/009695399/basedefs/ucontext.h.html
Pretty much any recent spec: (ucontext.h is gone)
https://pubs.opengroup.org/onlinepubs/9699919799/
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug go/113143] Remove usage of ucontext.h
2023-12-26 3:43 [Bug go/113143] New: Remove usage of ucontext.h kallisti5 at unixzen dot com
@ 2023-12-26 3:48 ` kallisti5 at unixzen dot com
2023-12-26 4:48 ` ian at airs dot com
` (10 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: kallisti5 at unixzen dot com @ 2023-12-26 3:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113143
--- Comment #1 from Alexander von Gluck <kallisti5 at unixzen dot com> ---
$ grep -R ucontext.h gcc/libgo
gcc/libgo/configure:#include <ucontext.h>
gcc/libgo/configure.ac:#include <ucontext.h>
gcc/libgo/go/runtime/runtime2.go:// _sizeof_ucontext_t is defined by
mkrsysinfo.sh from <ucontext.h>.
gcc/libgo/misc/cgo/testsanitizers/testdata/tsan_shared.go:#include <ucontext.h>
gcc/libgo/runtime/go-signal.c:#include <ucontext.h>
gcc/libgo/runtime/runtime.h:#include <ucontext.h>
gcc/libgo/sysinfo.c:#include <ucontext.h>
gcc/libgo/sysinfo.c:// From sys/ucontext.h
pretty much all of these references can be replaced with a signal.h include...
(or wrapped with HAVE_U_CONTEXT_H or whatever if concerned about backwards
compatibility to posix 2004.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug go/113143] Remove usage of ucontext.h
2023-12-26 3:43 [Bug go/113143] New: Remove usage of ucontext.h kallisti5 at unixzen dot com
2023-12-26 3:48 ` [Bug go/113143] " kallisti5 at unixzen dot com
@ 2023-12-26 4:48 ` ian at airs dot com
2023-12-26 13:13 ` kallisti5 at unixzen dot com
` (9 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: ian at airs dot com @ 2023-12-26 4:48 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113143
--- Comment #2 from Ian Lance Taylor <ian at airs dot com> ---
Note that except on x86_64 GNU/Linux, libgo requires the makecontext,
getcontext, and setcontext functions that are declared in ucontext.h. There is
no adequate replacement for those functions on strict POSIX systems. (On
x86_64 GNU/Linux libgo provides assembler versions of those functions (in
libgo/runtime/go-context.S) that are more efficient for libgo's purposes.)
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug go/113143] Remove usage of ucontext.h
2023-12-26 3:43 [Bug go/113143] New: Remove usage of ucontext.h kallisti5 at unixzen dot com
2023-12-26 3:48 ` [Bug go/113143] " kallisti5 at unixzen dot com
2023-12-26 4:48 ` ian at airs dot com
@ 2023-12-26 13:13 ` kallisti5 at unixzen dot com
2023-12-26 23:16 ` ian at airs dot com
` (8 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: kallisti5 at unixzen dot com @ 2023-12-26 13:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113143
--- Comment #3 from Alexander von Gluck <kallisti5 at unixzen dot com> ---
Good call out. It looks like in 2004 these functions were flagged as
obsolescent though:
https://pubs.opengroup.org/onlinepubs/009695399/functions/makecontext.html
Here's the note on it in the linux man page for getcontext:
"
glibc 2.1. SUSv2, POSIX.1-2001. Removed in POSIX.1-2008, citing
portability issues, and recommending that applications be
rewritten to use POSIX threads instead.
"
upstream go usage:
* makecontext: no code matches as of go 1.22 (main)
* getcontext: netbsd,solaris,freebsd code usage as of go 1.22 (main)
* setcontext: netbsd,freebsd code usages as of go 1.22 (main)
* swapcontext: freebsd code usages as of go 1.22 (main)
Per the 2004 spec:
"The obsolescent functions getcontext(), makecontext(), and swapcontext() can
be replaced using POSIX threads functions."
Essentially, for quite some time, (get|make|set)context are only used on the
BSD's and Solaris... thus invocation of include<ucontext.h> should be guarded /
masked off on all other platforms.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug go/113143] Remove usage of ucontext.h
2023-12-26 3:43 [Bug go/113143] New: Remove usage of ucontext.h kallisti5 at unixzen dot com
` (2 preceding siblings ...)
2023-12-26 13:13 ` kallisti5 at unixzen dot com
@ 2023-12-26 23:16 ` ian at airs dot com
2023-12-27 2:31 ` kallisti5 at unixzen dot com
` (7 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: ian at airs dot com @ 2023-12-26 23:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113143
--- Comment #4 from Ian Lance Taylor <ian at airs dot com> ---
I understand that makecontext/getcontext/setcontext were removed from POSIX.
However, there is no adequate replacement. Their functionality is absolutely
required for what libgo does. Fortunately GNU/Linux systems continue to
provide them.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug go/113143] Remove usage of ucontext.h
2023-12-26 3:43 [Bug go/113143] New: Remove usage of ucontext.h kallisti5 at unixzen dot com
` (3 preceding siblings ...)
2023-12-26 23:16 ` ian at airs dot com
@ 2023-12-27 2:31 ` kallisti5 at unixzen dot com
2023-12-27 2:34 ` kallisti5 at unixzen dot com
` (6 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: kallisti5 at unixzen dot com @ 2023-12-27 2:31 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113143
--- Comment #5 from Alexander von Gluck <kallisti5 at unixzen dot com> ---
> I understand that makecontext/getcontext/setcontext were removed from POSIX. However, there is no adequate replacement. Their functionality is absolutely required for what libgo does.
No Linux-specific code calls these in gccgo, or upstream go. Only FreeBSD,
Solaris, and OpenBSD.
Thus my question, why is ucontext.h referenced in cross-platform code when
signal.h will suffice?
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug go/113143] Remove usage of ucontext.h
2023-12-26 3:43 [Bug go/113143] New: Remove usage of ucontext.h kallisti5 at unixzen dot com
` (4 preceding siblings ...)
2023-12-27 2:31 ` kallisti5 at unixzen dot com
@ 2023-12-27 2:34 ` kallisti5 at unixzen dot com
2023-12-27 2:40 ` pinskia at gcc dot gnu.org
` (5 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: kallisti5 at unixzen dot com @ 2023-12-27 2:34 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113143
--- Comment #6 from Alexander von Gluck <kallisti5 at unixzen dot com> ---
For added clairity. Searching the upstream go sources:
```
grep -R getcontext
src/cmd/vendor/golang.org/x/sys/unix/syscall_netbsd.go:// getcontext
src/cmd/vendor/golang.org/x/sys/unix/zsysnum_freebsd_386.go: SYS_GETCONTEXT
= 421 // { int getcontext(struct __ucontext *ucp); }
src/cmd/vendor/golang.org/x/sys/unix/zsysnum_freebsd_amd64.go: SYS_GETCONTEXT
= 421 // { int getcontext(struct __ucontext *ucp); }
src/cmd/vendor/golang.org/x/sys/unix/zsysnum_freebsd_arm.go: SYS_GETCONTEXT
= 421 // { int getcontext(struct __ucontext *ucp); }
src/cmd/vendor/golang.org/x/sys/unix/zsysnum_freebsd_arm64.go: SYS_GETCONTEXT
= 421 // { int getcontext(struct __ucontext *ucp); }
src/cmd/vendor/golang.org/x/sys/unix/zsysnum_netbsd_386.go: SYS_GETCONTEXT
= 307 // { int|sys||getcontext(struct __ucontext *ucp); }
src/cmd/vendor/golang.org/x/sys/unix/zsysnum_netbsd_amd64.go: SYS_GETCONTEXT
= 307 // { int|sys||getcontext(struct __ucontext *ucp); }
src/cmd/vendor/golang.org/x/sys/unix/zsysnum_netbsd_arm.go: SYS_GETCONTEXT
= 307 // { int|sys||getcontext(struct __ucontext *ucp); }
src/cmd/vendor/golang.org/x/sys/unix/zsysnum_netbsd_arm64.go: SYS_GETCONTEXT
= 307 // { int|sys||getcontext(struct __ucontext *ucp); }
src/runtime/cgo/gcc_solaris_amd64.c: if (getcontext(&ctx) != 0)
src/runtime/cgo/gcc_solaris_amd64.c: perror("runtime/cgo: getcontext
failed");
src/runtime/os3_solaris.go://go:cgo_import_dynamic libc_getcontext getcontext
"libc.so"
src/runtime/os3_solaris.go://go:linkname libc_getcontext libc_getcontext
src/runtime/os3_solaris.go: libc_getcontext,
src/runtime/os3_solaris.go:func getcontext(context *ucontext) /* int32 */ {
src/runtime/os3_solaris.go: sysvicall1(&libc_getcontext,
uintptr(unsafe.Pointer(context)))
src/runtime/os_netbsd.go:func getcontext(ctxt unsafe.Pointer)
src/runtime/os_netbsd.go: getcontext(unsafe.Pointer(&uc))
src/runtime/sys_netbsd_386.s:#define SYS_getcontext 307
src/runtime/sys_netbsd_386.s:TEXT runtime·getcontext(SB),NOSPLIT,$-4
src/runtime/sys_netbsd_386.s: MOVL $SYS_getcontext, AX
src/runtime/sys_netbsd_amd64.s:#define SYS_getcontext 307
src/runtime/sys_netbsd_amd64.s:TEXT runtime·getcontext(SB),NOSPLIT,$-8
src/runtime/sys_netbsd_amd64.s: MOVL $SYS_getcontext, AX
src/runtime/sys_netbsd_arm.s:#define SYS_getcontext
SWI_OS_NETBSD | 307
src/runtime/sys_netbsd_arm.s:TEXT runtime·getcontext(SB),NOSPLIT|NOFRAME,$0
src/runtime/sys_netbsd_arm.s: SWI $SYS_getcontext
src/runtime/sys_netbsd_arm64.s:#define SYS_getcontext 307
src/runtime/sys_netbsd_arm64.s:TEXT runtime·getcontext(SB),NOSPLIT,$-8
src/runtime/sys_netbsd_arm64.s: SVC $SYS_getcontext
src/syscall/zsysnum_freebsd_386.go: SYS_GETCONTEXT = 421 // {
int getcontext(struct __ucontext *ucp); }
src/syscall/zsysnum_freebsd_amd64.go: SYS_GETCONTEXT = 421 // {
int getcontext(struct __ucontext *ucp); }
src/syscall/zsysnum_freebsd_arm.go: SYS_GETCONTEXT = 421 // {
int getcontext(struct __ucontext *ucp); }
src/syscall/zsysnum_freebsd_arm64.go: SYS_GETCONTEXT = 421 // {
int getcontext(struct __ucontext *ucp); }
src/syscall/zsysnum_netbsd_386.go: SYS_GETCONTEXT = 307 // {
int|sys||getcontext(struct __ucontext *ucp); }
src/syscall/zsysnum_netbsd_amd64.go: SYS_GETCONTEXT = 307 // {
int|sys||getcontext(struct __ucontext *ucp); }
src/syscall/zsysnum_netbsd_arm.go: SYS_GETCONTEXT = 307 // {
int|sys||getcontext(struct __ucontext *ucp); }
src/syscall/zsysnum_netbsd_arm64.go: SYS_GETCONTEXT = 307 // {
int|sys||getcontext(struct __ucontext *ucp); }
```
Those all appear to be BSD-specific references, unless i'm missing an
invocation of (get|set|swap)context somewhere?
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug go/113143] Remove usage of ucontext.h
2023-12-26 3:43 [Bug go/113143] New: Remove usage of ucontext.h kallisti5 at unixzen dot com
` (5 preceding siblings ...)
2023-12-27 2:34 ` kallisti5 at unixzen dot com
@ 2023-12-27 2:40 ` pinskia at gcc dot gnu.org
2023-12-27 3:20 ` kallisti5 at unixzen dot com
` (4 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-27 2:40 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113143
--- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Let me ask a dumb question, are you porting GCC/gccgo to a libc which does not
have ucontext.h ? If so what is the libc my I ask?
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug go/113143] Remove usage of ucontext.h
2023-12-26 3:43 [Bug go/113143] New: Remove usage of ucontext.h kallisti5 at unixzen dot com
` (6 preceding siblings ...)
2023-12-27 2:40 ` pinskia at gcc dot gnu.org
@ 2023-12-27 3:20 ` kallisti5 at unixzen dot com
2023-12-27 3:38 ` kallisti5 at unixzen dot com
` (3 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: kallisti5 at unixzen dot com @ 2023-12-27 3:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113143
--- Comment #8 from Alexander von Gluck <kallisti5 at unixzen dot com> ---
Not at all a dumb question :-)
I'm working through compiling libgo / gccgo on Haiku. We have our own lovely
libc which tests posix compliant.
Some historic consideration behind us not having ucontext.h is here:
https://dev.haiku-os.org/ticket/5324
We have around 3000 ports (including an old (c)go 1.4, rust, gcc, ruby, etc)
none of which have complained about a missing ucontext.h. This is kinda why I
feel like it's an anti-pattern to require it in libgo.
Even Google's go doesn't consider ucontext.h a requirement on non-bsd
platforms.
Here's the guys of our libc for context:
https://cgit.haiku-os.org/haiku/tree/headers/posix
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug go/113143] Remove usage of ucontext.h
2023-12-26 3:43 [Bug go/113143] New: Remove usage of ucontext.h kallisti5 at unixzen dot com
` (7 preceding siblings ...)
2023-12-27 3:20 ` kallisti5 at unixzen dot com
@ 2023-12-27 3:38 ` kallisti5 at unixzen dot com
2023-12-27 23:20 ` ian at airs dot com
` (2 subsequent siblings)
11 siblings, 0 replies; 13+ messages in thread
From: kallisti5 at unixzen dot com @ 2023-12-27 3:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113143
--- Comment #9 from Alexander von Gluck <kallisti5 at unixzen dot com> ---
Doing a little research, it looks like complaints of ucontext.h have come up
before multiple times:
Similar issue on OpenBSD a long time ago:
https://gcc-help.gcc.gnu.narkive.com/Xx1bResV/can-t-build-go-support-in-gcc-4-8-1-on-openbsd
muslc not supporting ucontext.h:
https://wiki.musl-libc.org/open-issues
(and a long list of google results)
I guess the root questions of this bug are:
1. Should any and all references to ucontext.h be wrapped with a HAVE macro?
(this seems to be what most folks do). Since (get/set/swap)context don't seem
to be called on non-BSD platforms, this seems possible?
2. Should libgo double down and implement processor-specific calls for each
architecture as called out by Ian in the above thread in 2013?
"It's possible to fix this by writing processor-dependent functions
that would serve the same purpose as the *context functions, and in
fact that would be more efficient. But I have not actually done this."
3. Is the expectation that all platforms which libgo targets include ucontext.h
compatibility libraries for calls no-longer standard in the posix
specifications since 2008. (muslc pushed against this... i'd be interested if
libgo compiles under musl systems)
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug go/113143] Remove usage of ucontext.h
2023-12-26 3:43 [Bug go/113143] New: Remove usage of ucontext.h kallisti5 at unixzen dot com
` (8 preceding siblings ...)
2023-12-27 3:38 ` kallisti5 at unixzen dot com
@ 2023-12-27 23:20 ` ian at airs dot com
2023-12-29 1:45 ` kallisti5 at unixzen dot com
2023-12-30 6:26 ` ian at airs dot com
11 siblings, 0 replies; 13+ messages in thread
From: ian at airs dot com @ 2023-12-27 23:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113143
--- Comment #10 from Ian Lance Taylor <ian at airs dot com> ---
The makecontext/getcontext/setcontext functions are called by libgo on
GNU/Linux for all targets other than x86_64. It is not the case that they are
used only on *BSD systems.
The default gc implementation does not require these functions because it
provides assembler code. This of course limits the gc implementation to only
support a limited number of targets: those for which the assembler code exists.
libgo is intended to be more portable.
To be clear I am fine with removing or guarding references to ucontext.h where
that makes sense. I'm just pointing out that the code can't in general work if
the *context functions are not available. It's unfortunate that POSIX removed
them without providing adequate replacements. Saying that they "can be
replaced using POSIX threads functions" is simply false. They provide a
portable mechanism for a userspace threads mechanism on top of POSIX threads.
Without them there is no way for libgo to implement goroutines efficiently.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug go/113143] Remove usage of ucontext.h
2023-12-26 3:43 [Bug go/113143] New: Remove usage of ucontext.h kallisti5 at unixzen dot com
` (9 preceding siblings ...)
2023-12-27 23:20 ` ian at airs dot com
@ 2023-12-29 1:45 ` kallisti5 at unixzen dot com
2023-12-30 6:26 ` ian at airs dot com
11 siblings, 0 replies; 13+ messages in thread
From: kallisti5 at unixzen dot com @ 2023-12-29 1:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113143
--- Comment #11 from Alexander von Gluck <kallisti5 at unixzen dot com> ---
Hm.. Could you point me to where Linux is using the (get/set/swap)context
calls? I still haven't found them in the codebase.
I don't want to miss any edge cases if I work up a patch.
^ permalink raw reply [flat|nested] 13+ messages in thread
* [Bug go/113143] Remove usage of ucontext.h
2023-12-26 3:43 [Bug go/113143] New: Remove usage of ucontext.h kallisti5 at unixzen dot com
` (10 preceding siblings ...)
2023-12-29 1:45 ` kallisti5 at unixzen dot com
@ 2023-12-30 6:26 ` ian at airs dot com
11 siblings, 0 replies; 13+ messages in thread
From: ian at airs dot com @ 2023-12-30 6:26 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113143
--- Comment #12 from Ian Lance Taylor <ian at airs dot com> ---
libgo/runtime/runtime.h:
#if defined(__x86_64__) && defined(__linux__) && !defined(__CET__)
...
#else
#define __go_context_t ucontext_t
#define __go_getcontext(c) getcontext(c)
#define __go_setcontext(c) setcontext(c)
#define __go_makecontext(c, fn, sp, size) \
((c)->uc_stack.ss_sp = sp, (c)->uc_stack.ss_size = size, makecontext(c,
fn, 0))
#endif
libgo/runtime/proc.c:
various calls to __go_getcontext, __go_setcontext, and __go_makecontext.
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2023-12-30 6:26 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-26 3:43 [Bug go/113143] New: Remove usage of ucontext.h kallisti5 at unixzen dot com
2023-12-26 3:48 ` [Bug go/113143] " kallisti5 at unixzen dot com
2023-12-26 4:48 ` ian at airs dot com
2023-12-26 13:13 ` kallisti5 at unixzen dot com
2023-12-26 23:16 ` ian at airs dot com
2023-12-27 2:31 ` kallisti5 at unixzen dot com
2023-12-27 2:34 ` kallisti5 at unixzen dot com
2023-12-27 2:40 ` pinskia at gcc dot gnu.org
2023-12-27 3:20 ` kallisti5 at unixzen dot com
2023-12-27 3:38 ` kallisti5 at unixzen dot com
2023-12-27 23:20 ` ian at airs dot com
2023-12-29 1:45 ` kallisti5 at unixzen dot com
2023-12-30 6:26 ` ian at airs dot com
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).