Compiling newlib with fat LTO

Paulo Matos <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>

Hi,

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'
AR_FOR_TARGET=riscv64-unknown-elf-gcc-ar
RANLIB_FOR_TARGET=riscv64-unknown-elf-gcc-ranlib
NM_FOR_TARGET=riscv64-unknown-elf-gcc-nm
--prefix=/home/pmatos/Projects/RISCV-cross/install
--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
--with-sysroot=/home/pmatos/Projects/RISCV-cross/install/riscv64-unknown-elf


The full command lines for a whole toolchain can be found here:
https://gitlab.com/snippets/1833421

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'

Example:
$ riscv64-unknown-elf-gcc
/home/pmatos/Projects/RISCV-cross/gcc/gcc/testsuite/gcc.c-torture/execute/20000112-1.c
   -fno-diagnostics-show-caret -fno-diagnostics-show-line-numbers
-fdiagnostics-color=never -O1  -w      -lm  -o ./20000112-1.exe
/home/pmatos/Projects/RISCV-cross/install/lib/gcc/riscv64-unknown-elf/9.0.1/../../../../riscv64-unknown-elf/bin/ld:
20000112-1.exe.ltrans0.ltrans.o: in function `.L21':
<artificial>:(.text+0x194): undefined reference to `_exit'
/home/pmatos/Projects/RISCV-cross/install/lib/gcc/riscv64-unknown-elf/9.0.1/../../../../riscv64-unknown-elf/bin/ld:
20000112-1.exe.ltrans0.ltrans.o: in function `.L45':
<artificial>:(.text+0x2f0): undefined reference to `_exit'
/home/pmatos/Projects/RISCV-cross/install/lib/gcc/riscv64-unknown-elf/9.0.1/../../../../riscv64-unknown-elf/bin/ld:
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?

Regards,

-- 
Paulo Matos
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.