S/390: Fix PR91628
authorRobin Dapp <rdapp@linux.ibm.com>
Tue, 7 Apr 2020 19:05:38 +0000 (21:05 +0200)
committerAndreas Krebbel <krebbel@linux.ibm.com>
Tue, 7 Apr 2020 19:08:06 +0000 (21:08 +0200)
With this patch we get rid of the usage of the glibc-internal symbol
__tls_get_addr_internal.

If build with multilib, the file
gcc/libphobos/libdruntime/config/systemz/get_tls_offset.S is used
for both configurations: systemz and s390.
Therefore both implementations are now in the systemz file which
uses an "#ifdef __s390x__" in order to distinguish both cases.
The s390 file is just including the systemz one.

libphobos/ChangeLog:

2020-04-07  Robin Dapp  <rdapp@linux.ibm.com>
            Stefan Liebler  <stli@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.

libphobos/ChangeLog
libphobos/configure
libphobos/libdruntime/Makefile.am
libphobos/libdruntime/Makefile.in
libphobos/libdruntime/config/s390/get_tls_offset.S [new file with mode: 0644]
libphobos/libdruntime/config/systemz/get_tls_offset.S [new file with mode: 0644]
libphobos/libdruntime/gcc/sections/elf_shared.d
libphobos/m4/druntime/cpu.m4

index 3791d4a5ef65066199307c773ce274e05813d4a9..86468e150290b69a726889eec65577d071e235cf 100644 (file)
@@ -1,3 +1,14 @@
+2020-04-07  Robin Dapp  <rdapp@linux.ibm.com>
+           Stefan Liebler  <stli@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.
+
 2020-04-07  Stefan Liebler  <stli@linux.ibm.com>
 
        * libdruntime/core/sys/posix/signal.d:
index 9cad270b2eb7b735c08c94f34a88d3423576892e..04a6e6aeb0fabd303b6954cfa1cef1f9329e82ed 100755 (executable)
@@ -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
@@ -11644,7 +11648,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11647 "configure"
+#line 11651 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11750,7 +11754,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11753 "configure"
+#line 11757 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
       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=
@@ -14061,6 +14071,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
@@ -15561,6 +15587,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
index ef18fb14d0e68288d73195fb9c0553f42d3189d1..b6f4329906419a0f32d346a2a16c9ec054e4e975 100644 (file)
@@ -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
index 44361f9c8186490a2ef5a77f583f795170ba6ab8..cbbe6298537fcab7c0525b98829348f9724eb41b 100644 (file)
@@ -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 \
@@ -450,17 +452,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@)
@@ -729,7 +733,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
@@ -1736,6 +1741,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)
 
@@ -1756,6 +1771,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)
@@ -1876,6 +1895,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 $@ $<
 
@@ -1899,6 +1924,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
@@ -2054,6 +2081,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 (file)
index 0000000..aaca05c
--- /dev/null
@@ -0,0 +1,25 @@
+/* IBM Z support code for TLS offsets.
+   Copyright (C) 2020 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/>.  */
+
+#include "../systemz/get_tls_offset.S"
diff --git a/libphobos/libdruntime/config/systemz/get_tls_offset.S b/libphobos/libdruntime/config/systemz/get_tls_offset.S
new file mode 100644 (file)
index 0000000..e9e6dc7
--- /dev/null
@@ -0,0 +1,79 @@
+/* IBM Z support code for TLS offsets.
+   Copyright (C) 2020 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).
+
+   Note: This file is shared between systemz and s390 as the
+        same file is used in multilib case for s390x and s390.  */
+
+#include "../common/threadasm.S"
+
+    .text
+    .globl CSYM(__ibmz_get_tls_offset)
+    .type CSYM(__ibmz_get_tls_offset), @function
+    .align 8
+CSYM(__ibmz_get_tls_offset):
+    .cfi_startproc
+
+#ifdef __s390x__
+     .machinemode zarch
+     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
+#else
+    .machinemode esa
+    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
+#endif
+     .cfi_endproc
+     .size     __ibmz_get_tls_offset, .-__ibmz_get_tls_offset
index b28c8dcb9eb12e989c551dd5ec6e384d610aaee0..7ff87a8cec77f7377f78f939956b624daa98a910 100644 (file)
@@ -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];
index aa5b5ea08fc58989849b0dd4dfbe1206ef521726..4887248fd09c2f83adeb7c29be713bba835ea8d9 100644 (file)
@@ -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"])
 ])