s390: Fix missing early-clobber in __to_generic_vx [BZ #34952]

Message ID 20261105001354.1471049-1-fuchsfl@gmail.com (mailing list archive)
State Committed
Commit ff45d05f8b0f3c8f576b2d3992263aad06488d40
Headers
Series s390: Fix missing early-clobber in __to_generic_vx [BZ #34952] |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Test passed
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 fail Patch failed to apply
redhat-pt-bot/TryBot-32bit success Build for i686

Commit Message

Florian Fuchs Nov. 5, 2026, 12:13 a.m. UTC
  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(-)
  

Comments

Stefan Liebler Nov. 5, 2026, 12:04 p.m. UTC | #1
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>
  
Stefan Liebler Nov. 5, 2026, 12:12 p.m. UTC | #2
On 11/5/26 13:04, Stefan Liebler wrote:
> 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>
Committed and also closed the bug (If there are still issues. Please
reopen again).

Thanks,
Stefan
  

Patch

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)				\