Weak function definition in assembly is prefered over strong c function

Asked by luxuryhell

- arm-none-eabi-gcc version 10.3-2021.10 20210824
- open source project affected: [REMOVED LINK AS IT TURNS OUT IT IS NOT OPEN SOURCE]
- device: nordic nRF52840/nRF52832/nRF52833
- library affected: Nordic NRF5 SDK 17.1.0 - custom build system (CMake)

Introduction

I am compiling the project with CMake. My company has their own HardFault_c_handler (lib/NordicAL/src/pal/Pal.cpp) defined. It should be called from HardFault_Handler (ISR vector), it is defined as weak in lib/NordicAL/lib/nrf5_sdk_17.1.0/modules/nrfx/mdk/gcc_startup_nrf52840.S and strong in lib/NordicAL/lib/nrf5_sdk_17.1.0/components/libraries/hardfault/nrf52/handler/hardfault_handler_gcc.c. For some reason the weak definition from the assembly file is always chosen. These files are compiled into the nrf5_sdk library, and than linked with the application executable.

So the source files are in the same library (nrf5_sdk), the hardfault_handler_gcc.c is added before the assembly file.

Relevant code in the assembly file:

__isr_vector:
    .long __StackTop /* Top of Stack */
    .long Reset_Handler
    .long NMI_Handler
    .long HardFault_Handler
.
.
.
.weak HardFault_Handler
.type HardFault_Handler, %function
        HardFault_Handler:
b .
.size HardFault_Handler, . - HardFault_Handler

Useful information

- Moving the code from hardfault_handler_gcc.c to pal (which later links to nrf5_sdk) links the proper definition,
- separating the files into separate libraries does not resolve the problem,
- reordering the files in the sources does not affect the issue,
- I am not using -flto (I saw an issue with it),
- using -Wl,-trace-symbol=HardFault_Handler sees the definition only in the .S file,
- separating the definition of the function from the .S file in another .S file resolves the problem, but it must be before the .c file in the sources,
- I also asked this question here: https://stackoverflow.com/questions/70679832/weak-function-definitions-for-interrupt-vector-in-a-static-library-are-preferred

This problem does not happen when the project is compiled with the included makefile system, the makefile system does not create the static library before linking.

Does this occur because the definition is in the same file it is defined in?

Question information

Language:
English Edit question
Status:
Open
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:

Can you help with this problem?

Provide an answer of your own, or ask luxuryhell for more information if necessary.

To post a message you must log in.