Miscompilation on arm64 with GCC LTO

Arsen Arsenović arsen at gentoo.org
Mon May 8 15:27:36 CEST 2023


Afternoon,

I'm forwarding a message from Sam James, a fellow Gentoo developer, as
he seems to be having some mail delivery issues.  The text of his bug
report follows:

------------------------ 8< ------------------------

Hello,

Note that this has been reported twice before [0][1] but I think I've
got a more specific test case.

This was reported in Gentoo [2] as well.

gmp-6.2.1 when built with gcc 12/13/14 (trunk as of today) combined with
-O2 -flto or -O3 -flto is miscompiled, causing a few issues:
1. `make check` for gmp fails the 't-constants' test
2. gcc itself ICEs with a trivial command [3]
```echo hi | aarch64-unknown-linux-gnu-gcc -E -dM -```
3. gcc hangs with a trivial command:
```echo hi | aarch64-unknown-linux-gnu-gfortran -Werror -xf77 -v -c -```

With regard to command 1 above:
```
# cat t-constants.log
Aborted (core dumped)
FAIL t-constants (exit status: 134)
```

and:
```
# ./t-constants
PP_INVERTED == 21cfe6cfc938b36b, but pp_inverted_calc ==
20f8c8b59d4cb9bc

After gmp.h,
ULONG_MAX  defined
LONG_MAX   defined
UINT_MAX   defined
INT_MAX    defined
USHRT_MAX  defined
SHRT_MAX   defined

ULONG_MAX      FFFFFFFFFFFFFFFF
ULONG_HIGHBIT  8000000000000000
LONG_MAX       7FFFFFFFFFFFFFFF
LONG_MIN       8000000000000000
UINT_MAX       FFFFFFFF
UINT_HIGHBIT   80000000
INT_MAX        7FFFFFFF
INT_MIN        80000000
USHRT_MAX      FFFF
USHRT_HIGHBIT  8000
SHRT_MAX       7FFF
SHRT_MIN       FFFF8000

Bits
long           64
int            32
short          16
unsigned long  64
unsigned int   32
unsigned short 16
mp_size_t      64
Aborted (core dumped)
```

... with backtrace:
```
Program received signal SIGABRT, Aborted.
0x0000fffff7df0224 in ?? () from /usr/lib64/libc.so.6
(gdb) bt
#0  0x0000fffff7df0224 in ?? () from /usr/lib64/libc.so.6
#1  0x0000fffff7daa03c in raise () from /usr/lib64/libc.so.6
#2  0x0000fffff7d96664 in abort () from /usr/lib64/libc.so.6
#3  0x0000aaaaaaaa0bd8 in main (argc=<optimized out>, argv=<optimized out>) at /var/tmp/portage/dev-libs/gmp-6.2.1-r5/work/gmp-6.2.1/tests/t-constants.c:340
(gdb)
```

When GCC hangs in command 3 above, strace shows no activity & the
backtrace from attaching gdb is at https://dev.gentoo.org/~sam/bugs/gmp/arm64-lto/configure.txt.

Note that Jannik identified the bad commit [0] as 18082:c5d0fcb06969 [4].

System information:
```
$ ./config.guess
aarch64-unknown-linux-gnu
$ ./configfsf.guess
aarch64-unknown-linux-gnu
$ uname -a
Linux arm64-20230425-unstable 5.15.64-gentoo-dist #1 SMP Wed Aug 31 17:57:10 -00 2022 aarch64 GNU/Linux 
$ gcc --version
gcc (Gentoo 13.1.0-r1 p1) 13.1.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is
NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
```

configure output:
https://dev.gentoo.org/~sam/bugs/gmp/arm64-lto/configure.txt.

I built with ./configure --enable-assembly CFLAGS="-O2 -flto"
CXXFLAGS="-O2 -flto" from the gmp-6.2.1.tar.lz tarball then ran
'make' and 'make check' to reproduce.

[0] https://gmplib.org/list-archives/gmp-bugs/2020-December/004981.html
[1] https://gmplib.org/list-archives/gmp-bugs/2023-January/005223.html
[3] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109765
[4] https://gmplib.org/repo/gmp/rev/c5d0fcb06969
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 251 bytes
Desc: not available
URL: <https://gmplib.org/list-archives/gmp-bugs/attachments/20230508/42a3207a/attachment.bin>


More information about the gmp-bugs mailing list