#1050589 gcc-13: [x32] -fbuiltin-strchr miscompiles

Package:
gcc-13
Source:
gcc-13
Description:
GNU C compiler
Submitter:
Thorsten Glaser
Date:
2025-06-23 18:01:05 UTC
Severity:
normal
Tags:
#1050589#5
Date:
2023-08-26 17:46:02 UTC
From:
To:
I've got miscompiles of mksh with gcc-13 on x32 with dietlibc.

I could reproduce this in a chroot by doing…

export CC='diet -Os gcc'
export CFLAGS='-g -Wformat -Werror=format-security -Wall -Wextra'
export CPPFLAGS='-Wdate-time -D_FORTIFY_SOURCE=2 -DMKSH_BUILDMEAT'
sh Build.sh -r -j
./mksh -c 'x=q; x=${ echo a; typeset e=2; return 3; echo x$e;}; echo .$x.'

… in an mksh source tree. (Output is “..” but “.a.” was expected.)

Adding -fno-builtin-strchr to CFLAGS makes the problem go away.

This is as far as I could reduce this; more would involve diving
into the gcc internals.

#1050589#10
Date:
2023-08-26 17:57:58 UTC
From:
To:
Dixi quod…

This is a regression against gcc-12 (= 12.3.0-8); if I install that
and export CC='diet -Os gcc-12' it works.

In case this is relevant: that codepath uses setjmp/longjmp quite a bit,
and builds for glibc, musl or klibc don’t trigger this, so it’s probably
a combination of several things. Using dietlibc/amd64 is also fine, and
dietlibc-wise, they are good as identical: differ only in start.S and
syscall numbers, and a few sections in header files.

bye,
//mirabilos