2020-04-06 03:39 PM
I have a program for which I would like to enable link-time optimization. However, once I pass the -flto flag to the compiler and linker, I get two linker errors, one complaining about multiple definition of _exit and undefined reference to _sbrk. I found various places online about people having issues with undefined references in conjunction with lto, but not redefinition errors. Does anybody have any idea what I can do here?
PS lto is a nice-to-have for this project. I can live without it, but it would be nice if I can get it to work.
2020-04-07 01:24 AM
Looking at the full error message, _exit() is apparently defined in libnosys.a too, besides syscalls.c. Both libnosys.a and syscalls.c serve the same function, providing stubs for nonexistent operating system calls. I have no idea why are both of them present in the standard STM32 project. Just get rid of libnosys.a, under Project / Properties / C/C++ Build / Settings / Tool Settings / MCU GCC Linker / System Calls, set Do not use system calls from library.
For the undefined reference errors, put __attribute__((used)) before each function which is missed by the linker.