-flto causes incorrect linkage of weak alias
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
GNU Arm Embedded Toolchain |
New
|
Undecided
|
Unassigned |
Bug Description
Version: 8.2.0 (Arch Repository)
OS: Manjaro Linux, kernel 4.17.17
Symptoms:
For stm32 microcontrollers, there exists assembly startup code, that defines a weak symbol (TIM3_IRQHandler in the example) as an alias to a function. A symbol with the same name gets defined in a c source, which is later linked with the assembled startup code.
When using normal compile flags, the resulting .elf files contains the symbol in the .text section as a "hard" symbol. The symbol points to the code of the c file. This is how it should work.
However when compiling the c source with -flto (other flags do not matter, as far as I have tried) and then link the same objects, the resulting .elf file only contains the TIM3_IRQHandler as a weak symbol, and no code is emitted for the c function in the final .elf binary.
Even when adding __attribute_
Example:
I have included a small example program using the startup file of the stm32f413, a minimal main.c file and a Makefile. The makefile has four targets: all, lto, check and clean. lto and all compile the program, check executes nm and greps the output to see if it is a weak symbol (W) or a text symbol (T). The Program should be able to run on any system with arm-none-eabi-gcc, ar-none-eabi-as, arm-none-eabi-nm and grep in its path.
I think this is a dup of #1747966