cancel
Showing results for 
Search instead for 
Did you mean: 

Cube IDE 32F4 - who do ST provide a precompiled std C lib, no source, and no WEAK functions so one can't replace the empty mutex calls?

PHolt.1
Senior III

AFAICT this is a libc.a although there are quite a lot of these loaded under c:\st\...

I have spent a huge amount of time with objcopy trying to weaken a long list of stupid (empty but not replaceable) mutex calls in printf and malloc etc. like this

--weaken-symbol=__lock___arc4random_mutex

--weaken-symbol=__lock___at_quick_exit_mutex

--weaken-symbol=__lock___atexit_recursive_mutex

--weaken-symbol=__lock___dd_hash_mutex

--weaken-symbol=__lock___env_recursive_mutex

--weaken-symbol=__lock___malloc_recursive_mutex

--weaken-symbol=__lock___sfp_recursive_mutex

--weaken-symbol=__lock___sinit_recursive_mutex 

--weaken-symbol=__lock___tz_mutex

--weaken-symbol=__retarget_lock_acquire

--weaken-symbol=__retarget_lock_acquire_recursive

--weaken-symbol=__retarget_lock_close

--weaken-symbol=__retarget_lock_close_recursive

--weaken-symbol=__retarget_lock_init

--weaken-symbol=__retarget_lock_init_recursive

--weaken-symbol=__retarget_lock_release

--weaken-symbol=__retarget_lock_release_recursive

--weaken-symbol=__retarget_lock_try_acquire

--weaken-symbol=__retarget_lock_try_acquire_recursive

The above are just from one libc.a file. All are empty functions but none are weak. So you end up with non thread safe lib and no way to fix this, short of finding a whole new lib source. What a completely stupid thing of them to do, compile the lib with mutex protection but leave these as stubs.

I have succeeded with above but then I struggle (like so many others) to get Cube to use the modified library. It is incredibly tricky. And in the end I get 210 errors saying

failed to merge target specific data of file

error: xxxxxx.elf uses VFP register arguments

and back to another 100 hits on google. And another week wasted. What complete id1ot would have compiled a library, mutex protected so thread-safe, but with mutex function stubs which must be replaced with real mutex calls, but didn't declare them as weak?

A final possibility is a "wrap" compiler option, apparently.

2 REPLIES 2
Nikita91
Lead II

Write your own functions and in the linker script set them before the libs.

I think ST provides a source for that somewhere in the generated code from MX: newlib_lock_glue.c etc.

https://www.st.com/resource/en/application_note/an5731-stm32cubemx-and-stm32cubeide-threadsafe-solution-stmicroelectronics.pdf

PHolt.1
Senior III

That's interesting. It looks like I need to get hold of newlib_lock_glue.c, but it doesn't google to anything and Cube didn't come with it. It would be handy because, if from the Cube package, it might actually work, unlike so many versions online : - )

In the end I partly solved this by a different path. I installed a thread-safe printf library

https://github.com/mpaland/printf

and that just leaves me with having to sort out mutexes for malloc and free, which is much easier since these are called from just a few places in my source code. In fact I could replace these functions too with open source ones...