Page 1 of 2

strong vApplicationStackOverflowHook

Posted: Tue Dec 11, 2018 9:01 pm
by Bidouill
Hi everyone,
I wrote a specific vApplicationStackOverflowHook function in order to have a special behaviour when hook appends.
But it's still the vApplicationStackOverflowHook of panic.c that is called even if it has a weak attribute.
Do I have to put something in my makefile to set my vApplicationStackOverflowHook function as strongest one.
Regards,

Re: strong vApplicationStackOverflowHook

Posted: Wed Dec 12, 2018 3:20 am
by ESP_Sprite
Do you happen to have your custom application hook in a .c file with nothing else in it? If so, you may have to make sure there's an unresolved symbol in there, otherwise the linker will discard the entire .o file.

Re: strong vApplicationStackOverflowHook

Posted: Wed Dec 12, 2018 8:12 pm
by Bidouill
Hi, Yes I try with just vApplicationStackOverflowHook function in my freertos_hook.c file : no change.
I try to put the vApplicationStackOverflowHook function inside app_main.c file and it works.
But as soon as I put it in the another file it doesn't work. freertos_hook.c is in the same folder as app_main.c file.

Re: strong vApplicationStackOverflowHook

Posted: Thu Dec 13, 2018 4:43 am
by ESP_Sprite
Gotcha, then you have that issue. An option to fix this is to declare a symbol in this file, for instance by creating a dummy function:

Code: Select all

void ld_include_stackoverflowhandler_file_dummy_function() {
    //dummy
}
and then in the component.mk file declaring this dummy function as an unresolved symbol:

Code: Select all

COMPONENT_ADD_LDFLAGS += -u ld_include_stackoverflowhandler_file_dummy_function
That should force the linker to also take this separate file into account.

Re: strong vApplicationStackOverflowHook

Posted: Wed Dec 19, 2018 8:49 pm
by Bidouill
Good guess, it did the trick.
Where can I find more documentation on "COMPONENT_ADD_LDFLAGS" to plainly understand why this works now?

Re: strong vApplicationStackOverflowHook

Posted: Thu Dec 20, 2018 2:55 am
by ESP_Sprite
COMPONENT_ADD_LDFLAGS isn't that special, it allows you to add things to the command line for the linking stage of the executable. Here, I just add '-u [symbol]' to it. According to the man-page, the effect of -u is 'Force symbol to be entered in the output file as an undefined symbol.'

This works, because as far as I know, the linker works on a base of unresolved symbols. It starts (for example) to find the function called main(), then looks at which functions and variables (those are the 'symbols') that uses, and finds those. It then looks at the functions and variables those use, etc, until it has found all functions and variables.

Now, the issue is that vApplicationStackOverflowHook normally is marked 'weak', which means ld will mark it as 'resolved, but overridable'. Because it's still resolved, it can decide the entire program is linked (no unresolved symbols) before it looked at the object file containg your strong vApplicationStackOverflowHook function; this causes that function to be ignored.

By adding a dummy unresolved symbol to the command line, the linker can't be done linking until it has resolved that function. You're effectively forcing it to also evaluate the file with your vApplicationStackOverflowHook in it.

I can't exactly tell you where I picked up that tidbit, though; it may be somewhere in the ld manual.

Re: strong vApplicationStackOverflowHook

Posted: Thu May 05, 2022 6:17 pm
by urbanze
ESP_Sprite wrote:
Thu Dec 13, 2018 4:43 am
Gotcha, then you have that issue. An option to fix this is to declare a symbol in this file, for instance by creating a dummy function:

Code: Select all

void ld_include_stackoverflowhandler_file_dummy_function() {
    //dummy
}
and then in the component.mk file declaring this dummy function as an unresolved symbol:

Code: Select all

COMPONENT_ADD_LDFLAGS += -u ld_include_stackoverflowhandler_file_dummy_function
That should force the linker to also take this separate file into account.
Hello! I got similar problem! My project have so many components (cmake) and [mqtt component] have many weak functions when data callback is called. I use this to parse json inside anothers modules and not inside mqtt core.

When I use weak function inside another module, this is never replaced, but when I use this same function inside main.cpp this works fine.

How can I solve this inside CmakeList component?

Re: strong vApplicationStackOverflowHook

Posted: Fri May 06, 2022 1:27 am
by ESP_Sprite
Does the dummy function plus -u [dummy-functionname] trick not work?

Re: strong vApplicationStackOverflowHook

Posted: Mon May 09, 2022 5:16 pm
by urbanze
ESP_Sprite wrote:
Fri May 06, 2022 1:27 am
Does the dummy function plus -u [dummy-functionname] trick not work?
No, my question is how to add this flag to my custom component using CMake and not .mk. I tried to put this flag in .mk of main folder but when execute, CPU still calling the weak function.

Re: strong vApplicationStackOverflowHook

Posted: Tue May 10, 2022 2:04 am
by ESP_Sprite
See the docs for that.