Compiling newlib with fat LTO

Paulo Matos
Fri Mar 8 17:41:00 GMT 2019


I am been attempting to build a riscv toolchain with newlib with
optional LTO. The idea is to use -ffat-lto-objects to include IR
information along with binary in the library so that later I can use lto
optionally when linking to newlib.

The way I am compiling newlib is pretty normal:
$ ../../newlib/configure CFLAGS_FOR_TARGET='-flto -ffat-lto-objects'
LDFLAGS_FOR_TARGET='-flto -ffat-lto-objects'
--disable-newlib-fvwrite-in-streamio --disable-newlib-fseek-optimization
--enable-newlib-nano-malloc --disable-newlib-unbuf-stream-opt
--enable-target-optspace --enable-newlib-reent-small
--disable-newlib-wide-orient --disable-newlib-io-float
--enable-newlib-nano-formatted-io --target=riscv64-unknown-elf

The full command lines for a whole toolchain can be found here:

All compiles fine but when I try to compile one of the tests from the
gcc testsuite, it fails with undefined '_exit'.
This only happens when I compile newlib with CFLAGS_FOR_TARGET='-flto
-ffat-lto-objects' LDFLAGS_FOR_TARGET='-flto -ffat-lto-objects'

$ riscv64-unknown-elf-gcc
   -fno-diagnostics-show-caret -fno-diagnostics-show-line-numbers
-fdiagnostics-color=never -O1  -w      -lm  -o ./20000112-1.exe
20000112-1.exe.ltrans0.ltrans.o: in function `.L21':
<artificial>:(.text+0x194): undefined reference to `_exit'
20000112-1.exe.ltrans0.ltrans.o: in function `.L45':
<artificial>:(.text+0x2f0): undefined reference to `_exit'
error: could not unlink output file
collect2: error: ld returned 1 exit status

If I dig a bit deeper I notice in the LTO resolution file (use
-save-temps to get it):
$ cat 20000112-1.res | grep '_exit$'
200 bcacc6c809c66af7 UNDEF _exit
199 aa3f5695ee2d0c31 UNDEF _exit

Although, _exit is there in libgloss.a, defined in sys-exit.c.
I am assuming that this is not a bug in newlib or gcc but a mistake on
my side building newlib with LTO.

Has anyone tried this before and can point out anything wrong with the
configure line above?


Paulo Matos

More information about the Newlib mailing list