Repository navigation
Conversation
In case static local variables are used anywhere in the C++ code of the sketch or the libraries, gcc kicks in to protect initializing those from any potential threads being run in parallel. The implementation of the above is to emit calls to __cxa_guard_acquire() and __cxa_guard_release(). These functions are part of libstdc++ [1], and so, once a local static variable appears, the whole libstdc++ is linked into the binary with all its bells and whistles, greatly increasing the binary size as a result. One possible solution to that was proposed in [2], but it dealt with a single consequence of linking in libstdc++ (adding the __verbose_terminate_handler()). This commits deals with the reason of libstdc++ linking. A gcc option -fno-threadsafe-statics is disabling the above local statics protection mechanism, as a result libstdc++ is not linked in. Resulting binary size comparison using a sketch from FastLED examples (as reported by Arduino IDE, in bytes; the first number is "program storage space", the second is "dynamic memory"): Before: 75160 / 6392 After: 14964 / 3152 For comparison, here are the numbers after applying the commit from [2]: PR#28: 29592 / 6328 Finally, the resulting sketch is working just fine. [1] https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/libsupc%2B%2B/guard.cc [2] rogerclarkmelbourne#28 Signed-off-by: Kir Kolyshkin <[email protected]>
|
This already got rejected because some users like FreeRTOS |
Thanks for letting me know @RickKimball, I'll discuss it there. |
|
I will close this as it has compatibility issues. Please open a new PR if this can be done and still support RTOS |
|
There was an extensive discussion at #296, which I just re-read, and my overall understanding is there is a claim that
with no substantial proof to it. I tried very hard to find it, but I'm not an RTOS user :( So, can we maybe revisit this PR and, unless proven that it breaks RTOS, consider merging it? |
|
Make it a menu option in boards.txt - for example, to tack it onto the optimizations (it's the first 3 lines below): Or you can add a new menu where folks can select between things - but it doesn't have to be an all or nothing option. |
|
Honestly I think this sill confuse most people. Also it will probably default to that option, hence anyone using RTOS could theoretically have problems next time they compile and run their code. |
|
I suggest to have discussions at a single place -- so far the most of it is at #296 |
|
@kolyshkin - I get that I need to add -fno-threadsafe-statics , but where and how ? - can it be done in a sketch ? |
|
@AndKe you need to modify the STM32F1/platform.txt file. |
|
@RickKimball yes, the thing is, I have no platform.txt inside a STM32F1 directory: |
|
Where is your core installed? If you turn on verbose compiler output the console window shows where your core is located. In my case: so my platform.txt is found in: |
|
Thanks mine is: Surprised to see ."arduino15" directory ... need to find out what it is good for :) |
|
You must have used Dan Drown's json file to install. If you had installed using github, you would have known where you put it. When you use the json file. You may or maynot be using what is in github. |
|
@RickKimball I've modified ~/.arduino15/packages/stm32duino/hardware/STM32F1/2019.2.4/platform.txt as needed, but compiler does not seem to get it: is there some sort of caching that survives Arduino application restart ? |
|
If you quit the arduino ide and restart it will use the latest platform.txt. What version of the Arduino IDE are you using? Never mind, I see you are using 1.8.8 that should be fine. |
|
v1.8.8 |
|
@RickKimball Thank you. now I can fully enjoy trying to figure out why FastLED does not work at all with Blue Pill. :) |
|
The issue with thread safe static is being discussed in several issues at the moment. e.g. I suspect the final solution will be to default to no-treadsafe-statics, and have a build option for thread safe statics, in the optimisation settings e.g. -Os -no-threadsafe-statics will be the default, and there will be a separate option for -Os on its own, which RTOS users need to select |
In case static local variables are used anywhere in the C++ code of the sketch or the libraries, gcc kicks in to protect initializing those from any potential threads being run in parallel.
The implementation of the above is to emit calls to
__cxa_guard_acquire()and__cxa_guard_release(). These functions are part of libstdc++ [1], and so, once a local static variable appears, the whole libstdc++ is linked into the binary with all its bells and whistles, greatly increasing the binary size as a result.One possible solution to that was proposed in [2], but it dealt with a single consequence of linking in libstdc++ (adding the
__verbose_terminate_handler()).This commits deals with the reason of libstdc++ linking. A gcc option
-fno-threadsafe-staticsis disabling the above local statics protection mechanism, as a result libstdc++ is not linked in implicitly.Resulting binary size comparison using a sketch from FastLED examples (as reported by Arduino IDE, in bytes; the first number is "program storage space", the second is "dynamic memory"):
For comparison, here are the numbers after applying the commit from [2]:
Finally, the resulting sketch is working just fine.
[1] https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/libsupc%2B%2B/guard.cc
[2] #28