Context:
https://www.eevblog.com/forum/microcontrollers/32f4-hard-fault-trap-how-to-track-this-down/https://www.eevblog.com/forum/programming/st-cube-gcc-how-to-override-a-function-not-defined-as-weak-(no-sources)/Last night I was tracing through some long and float printf code.
The "classic" C printf library is known to use the heap, at least for floats and evidently for longs (uint32_t, with an arm32) too. It is also generally thought to not be thread-safe, due to use of static storage. The library commonly used is from 1990 and that contains both mutex calls and malloc calls.
Sometimes the one I have calls the mutexes and sometimes it calls malloc as well, and it turns out that the heap code I have (probably of the same origin) has its own mutex protection and actually uses the same calls.
Unfortunately the mutex calls are to empty functions. Some silly bugger at STM compiled this stuff into a library, didn't include the source, and left the mutex functions as stubs which can't be replaced (easily) because they were not declared as "weak".
Anyway I have a Q on mutexes. I have only so far used simple mutexes, where a call has to be made during init to obtain a handle for the mutex. But this printf and malloc stuff uses recursive mutexes, and I see no "init" call anywhere. But perhaps recursive ones don't need a pre-init function. Also they don't need a parameter (a handle) because, in a recursive situation, how could you keep track of the handles?
My printf calls __retarget_lock_acquire_recursive and then __retarget_lock_release_recursive. However, the library contains symbols for all these (ignore the weaken-symbol strings)
--weaken-symbol __retarget_lock_init
--weaken-symbol __retarget_lock_init_recursive
--weaken-symbol __retarget_lock_close
--weaken-symbol __retarget_lock_close_recursive
--weaken-symbol __retarget_lock_acquire
--weaken-symbol __retarget_lock_acquire_recursive
--weaken-symbol __retarget_lock_try_acquire
--weaken-symbol __retarget_lock_try_acquire_recursive
--weaken-symbol __retarget_lock_release
--weaken-symbol __retarget_lock_release_recursive
--weaken-symbol __lock___arc4random_mutex
--weaken-symbol __lock___dd_hash_mutex
--weaken-symbol __lock___tz_mutex
--weaken-symbol __lock___env_recursive_mutex
--weaken-symbol __lock___malloc_recursive_mutex
--weaken-symbol __lock___at_quick_exit_mutex
--weaken-symbol __lock___atexit_recursive_mutex
--weaken-symbol __lock___sfp_recursive_mutex
--weaken-symbol __lock___sinit_recursive_mutex
Does anyone recognise these, and what might __retarget_lock_init be?
Remember this goes back to at least 1990, back to before the days embedded systems would have had a heap, or even a full printf.