https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83967
Bug ID: 83967 Summary: LTO removes C functions declared as weak in assembler(depending on files order in linking) Product: gcc Version: 7.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: lto Assignee: unassigned at gcc dot gnu.org Reporter: hurwic8 at gmail dot com CC: marxin at gcc dot gnu.org Target Milestone: --- I've observed strange behaviour of the link-time optimization on GCC 7.2.1, exact version: gcc version 7.2.1 20170904 (release) [ARM/embedded-7-branch revision 255204] (GNU Tools for Arm Embedded Processors 7-2017-q4-major) I have project that is compiled for the microcontroller. In startup file, that is written in assembler, there are weak definitions of the interrupt handlers. Some of those weak functions are defined in the project C files. Strange behaviour occurs when I set -flto flag on GCC 7.2.1: during optimization, the defined in C files interrupt functions are perceived as unused and removed(replaced by its weak definitions) - I've checked that in the .map file. This issue does not occur when startup file is first on the source files list, which is given as an argument to the linker. If I change order of source files, all interrupt handlers from C files, that are placed on the source files list before startup are removed and replaced by weak definitions from startup. For me it seems that linker is removing interrupt handler functions before noticing its usage in startup file. Or maybe weak function definitions from startup override definitions from C files. I've checked if this issue happens on the GCC 4.9.3 - it worked fine, so this is rather new behaviour. I've also confirmed this bug with other developer from Germany: https://www.mikrocontroller.net/topic/443262 Take a look at the latest posts, which are written in English. Is this a bug or should I place some extra pragmas/attributes to extort proper linker behaviour? Please let me know if you want me to prepare some basic examples of this issue.