-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Some cleanup of C++ support and fix GCC 6 builds #2979
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1a841ae
Some cleanup of C++ support and fix GCC 6 builds
kilograham e81c182
_fini should just return not bkpt
kilograham 317e975
review comment and fix bazel
kilograham 6915c8e
hacky workaround for check_configs
kilograham 04cde56
add kitchen_sink_cpp_no_flash to bazel build
kilograham c62e136
remove PICO_CONFIG for PICO_CXX_ENABLE_EXCEPTIONS since it is really …
kilograham c4cacf2
Apply suggestions from code review
kilograham 3e29a41
Apply suggestions from code review
kilograham ddab0a1
Merge develop into cpp-improvements
kilograham 4f9da7a
why
kilograham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /* | ||
| * Copyright (c) 2026 Raspberry Pi (Trading) Ltd. | ||
| * | ||
| * SPDX-License-Identifier: BSD-3-Clause | ||
| */ | ||
|
|
||
| #include "pico/cxx_options.h" | ||
|
|
||
| #define CXA_GUARD_UNINITIALIZED 0 | ||
| #define CXA_GUARD_INITIALIZED 1 | ||
| #define CXA_GUARD_INITIALIZING 2 | ||
|
|
||
| #if PICO_CXX_THREAD_SAFE_STATIC_INIT | ||
| #include <stdatomic.h> | ||
| #include <hardware/sync.h> | ||
|
|
||
| // newer LLVM complains on RP2040 because there are no atomics (it doesn't know we have pico_atomic) | ||
| Clang_Pragma("clang diagnostic push") | ||
| Clang_Pragma("clang diagnostic ignored \"-Watomic-alignment\"") | ||
|
|
||
| int __cxa_guard_acquire(int32_t *guard_object) { | ||
| // Cast the raw pointer to a standard C11 atomic pointer type | ||
| _Atomic int32_t *atomic_guard = (_Atomic int32_t *)guard_object; | ||
|
|
||
| while (true) { | ||
| // read current state | ||
| int32_t current = atomic_load_explicit(atomic_guard, memory_order_acquire); | ||
|
|
||
| // bit 0 set -> Initialization is complete, skip constructor | ||
| if (current & CXA_GUARD_INITIALIZED) { | ||
| return 0; | ||
| } | ||
|
|
||
| // bit 1 set -> another thread/core is initializing it, so sleep | ||
| if (current & CXA_GUARD_INITIALIZING) { | ||
| __wfe(); | ||
| continue; | ||
| } | ||
|
|
||
| // attempt to atomically claim the lock by moving state from CXA_GUARD_UNINITIALIZED to CXA_GUARD_INITIALIZING. | ||
| int32_t expected = CXA_GUARD_UNINITIALIZED; | ||
| if (atomic_compare_exchange_weak_explicit(atomic_guard, &expected, CXA_GUARD_INITIALIZING, | ||
| memory_order_release, | ||
| memory_order_relaxed)) { | ||
| return 1; // Success! This core must execute the constructor | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void __cxa_guard_release(int32_t *guard_object) { | ||
| _Atomic int32_t *atomic_guard = (_Atomic int32_t *)guard_object; | ||
|
|
||
| // set Bit 0 (done) and clear Bit 1 (unlocked) | ||
| atomic_store_explicit(atomic_guard, CXA_GUARD_INITIALIZED, memory_order_release); | ||
|
|
||
| // wake up any waiters | ||
| __sev(); | ||
| } | ||
|
|
||
| void __cxa_guard_abort(int32_t *guard_object) { | ||
| _Atomic int32_t *atomic_guard = (_Atomic int32_t *)guard_object; | ||
|
|
||
| // reset back to uninitialized state | ||
| atomic_store_explicit(atomic_guard, CXA_GUARD_UNINITIALIZED, memory_order_release); | ||
|
|
||
| // wake up any waiters | ||
| __sev(); | ||
| } | ||
|
|
||
| Clang_Pragma("clang diagnostic pop") | ||
| #else | ||
|
|
||
| int __cxa_guard_acquire(volatile int32_t *guard_object) { | ||
| int32_t guard_val = *guard_object; | ||
| if (guard_val == CXA_GUARD_INITIALIZED) { | ||
| return 0; | ||
| } | ||
| if (guard_val & CXA_GUARD_INITIALIZING) { | ||
| panic("recursive CXX initializer"); | ||
| } | ||
| *guard_object = CXA_GUARD_INITIALIZING; | ||
| return 1; | ||
| } | ||
|
|
||
| void __cxa_guard_release(volatile int32_t *guard_object) { | ||
| *guard_object = CXA_GUARD_INITIALIZED; | ||
| } | ||
|
|
||
| void __cxa_guard_abort(volatile int32_t *guard_object) { | ||
| *guard_object = CXA_GUARD_UNINITIALIZED; | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/rp2_common/pico_clib_interface/llvm_libc_interface_cpp.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #include <version> | ||
| #include <cstdarg> | ||
|
|
||
| #include "pico.h" | ||
|
|
||
| namespace std { | ||
| inline namespace __2 { | ||
| [[__noreturn__]] _LIBCPP_AVAILABILITY_VERBOSE_ABORT _LIBCPP_OVERRIDABLE_FUNC_VIS _LIBCPP_ATTRIBUTE_FORMAT( | ||
| __printf__, 1, 2) void __libcpp_verbose_abort(const char* __format, ...) _NOEXCEPT { | ||
| panic("c++ abort: %s", __format); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/rp2_common/pico_cxx_options/include/pico/cxx_options.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /* | ||
| * Copyright (c) 2026 Raspberry Pi (Trading) Ltd. | ||
| * | ||
| * SPDX-License-Identifier: BSD-3-Clause | ||
| */ | ||
|
|
||
| #ifndef _PICO_CXX_OPTIONS_H | ||
| #define _PICO_CXX_OPTIONS_H | ||
|
|
||
| #include "pico.h" | ||
|
|
||
| // PICO_CONFIG: PICO_CXX_DISABLE_ALLOCATION_OVERRIDES, Disable SDK overrides of C++ new/delete operators, type=bool, default=0, advanced=true, group=pico_cxx_options | ||
|
|
||
| // PICO_CONFIG: PICO_CXX_THREAD_SAFE_STATIC_INIT, Enable thread/IRQ safe locks for C++ static initializers, type=bool, default=1 when using pico_multicore, advanced=true, group=pico_cxx_options | ||
| #ifndef PICO_CXX_THREAD_SAFE_STATIC_INIT | ||
| #define PICO_CXX_THREAD_SAFE_STATIC_INIT LIB_PICO_MULTICORE | ||
| #endif | ||
|
|
||
| #endif | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.