[PATCH, libphobos] Fix compilation dependencies on s390x-linux-musl
Mathias Lang
perso.mathias.lang@gmail.com
Tue Jan 28 07:20:00 GMT 2020
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 ?
---
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();
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]])
+ ])
+])
+
# Decide if it's usable.
case $LIBPHOBOS_SUPPORTED:$enable_libphobos in
*:no) use_libphobos=no ;;
diff -Nurp a/libphobos/configure.tgt b/libphobos/configure.tgt
--- a/libphobos/configure.tgt
+++ b/libphobos/configure.tgt
@@ -22,6 +22,13 @@
# Disable the libphobos or libdruntime components on untested or known
# broken systems. More targets shall be added after testing.
LIBPHOBOS_SUPPORTED=no
+
+# Check if we require 'ucontext' or if we have a custom solution.
+# Most platform uses a custom assembly solution for context switches,
+# see `core.thread` and grep for `AsmExternal`.
+# Definitions are in config/ARCH/
+LIBDRUNTIME_NEEDS_UCONTEXT=no
+
case "${target}" in
aarch64*-*-linux*)
LIBPHOBOS_SUPPORTED=yes
@@ -37,6 +44,7 @@ case "${target}" in
;;
s390*-linux*)
LIBPHOBOS_SUPPORTED=yes
+ LIBDRUNTIME_NEEDS_UCONTEXT=yes
;;
x86_64-*-kfreebsd*-gnu | i?86-*-kfreebsd*-gnu)
LIBPHOBOS_SUPPORTED=yes
More information about the Gcc-patches
mailing list