-flto causes incorrect linkage of weak alias

Bug #1788156 reported by Alexander Daum on 2018-08-21
20
This bug affects 3 people
Affects Status Importance Assigned to Milestone
GNU Arm Embedded Toolchain
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__((used)) to the c function, there is no code emitted for it in the .elf file.

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.

Alexander Daum (alexander.daum) wrote :
Morty (morty) wrote :

I think this is a dup of #1747966

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers