[PATCH] s390: Fix missing early-clobber in __to_generic_vx [BZ #34952]
Stefan Liebler
stli@linux.ibm.com
Thu Nov 5 12:04:07 GMT 2026
On 11/5/26 01:13, Florian Fuchs wrote:
> R_TMP is declared as a plain output ("=d") without an early-clobber, so
> the compiler may give it the same register as one of the inputs.
>
> At -O1, GCC does so for R_BUF: the buffer address is zeroed and the
> following "vst %v16,0(%[R_I],%[R_BUF])" stores to address 0. Any
> conversion of 16 or more characters to IBM037, IBM1047 or a similar
> 8-bit charset then crashes. -O2 and -Os happen to allocate different
> registers.
>
> Mark R_TMP as early-clobber ("=&d"), like R_I in the same asm.
>
> Reproducer, when glibc built with -O1:
>
> head -c16 /dev/zero | tr '\0' A | iconv -f UTF-8 -t IBM1047
>
> Tested on s390x with glibc built with -O1: the reproducer above
> crashes without this change and works with it.
>
> Signed-off-by: Florian Fuchs <fuchsfl@gmail.com>
> ---
> Issue was hit, while building s390-tools with an -O1 glibc: GCC with
> -fexec-charset=IBM1047 crashed with an internal compiler error in
> iconv. cmdline that reproduces the gcc ice:
>
> echo 'const char *s = "Start subchannel failed";' | \
> gcc -fexec-charset=IBM1047 -x c -c - -o /dev/null
>
> sysdeps/s390/multiarch/8bit-generic.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/sysdeps/s390/multiarch/8bit-generic.c b/sysdeps/s390/multiarch/8bit-generic.c
> index 8224cec557..18671a8775 100644
> --- a/sysdeps/s390/multiarch/8bit-generic.c
> +++ b/sysdeps/s390/multiarch/8bit-generic.c
> @@ -266,7 +266,7 @@
> ".machine pop" \
> : /* outputs */ [R_IN] "+a" (inptr) \
> , [R_I] "=&a" (index) \
> - , [R_TMP] "=d" (tmp) \
> + , [R_TMP] "=&d" (tmp) \
> , [R_LI] "+d" (remaining_loop_count) \
> : /* inputs */ [R_BUF] "a" (buf) \
> , [R_MAX] "d" (max) \
Hi Florian,
many thanks for the bug-report and the fix. You are absolute right, I
also see the described register usages with -O1. With marking R_TMP as
early clobber, different registers are used and the reproducer "head
-c16 /dev/zero | tr '\0' A | iconv -f UTF-8 -t IBM1047" is fixed with an
-O1 build.
I've already double checked the remaining inline-assemblies in
8bit-generic.c for similar issues and will check the remaining
s390x-inline-assemblies.
Reviewed-by: Stefan Liebler <stli@linux.ibm.com>
More information about the Libc-alpha
mailing list