I'm building a project for the STM32F476. The default interrupt handlers are defined in the file "startup_stm32f746xx.s" and they're declared with the weak attribute, like this:
EXPORT RTC_Alarm_IRQHandler [WEAK]
I have my own interrupt handler for the RTC alarm interrupt, declared in a file named rtc.c using the same name as above. Looking at the map file after building my project, it seems like the linker is removing my alarm interrupt handler function:
Removing rtc.o(.text.RTC_ALARM_IRQHandler), (48 bytes). Removing rtc.o(.ARM.exidx.text.RTC_ALARM_IRQHandler), (8 bytes).
Why is the linker removing my RTC alarm handler function? I thought the purpose of the [WEAK] attribute was to define a default instance of a function that could be overridden by another instance of the function. Even the help file seems to imply this:
Use the [WEAK] attribute to inform the linker that a different instance of symbol takes precedence over this one, if a different one is available from another source.
How do I prevent the linker from removing my implementation of the RTC_Alarm_IRQHandler function?
you can refer to this armlink user manual page:
developer.arm.com/.../Weak-references-and-definitions
Thanks. Yes, that section confirms what I know about weak functions.
What I don't get is why it's inconsistent. The SysTick_Handler function, which is also declared as [WEAK] in startup_stm32f746xx.s, correctly gets replaced by my own SysTick handler function defined in another file. For some reason, that doesn't happen with RTC_Alarm_IRQHandler -- that function as defined in startup_stm32f746xx.s doesn't get replaced by my own function (as verified by running the application and noting that the CPU is executing in the default handler, which is a tight loop (B .))
Unchecking the "One ELF Section per Function" option will prevent the linker from removing my RTC_Alarm_IRQHandler function entirely, but it still does nothing to override the weak definition of RTC_Alarm_IRQHandler in startup_stm32f746xx.s -- that's the inconsistency.