On 28/01/2020 05:00, Mathias Lang wrote: > Hi, > > This patch fixes GDC on s390x-linux-musl targets. It was specifically > tested under Alpine Linux (see > https://gitlab.alpinelinux.org/alpine/aports/commit/c123e0f14ab73976a36c651d47d134f249413f29 > ). > The patch fixes two issues: First, Musl always provide > `__tls_get_addr`, so we can always use it to get the TLS range instead > of the internal function (which is glibc-specific). > Second, druntime provide an ASM implementation for > `fiber_switchContext` for most platform under > libphobos/libdruntime/config/$ARCH/switchcontext.S, and default to > `swapcontext` when not available, which is the case on s390x. > However, the configure script did not depend on `swapcontext` being > present, as it's part of glibc, but not Musl (there is a libucontext > available on Alpine for this), which is added here. > > @Iain: Any chance those could be backported to v9 ? >
Thanks, I see no reason not to backport. > --- > Mathias Lang > --- > libphobos/ChangeLog: > > * libdruntime/gcc/sections/elf_shared.d Always use > __tls_get_addr on Musl. > * configure.ac: Search librairies for swapcontext when > LIBDRUNTIME_NEEDS_UCONTEXT is yes. > * configure.tgt: Set LIBDRUNTIME_NEEDS_UCONTEXT on s390*-linux*. > * configure: Regenerate. > --- > diff -Nurp a/libphobos/libdruntime/gcc/sections/elf_shared.d > b/libphobos/libdruntime/gcc/sections/elf_shared.d > --- a/libphobos/libdruntime/gcc/sections/elf_shared.d > +++ b/libphobos/libdruntime/gcc/sections/elf_shared.d > @@ -1084,7 +1084,9 @@ void[] getTLSRange(size_t mod, size_t sz) nothrow @nogc > > // base offset > auto ti = tls_index(mod, 0); > - version (IBMZ_Any) > + version (CRuntime_Musl) > + return (__tls_get_addr(&ti)-TLS_DTV_OFFSET)[0 .. sz]; > + else version (IBMZ_Any) > { > auto idx = cast(void *)__tls_get_addr_internal(&ti) > + cast(ulong)__builtin_thread_pointer(); This is fine. > diff -Nurp a/libphobos/configure.ac b/libphobos/configure.ac > --- a/libphobos/configure.ac > +++ b/libphobos/configure.ac > @@ -140,6 +140,14 @@ case ${host} in > esac > AC_MSG_RESULT($LIBPHOBOS_SUPPORTED) > > +AC_MSG_CHECKING([if target needs to link in swapcontext]) > +AC_MSG_RESULT($LIBDRUNTIME_NEEDS_UCONTEXT) > +AS_IF([test "x$LIBDRUNTIME_NEEDS_UCONTEXT" = xyes], [ > + AC_SEARCH_LIBS([swapcontext], [c ucontext], [], [ > + AC_MSG_ERROR([[can't find library providing swapcontext]]) > + ]) > +]) > + Rather than adding LIBDRUNTIME_NEEDS_UCONTEXT, couldn't you just add a one-liner AC_SEARCH_LIBS to the WITH_LOCAL_DRUNTIME list? Testing as I suggest locally, there is no problems on x86 and x86_64. Iain.