Hi, I found a bug with weak function declarations in SDK11, using GCC.
app_error_weak.h
contains the following declaration:
#ifdef __CC_ARM
void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info);
#else
__WEAK void app_error_fault_handler(uint32_t id, uint32_t pc, uint32_t info);
#endif
app_error_weak.h
is included in app_error.h
and so indirectly in multiple header files.
This leads to a situation where I cannot define "strong" implementations of app_error_fault_handler()
in files where I use specific other include files (it is not clear which include files I may use and which not). For example, if I include softdevice_handler.h
in main.c
, I cannot define a "strong" app_error_fault_handler()
in main.c
at the same time, because the function will be declared as weak due to indirect inclusion of app_error_weak.h
In short, I will get two weak implementations of app_error_fault_handler()
, one defined in main.c
and one defined in app_error_weak.c
. GCC will pick one of these functions randomly and discard the other implementation.
Proposed solutions:
(1) Do not declare the function as weak in app_error_weak.h
. It should be sufficient to use the weak attribute in app_error_weak.c
where it is defined.
(2) Do not include app_error_weak.h
in app_error.h
, and use a non-weak declaration of the function in app_error.h
. app_error_weak.h
seems to becomes obsolete in this case.
For a clean implementation, I would prefer (2).