aboutsummaryrefslogtreecommitdiffstats
path: root/main/gcc/403-dlang-ibmz.patch
blob: f6f9a2ce0ca80af5abfd4578687555abe909ca25 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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	2020-01-01 00:00:00.000000000 +0900
+++ b/libphobos/libdruntime/gcc/sections/elf_shared.d	2020-01-01 00:00:00.000000000 +0900
@@ -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	2020-01-01 00:00:00.000000000 +0900
+++ b/libphobos/configure.ac	2020-01-01 00:00:00.000000000 +0900
@@ -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	2020-01-01 00:00:00.000000000 +0900
+++ b/libphobos/configure.tgt	2020-01-01 00:00:00.000000000 +0900
@@ -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/
+LIBPHOBOS_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
diff -Nurp a/libphobos/configure b/libphobos/configure
--- a/libphobos/configure	2020-01-01 00:00:00.000000000 +0900
+++ b/libphobos/configure	2020-01-01 00:00:00.000000000 +0900
@@ -13955,6 +13955,76 @@ esac
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIBPHOBOS_SUPPORTED" >&5
 $as_echo "$LIBPHOBOS_SUPPORTED" >&6; }

+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if target needs to link in swapcontext" >&5
+$as_echo_n "checking if target needs to link in swapcontext... " >&6; }
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $LIBDRUNTIME_NEEDS_UCONTEXT" >&5
+$as_echo "$LIBDRUNTIME_NEEDS_UCONTEXT" >&6; }
+if test "x$LIBDRUNTIME_NEEDS_UCONTEXT" = xyes; then :
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing swapcontext" >&5
+$as_echo_n "checking for library containing swapcontext... " >&6; }
+if ${ac_cv_search_swapcontext+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char swapcontext ();
+int
+main ()
+{
+return swapcontext ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' c ucontext; do
+  if test -z "$ac_lib"; then
+    ac_res="none required"
+  else
+    ac_res=-l$ac_lib
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_search_swapcontext=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext
+  if ${ac_cv_search_swapcontext+:} false; then :
+  break
+fi
+done
+if ${ac_cv_search_swapcontext+:} false; then :
+
+else
+  ac_cv_search_swapcontext=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_swapcontext" >&5
+$as_echo "$ac_cv_search_swapcontext" >&6; }
+ac_res=$ac_cv_search_swapcontext
+if test "$ac_res" != no; then :
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+else
+
+	as_fn_error $? "can't find library providing swapcontext" "$LINENO" 5
+
+fi
+
+
+fi
+
+
 # Decide if it's usable.
 case $LIBPHOBOS_SUPPORTED:$enable_libphobos in
 *:no)  use_libphobos=no  ;;