>> With the arm cross compiler: >> /usr/libexec/gcc/arm-none-eabi/ld: /tmp/ccupVhtJ.ltrans0.ltrans.o: reference to malloc >> /usr/libexec/gcc/arm-none-eabi/ld: /tmp/ccupVhtJ.ltrans0.ltrans.o: in function `f': >> /home/gabriel/tmp/t1.c:3: undefined reference to `malloc' >> collect2: error: ld returned 1 exit status >> >> So it's just not finding the symbol? > > It's how static linking works: the defining object is not unpacked from libc.a > unless the linker previously saw a reference to it. The linker would need to > (re)scan libc.a after being handed this ltrans unit from the LTO plugin. > > Can you show output with '-Wl,-v,-t', with and without LTO? > > Alexander Sure thing. 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 /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 /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 And with LTO: $ CC=arm-none-eabi-gcc make arm-none-eabi-gcc -O0 -flto -g -Wl,-y,malloc,-v,-t -c -o main.o main.c arm-none-eabi-gcc -O0 -flto -g -Wl,-y,malloc,-v,-t -c -o t1.o t1.c arm-none-eabi-gcc -O -flto -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/ccg9cQHe.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/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/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/cc8yOhlK.ltrans0.ltrans.o /usr/libexec/gcc/arm-none-eabi/ld: /tmp/cc8yOhlK.ltrans0.ltrans.o: reference to malloc /tmp/ccMj1Vhu.debug.temp.o /tmp/ccLX2EyT.debug.temp.o /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/libexec/gcc/arm-none-eabi/ld: /tmp/cc8yOhlK.ltrans0.ltrans.o: in function `f': /home/gabriel/tmp/t1.c:3: undefined reference to `malloc' collect2: error: ld returned 1 exit status make: *** [<builtin>: main] Error 1 So, it doesn't find the symbol in libc.a? The non-lto output shows a line about the definition of malloc right before the libc.a line it output, but that's missing in the lto one. Gabe Marcano