Hi all,
During the GNU Tools Cauldron we discussed (at the BoF: IPA & LTO) the
possibility (and hazards) of building the run time libraries for various
compilers with -flto, enabling an -flto -static linking of programs with
the run time library available during link time optimizations.
Today I tried that on my (AMD Ryzen 7 5800U) laptop with
gcc version 14.0.0 20230926 (experimental) [master
r14-4282-g53daf67fd55] (GCC)
with the following "quick hack":
diff --git a/libgfortran/configure b/libgfortran/configure
index cd176b04a14..69a2b4a8881 100755
--- a/libgfortran/configure
+++ b/libgfortran/configure
@@ -5959,11 +5959,11 @@ fi
# Add -Wall -fno-repack-arrays -fno-underscoring if we are using GCC.
have_real_17=no
if test "x$GCC" = "xyes"; then
- AM_FCFLAGS="-I . -Wall -Werror -fimplicit-none -fno-repack-arrays
-fno-underscoring"
+ AM_FCFLAGS="-I . -Wall -Werror -fimplicit-none -fno-repack-arrays
-fno-underscoring -flto"
## We like to use C11 and C99 routines when available. This makes
## sure that
## __STDC_VERSION__ is set such that libc includes make them available.
- AM_CFLAGS="-std=gnu11 -Wall -Wstrict-prototypes -Wmissing-prototypes
-Wold-style-definition -Wextra -Wwrite-strings
-Werror=implicit-function-declaration -Werror=vla"
+ AM_CFLAGS="-std=gnu11 -Wall -Wstrict-prototypes -Wmissing-prototypes
-Wold-style-definition -Wextra -Wwrite-strings
-Werror=implicit-function-declaration -Werror=vla -flto"
## Compile the following tests with the same system header contents
## that we'll encounter when compiling our own source files.
CFLAGS="-std=gnu11 $CFLAGS"
The build of this compiler (languages=fortran) completed without
problems (no test results - not enough time).
I then proceeded to build LAPACK with the following build options:
CFLAGS = -O3 -flto -flto-partition=none -static
and
FFLAGS = -O3 -flto -flto-partition=none -static
This gave the same test results of the LAPACK test suite as the build
with the same compiler, but without an lto'd libgfortran.
The lto-ing of libgfortran did succeed, because I did get a new warning:
gfortran -O3 -flto -flto-partition=none -static -o xlintstrfz zchkrfp.o
zdrvrfp.o zdrvrf1.o zdrvrf2.o zdrvrf3.o zdrvrf4.o zerrrfp.o zlatb4.o
zlaipd.o zlarhs.o zsbmv.o zget04.o zpot01.o zpot03.o zpot02.o chkxer.o
xerbla.o alaerh.o aladhd.o alahd.o alasvm.o ../../libtmglib.a
../../liblapack.a ../../librefblas.a
In function 'xtoa_big',
inlined from 'write_z' at
/home/toon/compilers/gcc/libgfortran/io/write.c:1296:11,
inlined from 'formatted_transfer_scalar_write' at
/home/toon/compilers/gcc/libgfortran/io/transfer.c:2136:4:
/home/toon/compilers/gcc/libgfortran/io/write.c:1222:6: warning: writing
1 byte into a region of size 0 [-Wstringop-overflow=]
1222 | *q = '\0';
| ^
/home/toon/compilers/gcc/libgfortran/io/write.c: In function
'formatted_transfer_scalar_write':
/home/toon/compilers/gcc/libgfortran/io/write.c:1291:8: note: at offset
[34, 4294967294] into destination object 'itoa_buf' of size 33
1291 | char itoa_buf[GFC_XTOA_BUF_SIZE];
| ^
which was (of course) not given with a non-lto libgfortran.
The full question of "lto-ing" run time libraries is more complicated
than just "whether it works" as those who attended the BoF will recall.
Hope this helps,
--
Toon Moene - e-mail: t...@moene.org - phone: +31 346 214290
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands