I'm working on an bare-metal embedded project for the STM32F103, and I'm using GNU ARM Embedded version 7-2017-q4-major toolchain. I'm currently compiling via GNU ARM Eclipse.
I'm at a point where I need to start optimizing the project for speed, and as a first thing to do I of course tried turning on all the optimizer flags. Everything else went fine, but when I try to turn on Link Time Optimization with -flto
, I get linker errors in the final step:
Invoking: Cross ARM C++ Linker
arm-none-eabi-g++ -mcpu=cortex-m3 -mthumb -O3 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections -flto -Wall -Wextra -g3 -T mem.ld -T libs.ld -T sections.ld -nostartfiles -Xlinker --gc-sections -L"../ldscripts" -Wl,-Map,"Project.map" -Xlinker --cref --specs=nano.specs -o "Project.elf" ./tiny-mt/tinymt/tinymt32.o ... .o
/Users/me/opt/gcc-arm-none-eabi-7-2017-q4-major/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/thumb/v7-m/libg_nano.a(lib_a-fstatr.o): In function `_fstat_r':
fstatr.c:(.text._fstat_r+0xe): undefined reference to `_fstat'
/Users/me/opt/gcc-arm-none-eabi-7-2017-q4-major/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/thumb/v7-m/libg_nano.a(lib_a-isattyr.o): In function `_isatty_r':
isattyr.c:(.text._isatty_r+0xc): undefined reference to `_isatty'
collect2: error: ld returned 1 exit status
make: *** [Project.elf] Error 1
This is apparently due to newlib-nano not being compiled with LTO?
So how do I make it work? I suppose I could try compiling newlib-nano myself and adding the necessary flags (and changing the tools to use -gcc-ar and so on), but I'd imagine/hope that someone would already have done this? My google-fu was not enough to find anything helpful.
specs=nosys.specs
provides basic implementations of system functions, that mostly just return error codes. You could try that if you want – Mike van Dyke_exit
from_syscalls.c
to avoid another (new) linker error, but after that seems to be ok! – Timo