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

libstdc++-v3: enable std::thread for zephyr via posix #25

Closed

Conversation

cfriedt
Copy link
Member

@cfriedt cfriedt commented Dec 1, 2023

Add scaffolding to set required zephyr-specific bits for gcc in order to enable standard C++ threads, mutexes, condition variables, etc, using the POSIX API as a foundation.

Note: it is not possible to run compile and / or link tests under libstdc++-v3 at this time.

@cfriedt cfriedt requested a review from stephanosio December 1, 2023 21:35
@cfriedt
Copy link
Member Author

cfriedt commented Dec 1, 2023

Tested to work with zephyrproject-rtos/zephyr#43729 as of commit cb7b650

Screenshot 2023-12-01 at 4 44 38 PM

The linked PR includes support and tests covering std::thread, std::mutex, std::condition_variable, and quite a bit more.

Copy link
Member

@stephanosio stephanosio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to the comments below, need to regenerate configure script as well.

libstdc++-v3/configure.ac Outdated Show resolved Hide resolved
libstdc++-v3/configure.ac Outdated Show resolved Hide resolved
libstdc++-v3/configure.ac Outdated Show resolved Hide resolved
@cfriedt
Copy link
Member Author

cfriedt commented Dec 4, 2023

In addition to the comments below, need to regenerate configure script as well.

@stephanosio - I just saw that some zephyr things were hard-coded in the ./configure script (which should really be generated and not edited).

Are there some Zephyr-SDK specific steps to regenerating it?

E.g. what about editing gnu-config (aka config) items so that zephyr is recognized as an OS. That is (mainly) what should eventually be upstreamed.

Otherwise, it would be like

  • regenerate ./configure
  • copy out all new sections relevant to the change
  • revert to the previous ./configure
  • manually edit / update new sections relevant to the change

I can imagine that is.. quite a bit of work.. and likely makes life significantly harder than it needs to be

@Flameeyes
Copy link

My recommendation would be to patch autoconf so that it knows about Zephyr, and then use this patched autoconf to regenerate the configure script, even if the autoconf patch is not quite ready for upstream.

Besides giving a head start to upstreaming, this would mean never having to touch the generated files. Which is a lot more resilient.

@stephanosio
Copy link
Member

@stephanosio - I just saw that some zephyr things were hard-coded in the ./configure script (which should really be generated and not edited).

Are there some Zephyr-SDK specific steps to regenerating it?

It is not hard-coded. configure script is generated using autoreconf from configure.ac as done in the upstream GCC (see https://gcc.gnu.org/wiki/Regenerating_GCC_Configuration).

E.g. what about editing gnu-config (aka config) items so that zephyr is recognized as an OS. That is (mainly) what should eventually be upstreamed.

I have already submitted an upstream patch and it was accepted a while ago (it should already be part of the latest GCC config.sub) -- see https://git.savannah.gnu.org/cgit/config.git/commit/?id=401e1a7dd1e082fd110ba9df169d2de9ec2bab74.

Of course, that only makes it "recognise" the target, the rest of the target support still need to be added to GCC and Binutils (which is basically what zephyrproject-rtos/sdk-ng#350 describes).

Copy link
Member

@stephanosio stephanosio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still need to regenerate configure.

libstdc++-v3/acinclude.m4 Outdated Show resolved Hide resolved
libstdc++-v3/acinclude.m4 Outdated Show resolved Hide resolved
libstdc++-v3/acinclude.m4 Outdated Show resolved Hide resolved
@cfriedt
Copy link
Member Author

cfriedt commented Dec 4, 2023

I have already submitted an upstream patch and it was accepted a while ago (it should already be part of the latest GCC config.sub) -- see https://git.savannah.gnu.org/cgit/config.git/commit/?id=401e1a7dd1e082fd110ba9df169d2de9ec2bab74.

Oh nice - I guess my autoconf needs to be updated (has autoconf had a full release since then?).

Of course, that only makes it "recognise" the target, the rest of the target support still need to be added to GCC and Binutils (which is basically what zephyrproject-rtos/sdk-ng#350 describes).

Awesome - I almost forgot about that issue. It's been a while. Making progress though.

@cfriedt cfriedt force-pushed the enable-std-thread branch 14 times, most recently from 4324e58 to 140e38a Compare December 5, 2023 15:23
@cfriedt cfriedt force-pushed the enable-std-thread branch 2 times, most recently from a3b4e76 to ae0b1ba Compare December 5, 2023 18:27
Use the existing gthr-posix.h configuration for gthreads to
enable support in Zephyr for C++ std::thread, std::mutex,
std::condition_variable, std::binary_semaphore,
std::counting_semaphore, and more.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
@cfriedt cfriedt force-pushed the enable-std-thread branch 5 times, most recently from e8326cf to 40469b4 Compare December 5, 2023 20:58
Regenerate the ./configure script with zephyr-specific conditions
to enable std::thread, std::mutex, std::condition_variable,
std::binary_semaphore, std::counting_semaphore, etc.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
This change adds a zephyr-bits.h header file which includes the
basic definitions required to support ISO C++ thread, mutex,
condition variables, and more via POSIX. For additional details
see libgcc/gthr-posix.h .

Note: this header should not be exported; it is solely for the
purpose of enabling C++ threads in the Zephyr SDK when building
against newlib or picolibc.

Signed-off-by: Chris Friedt <cfriedt@meta.com>
Touch-up the generated configure script to reflect changes in
configure.ac .

Signed-off-by: Chris Friedt <cfriedt@meta.com>
@cfriedt
Copy link
Member Author

cfriedt commented Dec 6, 2023

@stephanosio

Building the Zephyr SDK manually is successful with the current changes in #25 and zephyrproject-rtos/sdk-ng#722 but unfortunately CI fails without really having any kind of decent diagnostics or debug information.

build.log.xz.txt (xz -d < build.log.xz.txt > build.log.txt)

Not really sure where to go from here.

@cfriedt
Copy link
Member Author

cfriedt commented Feb 23, 2024

Closing this in favour of the c11 altrnative

@cfriedt cfriedt closed this Feb 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants