strong vApplicationStackOverflowHook

Bidouill
Posts: 3
Joined: Tue Dec 11, 2018 8:53 pm

strong vApplicationStackOverflowHook

Postby Bidouill » Tue Dec 11, 2018 9:01 pm

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,

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: strong vApplicationStackOverflowHook

Postby ESP_Sprite » Wed Dec 12, 2018 3:20 am

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.

Bidouill
Posts: 3
Joined: Tue Dec 11, 2018 8:53 pm

Re: strong vApplicationStackOverflowHook

Postby Bidouill » Wed Dec 12, 2018 8:12 pm

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.

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: strong vApplicationStackOverflowHook

Postby ESP_Sprite » 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.

Bidouill
Posts: 3
Joined: Tue Dec 11, 2018 8:53 pm

Re: strong vApplicationStackOverflowHook

Postby Bidouill » Wed Dec 19, 2018 8:49 pm

Good guess, it did the trick.
Where can I find more documentation on "COMPONENT_ADD_LDFLAGS" to plainly understand why this works now?

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: strong vApplicationStackOverflowHook

Postby ESP_Sprite » Thu Dec 20, 2018 2:55 am

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.

User avatar
urbanze
Posts: 295
Joined: Sat Jun 10, 2017 9:55 pm
Location: Brazil

Re: strong vApplicationStackOverflowHook

Postby urbanze » Thu May 05, 2022 6:17 pm

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?

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: strong vApplicationStackOverflowHook

Postby ESP_Sprite » Fri May 06, 2022 1:27 am

Does the dummy function plus -u [dummy-functionname] trick not work?

User avatar
urbanze
Posts: 295
Joined: Sat Jun 10, 2017 9:55 pm
Location: Brazil

Re: strong vApplicationStackOverflowHook

Postby urbanze » Mon May 09, 2022 5:16 pm

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.

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: strong vApplicationStackOverflowHook

Postby ESP_Sprite » Tue May 10, 2022 2:04 am

See the docs for that.

Who is online

Users browsing this forum: Bing [Bot] and 110 guests