Created attachment 847690 [details]
I've found the problem related to GCC LTO optimization for GMP for ARM aarch64
under QEMU with ARM Neoverse-N1 virt-4.2 (Oracle Cloud) and ARM virt-7.2 (Apple M1)
both running the latest Gentoo with gmp-6.2.1-r5 compiled by both
gcc version 11.3.1 20221209 and gcc version 12.2.1 20221231.
1. Compile GMP with LTO optimization -- compiles OK
2. Try to compile iproute2-6.1.0 or cmake-3.25.1 -- compilation hangs during the process
Disabling LTO optimization for GMP solves the problem.
- Please share the full iproute2 log up until the point it hangs, ditto CMake.
- If you take a fresh stage3 then compile GMP with LTO, is that sufficient to then make building iproute2 or CMake hang?
Created attachment 847840 [details]
That's my bug report to gmp-bugs at gmplib.org:
--- report starts ---
Let me try to reproduce the whole process with original GMP source:
1. I've downloaded https://gmplib.org/download/gmp/gmp-6.2.1.tar.xz
2. Exported my CFLAGS with LTO enabled:
export COMMON_FLAGS="-O3 -march=native -mcpu=native -pipe -funroll-loops \
-fomit-frame-pointer -fforce-addr -ftracer -fno-stack-protector -flto"
3. Configure, make & install GMP with gcc version 12.2.1 20221231:
./configure --prefix=/usr/ --libdir=/usr/lib64/ --enable-cxx
4. Cloned iproute2:
git clone git://git.kernel.org/pub/scm/network/iproute2/iproute2.git
5. Try to compile iproute2 with hang as follows:
... hangs here ...
6. Commented out the following piece of iproute2 code in tc/tc_estimator.c:
// if (A/(-log(w)) > time_const)
7. Continued to compile iproute2 and compilation went OK
Same error was reproduced with current https://gmplib.org/repo/gmp-6.2/
Switching off LTO let iproute2 compile OK
--- report ends ---
AFAIK that's not only causing problems with iproute2/cmake but with any other packages (e.g.: dev-libs/liblinear) using some portion of math of GMP lib.
My current Gentoo is based on stage3-arm64-openrc-20230101T231658Z, all others packages are up to date, please check the attached `portage_all_installed` for all packages with their current versions.
As I retried to recompile iproute2 for collecting all the logs, I've found out
that it started to compile OK. However other packages (liblinear & cmake) hang
during the compilation.
Please find `liblinear.emerge.log` & `cmake.emerge.log` attached.
Created attachment 847842 [details]
Created attachment 847844 [details]
As I've just researched iproute2 started to compile since I had upgraded
dev-libs/mpfr from 4.1.1_p1 to 4.2.0, however dev-libs/liblinear-243 and
dev-util/cmake-3.25.1 still hang
As Torbjörn Granlund from gmplib.org answered:
Unfortunately, I don't have time to isolate this problem.
I long shot would be to disable assembly in the GMP build (by means of
.../configure --disable-assembly). The arm64 asm in GMP 6.2.1 followed
the ABI docs of the time, which turned out to cause problems at least in
However enabling --disable-assembly didn't solve the problem.
(In reply to Sam James from comment #1)
> - If you take a fresh stage3 then compile GMP with LTO, is that sufficient
> to then make building iproute2 or CMake hang?
What about this? (You would do it in a chroot in /tmp or something.)
Also, please try minimise precisely which CFLAGS cause it. Is it just "-O3 -flto", for example?
Sorry, I was mistaken so further research showed that
`configure --disable-assembly` solves the problem.
(In reply to Sam James from comment #8)
> (In reply to Sam James from comment #1)
> > - If you take a fresh stage3 then compile GMP with LTO, is that sufficient
> > to then make building iproute2 or CMake hang?
> What about this? (You would do it in a chroot in /tmp or something.)
> Also, please try minimise precisely which CFLAGS cause it. Is it just "-O3
> -flto", for example?
Pure CFLAGS `-O2 -flto` and `-Os -flto` for GMP leads to hang with liblinear's
compilation, except if GMP is configured with `--disable-assembly`
See also https://gmplib.org/list-archives/gmp-bugs/2020-December/004981.html.
The bug has been referenced in the following commit(s):
Author: Sam James <firstname.lastname@example.org>
AuthorDate: 2023-05-07 23:53:29 +0000
Commit: Sam James <email@example.com>
CommitDate: 2023-05-07 23:53:49 +0000
dev-libs/gmp: strip-flags & filter-lto for miscompilation
Miscompiled on arm64 with LTO at least. strip-flags as well because gmp is so
brittle (see e.g. the past configure mess).
Signed-off-by: Sam James <firstname.lastname@example.org>
dev-libs/gmp/gmp-6.2.1-r2.ebuild | 5 +++++
dev-libs/gmp/gmp-6.2.1-r5.ebuild | 5 +++++
2 files changed, 10 insertions(+)
I think I can hit this with -O2 -flto and -O3 -flto with GCC 12/13/14.
I get an ICE with 'echo hi | aarch64-unknown-linux-gnu-gcc -E -dM -':
$ echo hi | aarch64-unknown-linux-gnu-gcc -E -dM -
<built-in>: internal compiler error: in real_to_decimal_for_mode, at real.cc:1899
0xe036af real_to_decimal_for_mode(char*, real_value const*, unsigned long, unsigned long, int, machine_mode)
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://bugs.gentoo.org/> for instructions.
and 'echo hi | aarch64-unknown-linux-gnu-gfortran -Werror -xf77 -v -c -' hangs for me.
(In reply to gluker from comment #7)
> As Torbjörn Granlund from gmplib.org answered:
For the record, this was at https://gmplib.org/list-archives/gmp-bugs/2023-January/005223.html.