This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] [dlang/phobos] S/390: Fix PR91628


Hi,

in order to not use a glibc-internal symbol anymore, this patch adds
separate .S files for s390x and s390 that allow to obtain the tls offset.

I bootstrapped on s390x -m64 and -m31 and test on s390x, s390 seeing no
new regressions.

Regards
 Robin

--

libphobos/ChangeLog:

2019-11-27  Robin Dapp  <rdapp@linux.ibm.com>

	* configure: Regenerate.
	* libdruntime/Makefile.am: Add s390x and s390.
	* libdruntime/Makefile.in: Regenerate.
	* libdruntime/config/s390/get_tls_offset.S: New file.
	* libdruntime/config/systemz/get_tls_offset.S: New file.
	* libdruntime/gcc/sections/elf_shared.d: Use ibmz_get_tls_offset.
	* m4/druntime/cpu.m4: Add s390x and s390.
diff --git a/libphobos/configure b/libphobos/configure
index fde2af90c44..3ecb286dd23 100755
--- a/libphobos/configure
+++ b/libphobos/configure
@@ -683,6 +683,10 @@ DRUNTIME_OS_AIX_FALSE
 DRUNTIME_OS_AIX_TRUE
 DRUNTIME_OS_UNIX_FALSE
 DRUNTIME_OS_UNIX_TRUE
+DRUNTIME_CPU_S390_FALSE
+DRUNTIME_CPU_S390_TRUE
+DRUNTIME_CPU_SYSTEMZ_FALSE
+DRUNTIME_CPU_SYSTEMZ_TRUE
 DRUNTIME_CPU_X86_FALSE
 DRUNTIME_CPU_X86_TRUE
 DRUNTIME_CPU_POWERPC64_FALSE
@@ -14008,6 +14012,12 @@ fi
       i[34567]86|x86_64)
                druntime_target_cpu_parsed="x86"
                ;;
+      s390x)
+               druntime_target_cpu_parsed="s390x"
+               ;;
+      s390)
+               druntime_target_cpu_parsed="s390"
+               ;;
   esac
    if test "$druntime_target_cpu_parsed" = "aarch64"; then
   DRUNTIME_CPU_AARCH64_TRUE=
@@ -14057,6 +14067,22 @@ else
   DRUNTIME_CPU_X86_FALSE=
 fi
 
+   if test "$druntime_target_cpu_parsed" = "s390x"; then
+  DRUNTIME_CPU_SYSTEMZ_TRUE=
+  DRUNTIME_CPU_SYSTEMZ_FALSE='#'
+else
+  DRUNTIME_CPU_SYSTEMZ_TRUE='#'
+  DRUNTIME_CPU_SYSTEMZ_FALSE=
+fi
+
+   if test "$druntime_target_cpu_parsed" = "s390"; then
+  DRUNTIME_CPU_S390_TRUE=
+  DRUNTIME_CPU_S390_FALSE='#'
+else
+  DRUNTIME_CPU_S390_TRUE='#'
+  DRUNTIME_CPU_S390_FALSE=
+fi
+
 
 
   { $as_echo "$as_me:${as_lineno-$LINENO}: checking for target OS" >&5
@@ -15534,6 +15560,14 @@ if test -z "${DRUNTIME_CPU_X86_TRUE}" && test -z "${DRUNTIME_CPU_X86_FALSE}"; th
   as_fn_error $? "conditional \"DRUNTIME_CPU_X86\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
 fi
+if test -z "${DRUNTIME_CPU_SYSTEMZ_TRUE}" && test -z "${DRUNTIME_CPU_SYSTEMZ_FALSE}"; then
+  as_fn_error $? "conditional \"DRUNTIME_CPU_SYSTEMZ\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
+if test -z "${DRUNTIME_CPU_S390_TRUE}" && test -z "${DRUNTIME_CPU_S390_FALSE}"; then
+  as_fn_error $? "conditional \"DRUNTIME_CPU_S390\" was never defined.
+Usually this means the macro was only invoked conditionally." "$LINENO" 5
+fi
 if test -z "${DRUNTIME_OS_UNIX_TRUE}" && test -z "${DRUNTIME_OS_UNIX_FALSE}"; then
   as_fn_error $? "conditional \"DRUNTIME_OS_UNIX\" was never defined.
 Usually this means the macro was only invoked conditionally." "$LINENO" 5
diff --git a/libphobos/libdruntime/Makefile.am b/libphobos/libdruntime/Makefile.am
index d3fc347e2d0..addaf3c9638 100644
--- a/libphobos/libdruntime/Makefile.am
+++ b/libphobos/libdruntime/Makefile.am
@@ -98,6 +98,12 @@ else
     DRUNTIME_SOURCES_CONFIGURED += config/x86/switchcontext.S
 endif
 endif
+if DRUNTIME_CPU_SYSTEMZ
+    DRUNTIME_SOURCES_CONFIGURED += config/systemz/get_tls_offset.S
+endif
+if DRUNTIME_CPU_S390
+    DRUNTIME_SOURCES_CONFIGURED += config/s390/get_tls_offset.S
+endif
 
 # Provide __start_minfo, __stop_minfo if linker doesn't.
 if !DRUNTIME_OS_MINFO_BRACKETING
diff --git a/libphobos/libdruntime/Makefile.in b/libphobos/libdruntime/Makefile.in
index aaf05b534d8..508cb30421c 100644
--- a/libphobos/libdruntime/Makefile.in
+++ b/libphobos/libdruntime/Makefile.in
@@ -130,6 +130,8 @@ target_triplet = @target@
 @DRUNTIME_CPU_POWERPC64_TRUE@am__append_17 = config/powerpc64/callwithstack.S
 @DRUNTIME_CPU_X86_TRUE@@DRUNTIME_OS_MINGW_TRUE@am__append_18 = config/mingw/switchcontext.S
 @DRUNTIME_CPU_X86_TRUE@@DRUNTIME_OS_MINGW_FALSE@am__append_19 = config/x86/switchcontext.S
+@DRUNTIME_CPU_SYSTEMZ_TRUE@am__append_20 = config/systemz/get_tls_offset.S
+@DRUNTIME_CPU_S390_TRUE@am__append_21 = config/s390/get_tls_offset.S
 subdir = libdruntime
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
 am__aclocal_m4_deps = $(top_srcdir)/../config/acx.m4 \
@@ -449,17 +451,19 @@ am__objects_25 = core/sys/solaris/dlfcn.lo core/sys/solaris/elf.lo \
 @DRUNTIME_CPU_POWERPC64_TRUE@am__objects_31 = config/powerpc64/libgdruntime_la-callwithstack.lo
 @DRUNTIME_CPU_X86_TRUE@@DRUNTIME_OS_MINGW_TRUE@am__objects_32 = config/mingw/libgdruntime_la-switchcontext.lo
 @DRUNTIME_CPU_X86_TRUE@@DRUNTIME_OS_MINGW_FALSE@am__objects_33 = config/x86/libgdruntime_la-switchcontext.lo
-am__objects_34 = $(am__objects_4) $(am__objects_6) $(am__objects_8) \
+@DRUNTIME_CPU_SYSTEMZ_TRUE@am__objects_34 = config/systemz/libgdruntime_la-get_tls_offset.lo
+@DRUNTIME_CPU_S390_TRUE@am__objects_35 = config/s390/libgdruntime_la-get_tls_offset.lo
+am__objects_36 = $(am__objects_4) $(am__objects_6) $(am__objects_8) \
 	$(am__objects_10) $(am__objects_12) $(am__objects_14) \
 	$(am__objects_16) $(am__objects_18) $(am__objects_20) \
 	$(am__objects_22) $(am__objects_24) $(am__objects_26) \
 	$(am__objects_27) $(am__objects_28) $(am__objects_29) \
 	$(am__objects_30) $(am__objects_31) $(am__objects_32) \
-	$(am__objects_33)
-am__objects_35 = gcc/config.lo gcc/libbacktrace.lo
-am__objects_36 = $(am__objects_1) $(am__objects_2) $(am__objects_34) \
-	$(am__objects_35)
-am_libgdruntime_la_OBJECTS = $(am__objects_36)
+	$(am__objects_33) $(am__objects_34) $(am__objects_35)
+am__objects_37 = gcc/config.lo gcc/libbacktrace.lo
+am__objects_38 = $(am__objects_1) $(am__objects_2) $(am__objects_36) \
+	$(am__objects_37)
+am_libgdruntime_la_OBJECTS = $(am__objects_38)
 libgdruntime_la_OBJECTS = $(am_libgdruntime_la_OBJECTS)
 AM_V_P = $(am__v_P_@AM_V@)
 am__v_P_ = $(am__v_P_@AM_DEFAULT_V@)
@@ -728,7 +732,8 @@ DRUNTIME_SOURCES_CONFIGURED = $(am__append_1) $(am__append_2) \
 	$(am__append_9) $(am__append_10) $(am__append_11) \
 	$(am__append_12) $(am__append_13) $(am__append_14) \
 	$(am__append_15) $(am__append_16) $(am__append_17) \
-	$(am__append_18) $(am__append_19)
+	$(am__append_18) $(am__append_19) $(am__append_20) \
+	$(am__append_21)
 
 # Provide __start_minfo, __stop_minfo if linker doesn't.
 @DRUNTIME_OS_MINFO_BRACKETING_FALSE@DRTSTUFF = gcc/drtbegin.o gcc/drtend.o
@@ -1735,6 +1740,16 @@ config/x86/$(am__dirstamp):
 	@: > config/x86/$(am__dirstamp)
 config/x86/libgdruntime_la-switchcontext.lo:  \
 	config/x86/$(am__dirstamp)
+config/systemz/$(am__dirstamp):
+	@$(MKDIR_P) config/systemz
+	@: > config/systemz/$(am__dirstamp)
+config/systemz/libgdruntime_la-get_tls_offset.lo:  \
+	config/systemz/$(am__dirstamp)
+config/s390/$(am__dirstamp):
+	@$(MKDIR_P) config/s390
+	@: > config/s390/$(am__dirstamp)
+config/s390/libgdruntime_la-get_tls_offset.lo:  \
+	config/s390/$(am__dirstamp)
 gcc/config.lo: gcc/$(am__dirstamp)
 gcc/libbacktrace.lo: gcc/$(am__dirstamp)
 
@@ -1755,6 +1770,10 @@ mostlyclean-compile:
 	-rm -f config/powerpc/*.lo
 	-rm -f config/powerpc64/*.$(OBJEXT)
 	-rm -f config/powerpc64/*.lo
+	-rm -f config/s390/*.$(OBJEXT)
+	-rm -f config/s390/*.lo
+	-rm -f config/systemz/*.$(OBJEXT)
+	-rm -f config/systemz/*.lo
 	-rm -f config/x86/*.$(OBJEXT)
 	-rm -f config/x86/*.lo
 	-rm -f core/*.$(OBJEXT)
@@ -1875,6 +1894,12 @@ config/mingw/libgdruntime_la-switchcontext.lo: config/mingw/switchcontext.S
 config/x86/libgdruntime_la-switchcontext.lo: config/x86/switchcontext.S
 	$(AM_V_CPPAS)$(LIBTOOL) $(AM_V_lt) $(libgdruntime_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CCAS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CCASFLAGS) $(CCASFLAGS) -c -o config/x86/libgdruntime_la-switchcontext.lo `test -f 'config/x86/switchcontext.S' || echo '$(srcdir)/'`config/x86/switchcontext.S
 
+config/systemz/libgdruntime_la-get_tls_offset.lo: config/systemz/get_tls_offset.S
+	$(AM_V_CPPAS)$(LIBTOOL) $(AM_V_lt) $(libgdruntime_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CCAS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CCASFLAGS) $(CCASFLAGS) -c -o config/systemz/libgdruntime_la-get_tls_offset.lo `test -f 'config/systemz/get_tls_offset.S' || echo '$(srcdir)/'`config/systemz/get_tls_offset.S
+
+config/s390/libgdruntime_la-get_tls_offset.lo: config/s390/get_tls_offset.S
+	$(AM_V_CPPAS)$(LIBTOOL) $(AM_V_lt) $(libgdruntime_la_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CCAS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CCASFLAGS) $(CCASFLAGS) -c -o config/s390/libgdruntime_la-get_tls_offset.lo `test -f 'config/s390/get_tls_offset.S' || echo '$(srcdir)/'`config/s390/get_tls_offset.S
+
 .c.o:
 	$(AM_V_CC)$(COMPILE) -c -o $@ $<
 
@@ -1898,6 +1923,8 @@ clean-libtool:
 	-rm -rf config/mips/.libs config/mips/_libs
 	-rm -rf config/powerpc/.libs config/powerpc/_libs
 	-rm -rf config/powerpc64/.libs config/powerpc64/_libs
+	-rm -rf config/s390/.libs config/s390/_libs
+	-rm -rf config/systemz/.libs config/systemz/_libs
 	-rm -rf config/x86/.libs config/x86/_libs
 	-rm -rf core/.libs core/_libs
 	-rm -rf core/internal/.libs core/internal/_libs
@@ -2053,6 +2080,8 @@ distclean-generic:
 	-rm -f config/mips/$(am__dirstamp)
 	-rm -f config/powerpc/$(am__dirstamp)
 	-rm -f config/powerpc64/$(am__dirstamp)
+	-rm -f config/s390/$(am__dirstamp)
+	-rm -f config/systemz/$(am__dirstamp)
 	-rm -f config/x86/$(am__dirstamp)
 	-rm -f core/$(am__dirstamp)
 	-rm -f core/internal/$(am__dirstamp)
diff --git a/libphobos/libdruntime/config/s390/get_tls_offset.S b/libphobos/libdruntime/config/s390/get_tls_offset.S
new file mode 100644
index 00000000000..d8ff5e1f80f
--- /dev/null
+++ b/libphobos/libdruntime/config/s390/get_tls_offset.S
@@ -0,0 +1,60 @@
+/* IBM Z support code for TLS offsets.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+/* __tls_get_offset expects the GOT pointer in %r12 and adds
+   it to its argument in %r2.  In order to get the offset of
+   ti, we load it into %r2, subtract the current %r12 from %r2
+   so the addition will result in a nop (%r2 - %r12 + %r12).  */
+
+#include "../common/threadasm.S"
+
+    .text
+    .globl CSYM(ibmz_get_tls_offset)
+    .type CSYM(ibmz_get_tls_offset), @function
+    .machinemode esa
+    .align 8
+CSYM(ibmz_get_tls_offset):
+    .cfi_startproc
+
+    stm	%r12,%r15,48(%r15)
+    .cfi_offset 12, -48
+    .cfi_offset 13, -44
+    .cfi_offset 14, -40
+    .cfi_offset 15, -36
+    ahi	%r15,-96
+    .cfi_def_cfa_offset 192
+    larl	%r12,_GLOBAL_OFFSET_TABLE_
+    sr		%r2,%r12
+    brasl	%r14,__tls_get_offset@PLT
+    l		%r4,152(%r15)
+    lm		%r12,%r15,144(%r15)
+    .cfi_restore 15
+    .cfi_restore 14
+    .cfi_restore 13
+    .cfi_restore 12
+    .cfi_def_cfa_offset 96
+    br	%r4
+
+    .cfi_endproc
+    .size	ibmz_get_tls_offset, .-ibmz_get_tls_offset
diff --git a/libphobos/libdruntime/config/systemz/get_tls_offset.S b/libphobos/libdruntime/config/systemz/get_tls_offset.S
new file mode 100644
index 00000000000..e58c93fa008
--- /dev/null
+++ b/libphobos/libdruntime/config/systemz/get_tls_offset.S
@@ -0,0 +1,55 @@
+/* IBM Z support code for TLS offsets.
+   Copyright (C) 2019 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
+<http://www.gnu.org/licenses/>.  */
+
+/* __tls_get_offset expects the GOT pointer in %r12 and adds
+   it to its argument in %r2.  In order to get the offset of
+   ti, we load it into %r2, subtract the current %r12 from %r2
+   so the addition will result in a nop (%r2 - %r12 + %r12).  */
+
+#include "../common/threadasm.S"
+
+    .text
+    .globl CSYM(ibmz_get_tls_offset)
+    .type CSYM(ibmz_get_tls_offset), @function
+    .machinemode zarch
+    .align 8
+CSYM(ibmz_get_tls_offset):
+    .cfi_startproc
+
+    stmg	%r14,%r15,112(%r15)
+    .cfi_offset 14, -48
+    .cfi_offset 15, -40
+    aghi	%r15,-160
+    .cfi_def_cfa_offset 320
+    sgr	%r2,%r12
+    brasl	%r14,__tls_get_offset@PLT
+    lg		%r4,272(%r15)
+    lmg	%r14,%r15,272(%r15)
+    .cfi_restore 15
+    .cfi_restore 14
+    .cfi_def_cfa_offset 160
+    br	%r4
+
+    .cfi_endproc
+    .size	ibmz_get_tls_offset, .-ibmz_get_tls_offset
diff --git a/libphobos/libdruntime/gcc/sections/elf_shared.d b/libphobos/libdruntime/gcc/sections/elf_shared.d
index 7f9036bf505..57d635dc6b6 100644
--- a/libphobos/libdruntime/gcc/sections/elf_shared.d
+++ b/libphobos/libdruntime/gcc/sections/elf_shared.d
@@ -1028,7 +1028,7 @@ struct tls_index
 }
 
 extern(C) void* __tls_get_addr(tls_index* ti) nothrow @nogc;
-extern(C) void* __tls_get_addr_internal(tls_index* ti) nothrow @nogc;
+extern(C) void* ibmz_get_tls_offset(tls_index *ti) nothrow @nogc;
 
 /* The dynamic thread vector (DTV) pointers may point 0x8000 past the start of
  * each TLS block. This is at least true for PowerPC and Mips platforms.
@@ -1086,9 +1086,11 @@ void[] getTLSRange(size_t mod, size_t sz) nothrow @nogc
         auto ti = tls_index(mod, 0);
         version (IBMZ_Any)
         {
-            auto idx = cast(void *)__tls_get_addr_internal(&ti)
-                + cast(ulong)__builtin_thread_pointer();
-            return idx[0 .. sz];
+            // IBM Z only provides __tls_get_offset instead of __tls_get_addr
+            // which returns an offset relative to the thread pointer.
+            auto addr = ibmz_get_tls_offset(&ti);
+            addr = addr + cast(c_ulong)__builtin_thread_pointer();
+            return addr[0 .. sz];
         }
         else
             return (__tls_get_addr(&ti)-TLS_DTV_OFFSET)[0 .. sz];
diff --git a/libphobos/m4/druntime/cpu.m4 b/libphobos/m4/druntime/cpu.m4
index aa5b5ea08fc..4887248fd09 100644
--- a/libphobos/m4/druntime/cpu.m4
+++ b/libphobos/m4/druntime/cpu.m4
@@ -25,6 +25,12 @@ AC_DEFUN([DRUNTIME_CPU_SOURCES],
       i[[34567]]86|x86_64)
                druntime_target_cpu_parsed="x86"
                ;;
+      s390x)
+               druntime_target_cpu_parsed="s390x"
+               ;;
+      s390)
+               druntime_target_cpu_parsed="s390"
+               ;;
   esac
   AM_CONDITIONAL([DRUNTIME_CPU_AARCH64],
                  [test "$druntime_target_cpu_parsed" = "aarch64"])
@@ -38,6 +44,10 @@ AC_DEFUN([DRUNTIME_CPU_SOURCES],
                  [test "$druntime_target_cpu_parsed" = "powerpc64"])
   AM_CONDITIONAL([DRUNTIME_CPU_X86],
                  [test "$druntime_target_cpu_parsed" = "x86"])
+  AM_CONDITIONAL([DRUNTIME_CPU_SYSTEMZ],
+                 [test "$druntime_target_cpu_parsed" = "s390x"])
+  AM_CONDITIONAL([DRUNTIME_CPU_S390],
+                 [test "$druntime_target_cpu_parsed" = "s390"])
 ])
 
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]