[PATCH] S/390: Fix PR91628

2020-03-23 Thread Stefan Liebler via Gcc-patches

Hi,

this patch picks up Robin Dapps patch __tls_get_offset-in-separate.S.
See "Bugzilla 91628 - libdruntime uses glibc internal symbol on s390"
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91628)

The original purpose was to get rid of the usage of the glibc-internal 
symbol __tls_get_addr_internal.


The patch has not applied as is, therefore I've just regenerated the
configure and Makefiles.

Furthermore 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.

Bye,
Stefan

--

libphobos/ChangeLog:

2019-11-27  Robin Dapp  
2020-03-23  Stefan Liebler  

* 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.
commit db977cdbfc3449dfd730b639cd762588202cbb94
Author: Stefan Liebler 
Date:   Mon Mar 16 15:06:08 2020 +0100

S/390: Fix PR91628

This patch picks up Robin Dapps patch __tls_get_offset-in-separate.S.
See "Bugzilla 91628 - libdruntime uses glibc internal symbol on s390"
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91628)

The patch has not applied as is, therefore I've just regenerated the
configure and Makefiles.

Furthermore 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:

2019-11-27  Robin Dapp  
2020-03-23  Stefan Liebler  

* 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 9cad270b2eb..04a6e6aeb0f 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
@@ -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
@@ -14012,6 +14016,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=
@@ -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

[PATCH] S/390: Fix layout of struct sigaction_t

2020-03-23 Thread Stefan Liebler via Gcc-patches

Hi,

the ordering of some fields in  struct sigaction on s390x (64bit)
differs compared to s390 and other architectures.
This patch adjusts this order according to the definition of
/sysdeps/unix/sysv/linux/s390/bits/sigaction.h

Without this fix e.g. the call
sigaction( suspendSignalNumber, &sigusr1, null ) in thread.d
leads to setting the sa_restorer field to 0x.
In case a signal, the signal handler returns to this address
and the process stops with a SIGILL.

This was observable in several execution testcases on s390x:
libphobos.druntime/core/thread.d
libphobos.druntime_shared/core/thread.d
libphobos.thread/tlsgc_sections.d
libphobos.allocations/tls_gc_integration.d
libphobos.phobos/std/parallelism.d
libphobos.phobos_shared/std/parallelism.d
libphobos.shared/host.c
libphobos.shared/linkD.c
libphobos.shared/linkDR.c
libphobos.shared/link_linkdep.d
libphobos.shared/load.d
libphobos.shared/loadDR.c
libphobos.shared/load_linkdep.d
libphobos.shared/load_loaddep.d

Bye,
Stefan

--

libphobos/ChangeLog:

2020-03-23  Stefan Liebler  

* libphobos/libdruntime/core/sys/posix/signal.d:
Add struct sigaction_t for SystemZ.
commit 0986df3847c287c144b2e38d3ec1d423b934d7a8
Author: Stefan Liebler 
Date:   Tue Mar 17 17:00:44 2020 +0100

S/390: Fix layout of struct sigaction_t

The ordering of some fields in  struct sigaction on s390x (64bit)
differs compared to s390 and other architectures.
This patch adjusts this order according to the definition of
/sysdeps/unix/sysv/linux/s390/bits/sigaction.h

Without this fix e.g. the call
sigaction( suspendSignalNumber, &sigusr1, null ) in thread.d
leads to setting the sa_restorer field to 0x.
In case a signal, the signal handler returns to this address
and the process stops with a SIGILL.

This was observable in several execution testcases on s390x:
libphobos.druntime/core/thread.d
libphobos.druntime_shared/core/thread.d
libphobos.thread/tlsgc_sections.d
libphobos.allocations/tls_gc_integration.d
libphobos.phobos/std/parallelism.d
libphobos.phobos_shared/std/parallelism.d
libphobos.shared/host.c
libphobos.shared/linkD.c
libphobos.shared/linkDR.c
libphobos.shared/link_linkdep.d
libphobos.shared/load.d
libphobos.shared/loadDR.c
libphobos.shared/load_linkdep.d
libphobos.shared/load_loaddep.d

libphobos/ChangeLog:

2020-03-23  Stefan Liebler  

* libphobos/libdruntime/core/sys/posix/signal.d:
Add struct sigaction_t for SystemZ.

diff --git a/libphobos/libdruntime/core/sys/posix/signal.d b/libphobos/libdruntime/core/sys/posix/signal.d
index ed3985eee4d..5abcdac1355 100644
--- a/libphobos/libdruntime/core/sys/posix/signal.d
+++ b/libphobos/libdruntime/core/sys/posix/signal.d
@@ -575,24 +575,51 @@ else
 
 version (CRuntime_Glibc)
 {
-struct sigaction_t
+version (SystemZ)
 {
-static if ( true /* __USE_POSIX199309 */ )
+struct sigaction_t
 {
-union
+static if ( true /* __USE_POSIX199309 */ )
+{
+union
+{
+sigfn_t sa_handler;
+sigactfn_t  sa_sigaction;
+}
+}
+else
 {
 sigfn_t sa_handler;
-sigactfn_t  sa_sigaction;
 }
+int __glibc_reserved0;
+int sa_flags;
+
+void function() sa_restorer;
+
+sigset_tsa_mask;
 }
-else
+}
+else
+{
+struct sigaction_t
 {
-sigfn_t sa_handler;
-}
-sigset_tsa_mask;
-int sa_flags;
+static if ( true /* __USE_POSIX199309 */ )
+{
+union
+{
+sigfn_t sa_handler;
+sigactfn_t  sa_sigaction;
+}
+}
+else
+{
+sigfn_t sa_handler;
+}
+sigset_tsa_mask;
+int sa_flags;
 
-void function() sa_restorer;
+void function() sa_restorer;
+}
 }
 }
 else version (CRuntime_Musl)


Re: [PATCH] S/390: Fix PR91628

2020-03-31 Thread Stefan Liebler via Gcc-patches

ping

On 3/23/20 6:04 PM, Stefan Liebler wrote:

Hi,

this patch picks up Robin Dapps patch __tls_get_offset-in-separate.S.
See "Bugzilla 91628 - libdruntime uses glibc internal symbol on s390"
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91628)

The original purpose was to get rid of the usage of the glibc-internal 
symbol __tls_get_addr_internal.


The patch has not applied as is, therefore I've just regenerated the
configure and Makefiles.

Furthermore 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.

Bye,
Stefan

--

libphobos/ChangeLog:

2019-11-27  Robin Dapp  
2020-03-23  Stefan Liebler  

 * 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.




Re: [PATCH] S/390: Fix layout of struct sigaction_t

2020-03-31 Thread Stefan Liebler via Gcc-patches

ping

On 3/23/20 6:05 PM, Stefan Liebler wrote:

Hi,

the ordering of some fields in  struct sigaction on s390x (64bit)
differs compared to s390 and other architectures.
This patch adjusts this order according to the definition of
/sysdeps/unix/sysv/linux/s390/bits/sigaction.h

Without this fix e.g. the call
sigaction( suspendSignalNumber, &sigusr1, null ) in thread.d
leads to setting the sa_restorer field to 0x.
In case a signal, the signal handler returns to this address
and the process stops with a SIGILL.

This was observable in several execution testcases on s390x:
libphobos.druntime/core/thread.d
libphobos.druntime_shared/core/thread.d
libphobos.thread/tlsgc_sections.d
libphobos.allocations/tls_gc_integration.d
libphobos.phobos/std/parallelism.d
libphobos.phobos_shared/std/parallelism.d
libphobos.shared/host.c
libphobos.shared/linkD.c
libphobos.shared/linkDR.c
libphobos.shared/link_linkdep.d
libphobos.shared/load.d
libphobos.shared/loadDR.c
libphobos.shared/load_linkdep.d
libphobos.shared/load_loaddep.d

Bye,
Stefan

--

libphobos/ChangeLog:

2020-03-23  Stefan Liebler  

 * libphobos/libdruntime/core/sys/posix/signal.d:
 Add struct sigaction_t for SystemZ.




Re: [PATCH] S/390: Fix layout of struct sigaction_t

2020-04-01 Thread Stefan Liebler via Gcc-patches

On 4/1/20 12:54 PM, Iain Buclaw wrote:

On 01/04/2020 08:28, Stefan Liebler wrote:

ping



Thanks, I'll send the patch upstream, as it's the same there.

Looks OK to me.

Regards
Iain.



Thanks for committing the patch upstream



Re: [PATCH] S/390: Fix PR91628

2020-04-01 Thread Stefan Liebler via Gcc-patches

On 4/1/20 12:50 PM, Iain Buclaw wrote:



On 01/04/2020 08:28, Stefan Liebler wrote:

ping



Hi Stefan,

As I've already said, I think that the name should be __ibmz_get_tls_offset to 
make clear that it is an internal function.

Other than that, looks good to me.

Iain.



Hi Iain,

Sorry. I've missed your comment in the bugzilla.
I've updated the name to __ibmz_get_this_offset.
Nothing else is changed in the attached patch.

Please commit the patch upstream.
Do you also close the bugzilla as soon as committed?

Regarding the mentioned musl-patch in your bugzilla comment:
Yes, the diff looks like not conflicting.

Thanks,
Stefan
commit 98dd0351159449228df6069c8b9a9c2b1e31d683
Author: Stefan Liebler 
Date:   Mon Mar 16 15:06:08 2020 +0100

S/390: Fix PR91628

This patch picks up Robin Dapps patch __tls_get_offset-in-separate.S.
See "Bugzilla 91628 - libdruntime uses glibc internal symbol on s390"
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91628)

The patch has not applied as is, therefore I've just regenerated the
configure and Makefiles.

Furthermore 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:

2019-11-27  Robin Dapp  
2020-04-01  Stefan Liebler  

* 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 9cad270b2eb..04a6e6aeb0f 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
@@ -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
@@ -14012,6 +14016,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=
@@ -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
diff --git a/libphobos/libdruntime/Makefile.am b/libphobos/libdruntime/Makefile.am
index ef18fb14d0e..b6f43299064 100644
--- a/libphobos/libdruntime/Makefile.am
+++ b/libphobos/libdruntime/Makefile.am
@@ -98,6 +98,12 @@ else
 D

Re: [PATCH] S/390: Fix PR91628

2020-04-07 Thread Stefan Liebler via Gcc-patches

On 4/1/20 6:20 PM, Stefan Liebler wrote:

On 4/1/20 12:50 PM, Iain Buclaw wrote:



On 01/04/2020 08:28, Stefan Liebler wrote:

ping



Hi Stefan,

As I've already said, I think that the name should be 
__ibmz_get_tls_offset to make clear that it is an internal function.


Other than that, looks good to me.

Iain.



Hi Iain,

Sorry. I've missed your comment in the bugzilla.
I've updated the name to __ibmz_get_this_offset.
Nothing else is changed in the attached patch.

Please commit the patch upstream.
Do you also close the bugzilla as soon as committed?

Regarding the mentioned musl-patch in your bugzilla comment:
Yes, the diff looks like not conflicting.

Thanks,
Stefan


Hi Iain,

Andreas has just committed the other patch "S/390: Fix layout of struct 
sigaction_t" to gcc after your pull-request was merged 
(https://github.com/dlang/druntime/pull/3020).


To me it seems that this patch is not simply pull-request-able to 
https://github.com/dlang/druntime.
As you've already mentioned "Other than that, looks good to me.", is 
this gcc patch okay to commit from your side? Then Andreas can also 
commit it and we can close the bugzilla.


Bye,
Stefan



Re: [PATCH] fwprop: Fix single_use_p calculation

2021-03-15 Thread Stefan Liebler via Gcc-patches
On 02/03/2021 23:37, Ilya Leoshkevich wrote:
> Bootstrapped and regtested on x86_64-redhat-linux, ppc64le-redhat-linux
> and s390x-redhat-linux.  Ok for master?
> 
> 
> 
> Commit efb6bc55a93a ("fwprop: Allow (subreg (mem)) simplifications")
> introduced a check that was supposed to look at the propagated def's
> number of uses.  It uses insn_info::num_uses (), which in reality
> returns the number of uses def's insn has.  The whole change therefore
> works only by accident.
> 
> Fix by looking at def_info's uses instead of insn_info's uses.  This
> requires passing around def_info instead of insn_info.
> 

If building glibc on s390x with -march=z14, there is currently an extra
"unneeded" stackframe in e.g. sqrtl, llroundl, lroundl, llrintl, llrint
and roundevenl.

 <__ieee754_sqrtl>:
   0:   b3 c1 00 4f ldgr%f4,%r15
   4:   e3 f0 ff 50 ff 71   lay %r15,-176(%r15)
   a:   e3 00 f0 a8 00 20   cg  %r0,168(%r15)
# The long double argument is loaded ...
  10:   e7 00 30 00 30 06   vl  %v0,0(%r3),3
# ... stored to extra "unneeded" stackframe ...
  16:   e7 00 f0 a0 30 0e   vst %v0,160(%r15),3
# ... and loaded from there into a floating-point-pair
  1c:   68 00 f0 a0 ld  %f0,160(%r15)
  20:   68 20 f0 a8 ld  %f2,168(%r15)
  24:   b3 16 00 00 sqxbr   %f0,%f0
  28:   60 00 20 00 std %f0,0(%r2)
  2c:   60 20 20 08 std %f2,8(%r2)
  30:   b3 cd 00 f4 lgdr%r15,%f4
  34:   07 fe   br  %r14


With this patch, there is no stackframe in those functions anymore as it
was if build with gcc 10.

 <__ieee754_sqrtl>:
   0:   68 00 30 00 ld  %f0,0(%r3)
   4:   68 20 30 08 ld  %f2,8(%r3)
   8:   b3 16 00 00 sqxbr   %f0,%f0
   c:   60 00 20 00 std %f0,0(%r2)
  10:   60 20 20 08 std %f2,8(%r2)
  14:   07 fe   br  %r14


Thanks,
Stefan