ARM cross-compiler with newlib, LTO, undefined reference to libc symbols

Alexander Monakov amonakov@ispras.ru
Sat May 29 21:17:24 GMT 2021


On Sat, 29 May 2021, Gabriel Marcano via Gcc-help wrote:

> Here's the non-lto build:
>  arm-none-eabi-gcc -O0 -g -Wl,-y,malloc,-v,-t   -c -o main.o main.c
>  arm-none-eabi-gcc -O0 -g -Wl,-y,malloc,-v,-t   -c -o t1.o t1.c
>  arm-none-eabi-gcc -O -g -Wl,-y,malloc,-v,-t  main.o t1.o   -o main
>  collect2 version 11.1.0
>  /usr/libexec/gcc/arm-none-eabi/ld -plugin
>    /usr/libexec/gcc/arm-none-eabi/11.1.0/liblto_plugin.so
>    -plugin-opt=/usr/libexec/gcc/arm-none-eabi/11.1.0/lto-wrapper
>    -plugin-opt=-fresolution=/tmp/ccyt1CxF.res -plugin-opt=-pass-through=-lgcc
>    -plugin-opt=-pass-through=-lg -plugin-opt=-pass-through=-lc
>    --sysroot=/usr/arm-none-eabi -X -o main
>    /usr/lib/gcc/arm-none-eabi/11.1.0/crti.o
>    /usr/lib/gcc/arm-none-eabi/11.1.0/crtbegin.o
>    /usr/lib/gcc/arm-none-eabi/11.1.0/../../../../arm-none-eabi/lib/crt0.o
>    -L/usr/lib/gcc/arm-none-eabi/11.1.0
>    -L/usr/lib/gcc/arm-none-eabi/11.1.0/../../../../arm-none-eabi/lib
>    -L/usr/arm-none-eabi/lib -L/usr/arm-none-eabi/usr/lib -y malloc -v -t main.o
>    t1.o --start-group -lgcc -lg -lc --end-group
>    /usr/lib/gcc/arm-none-eabi/11.1.0/crtend.o
>    /usr/lib/gcc/arm-none-eabi/11.1.0/crtn.o
>  GNU ld (Gentoo 2.36.1 p3) 2.36.1
>  /usr/lib/gcc/arm-none-eabi/11.1.0/crti.o
>  /usr/lib/gcc/arm-none-eabi/11.1.0/crtbegin.o
>  /usr/lib/gcc/arm-none-eabi/11.1.0/../../../../arm-none-eabi/lib/crt0.o
>  main.o
>  t1.o
>  /usr/libexec/gcc/arm-none-eabi/ld: t1.o: reference to malloc
>  /usr/lib/gcc/arm-none-eabi/11.1.0/libgcc.a
>  /usr/lib/gcc/arm-none-eabi/11.1.0/../../../../arm-none-eabi/lib/libg.a
>  /usr/libexec/gcc/arm-none-eabi/ld: lib_a-malloc.o (symbol from plugin): definition of malloc

So this line ("symbol from plugin")

>  /usr/lib/gcc/arm-none-eabi/11.1.0/../../../../arm-none-eabi/lib/libc.a
>  /usr/lib/gcc/arm-none-eabi/11.1.0/libgcc.a
>  /usr/lib/gcc/arm-none-eabi/11.1.0/../../../../arm-none-eabi/lib/libg.a
>  /usr/lib/gcc/arm-none-eabi/11.1.0/../../../../arm-none-eabi/lib/libc.a
>  /usr/lib/gcc/arm-none-eabi/11.1.0/crtend.o
>  /usr/lib/gcc/arm-none-eabi/11.1.0/crtn.o
>  /tmp/ccHV3ALY.ltrans0.ltrans.o
>  /usr/libexec/gcc/arm-none-eabi/ld: /tmp/ccHV3ALY.ltrans0.ltrans.o: definition of malloc

and this line (synthesized ltrans unit) indicate that your libc.a has LTO
bytecode.


How did that happen, did you build Newlib with -flto?

Alexander


More information about the Gcc-help mailing list