Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[c++] Add static initialization guards for Cortex-M #346

Merged
merged 5 commits into from
Mar 13, 2020

Conversation

salkinium
Copy link
Member

This adds a hopefully atomic statics initialization guard implementation to implement #345.
In case of recursive initialization, a debug assertion cxa.guard.recursion is raised.
For AVRs, the threadsafe statics are not implemented at all to save code space.

Should the guard implementation be optional for ARM Cortex-M? The guard itself takes 4 bytes per function static, and the guards a little bit of code. I don't think this is too much size, but for very small targets it may be useful to have this as an option. I'm also not aware of this not being atomic being an issue in the past.

Not sure how to overwrite this for FreeRTOS use, I'll fix it when it becomes an issue.

cc @chris-durand @rleh @dergraaf

@salkinium
Copy link
Member Author

salkinium commented Mar 13, 2020

I also had to implement the GCC atomic builtins for ARMv6-M, since apparently the toolchain delegates the implementation to the user for these things. They are now done using atomic locks, which is fairly brute force, but should work just fine.
https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html

@salkinium salkinium merged commit 5332765 into modm-io:develop Mar 13, 2020
@salkinium salkinium deleted the feature/__cxa_guard branch March 13, 2020 22:48
@salkinium salkinium linked an issue Mar 13, 2020 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

1 participant