Skip to content

Build -Os and -O2 versions of every target library #821

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 13 commits into from
May 1, 2025
Merged

Conversation

keith-packard
Copy link
Collaborator

@keith-packard keith-packard commented Oct 14, 2024

This uses a new gcc config option, --enable-multilib-space, which duplicates every multilib configuration, adding
a new version which optimizes for space. With this, every library in the toolchain will get built twice and will be selected
depending on the options applied during the link phase. Add -Os or -Oz and you will get space-optimized versions of every toolchain library.

crosstool-ng PR: zephyrproject-rtos/crosstool-ng#26
GCC PR: zephyrproject-rtos/gcc#39
Picolibc PR: TBD

@abrodkin
Copy link
Collaborator

@keith-packard that feature looks awesome, and as usual only two questions:

  1. Any plans to get it submitted to the upstream Crosstool-NG?
  2. any chance to get that patch zephyrproject-rtos/gcc@34caa70 submitted to the GCC upstream?

@keith-packard
Copy link
Collaborator Author

@keith-packard that feature looks awesome, and as usual only two questions:

1. Any plans to get it submitted to the upstream Crosstool-NG?

Yup, once we know how this will work upstream in gcc, we can figure out how to get it merged to ct-ng.

2. any chance to get that patch [zephyrproject-rtos/gcc@34caa70](https://github.com/zephyrproject-rtos/gcc/commit/34caa704141c7ccde3ed2e0a7512ca636cb29bc5) submitted to the GCC upstream?

Yup, already submitted. https://gcc.gnu.org/pipermail/gcc-patches/2024-October/665446.html

@keith-packard
Copy link
Collaborator Author

keith-packard commented Oct 21, 2024

This is actually working when I disabled newlib-nano to keep the build times in check. The only testing failure occurred when a newlib-nano test slipped through; that should be fixed with zephyrproject-rtos/zephyr#80161.

Here's my best guess as to the space required for an x86_64 linux toolchain:

Only -Os    9GB
-Os+-O2     13GB

This includes -Os and -O2 versions of picolibc, newlib and newlib-nano along with libstdc++ compiled for each one. We could probably hack things up so that newlib was only provided in -O2 version while newlib-nano only in -Os; that would save two thirds of the increase measured above.

There isn't a great alternative here -- we can tell people to use the module when they need -O2, but that rules out using C++ with -O2.

When can we consider reducing the number of C library variants provided in the SDK?

@stephanosio
Copy link
Member

This is actually working when I disabled newlib-nano to keep the build times in check. The only testing failure occurred when a newlib-nano test slipped through; that should be fixed with zephyrproject-rtos/zephyr#80161.

I have cherry-picked that patch into the collab-sdk-dev branch for now so that this can be tested.

When can we consider reducing the number of C library variants provided in the SDK?

I think trying to completely remove newlib from the SDK is going to be met with a lot of backlashes.

Another option would be to remove newlib from the main SDK distribution and create a separate newlib "overlay," which can be downloaded and installed only if one needs it (similar to what LLVM Embedded Toolchain for Arm does).

@keith-packard
Copy link
Collaborator Author

This is actually working when I disabled newlib-nano to keep the build times in check. The only testing failure occurred when a newlib-nano test slipped through; that should be fixed with zephyrproject-rtos/zephyr#80161.

I have cherry-picked that patch into the collab-sdk-dev branch for now so that this can be tested.

Thanks.

I think trying to completely remove newlib from the SDK is going to be met with a lot of backlashes.

Yeah, was only thinking about newlib-nano.

Another option would be to remove newlib from the main SDK distribution and create a separate newlib "overlay," which can be downloaded and installed only if one needs it (similar to what LLVM Embedded Toolchain for Arm does).

That would save a huge amount of space, and should be fairly easy to implement.

@stephanosio stephanosio added the DNM DO NOT MERGE label Oct 24, 2024
@stephanosio
Copy link
Member

@keith-packard crosstool-ng PR has been merged. Can you please open a PR for GCC and picolibc (or do upstream sync for it)?

@keith-packard
Copy link
Collaborator Author

Will take care of this tomorrow.

@keith-packard
Copy link
Collaborator Author

I've got the GCC PR queued. zephyrproject-rtos/picolibc main is sync'd with picolibc main to pull in fixes for arc, xtensa and add uchar.h

@stephanosio
Copy link
Member

Merged GCC PR.

It looks like I merged wrong crosstool-ng PR (though, I assume it is still valid?) and crosstool-ng submodule is still pointing to multlib-space branch.

Could you please open a PR for crosstool-ng as well?

@keith-packard
Copy link
Collaborator Author

Merged GCC PR.

It looks like I merged wrong crosstool-ng PR (though, I assume it is still valid?) and crosstool-ng submodule is still pointing to multlib-space branch.

Could you please open a PR for crosstool-ng as well?

zephyrproject-rtos/crosstool-ng#30

Note that the build tests are currently failing because Zephyr is defining values which are required to be present in limits.h (and which upstream picolibc now includes). zephyrproject-rtos/zephyr#80409

@keith-packard
Copy link
Collaborator Author

I've rebased this PR and have a plan to make it workable -- we don't need space optimized versions of every library for every target, only for targets which need the smallest possible executables. I've proposed that we deliver space optimized variants only for arm and arc. We can easiliy add more by modifying the SDK configuration files to add 'CT_MULTILIB_SPACE=y' as desired.

@keith-packard keith-packard force-pushed the multilib-space branch 3 times, most recently from 29f7c44 to 70cfba4 Compare March 27, 2025 21:54
@keith-packard keith-packard force-pushed the multilib-space branch 4 times, most recently from 84a5049 to cae3442 Compare April 6, 2025 08:39
Need to use BUILD_DIR instead of WORKSPACE as the latter hasn't been
set at this point.

Signed-off-by: Keith Packard <[email protected]>
Make sure we catch build failures.

Signed-off-by: Keith Packard <[email protected]>
This makes it possible to build picolibc for microblazeel

Signed-off-by: Keith Packard <[email protected]>
Picolibc has had microblazeel support since version 1.8.2, which was
released about two years ago.

Signed-off-by: Keith Packard <[email protected]>
Merge GCC version with multilib-space support which adds
-Os versions of every multilib configuration.

Signed-off-by: Keith Packard <[email protected]>
The CT_MULTILIB_SPACE option passes --enable-multilib-space to gcc so
that we get -Os versions of every multilib configuration.

Signed-off-by: Keith Packard <[email protected]>
Switch to latest picolibc release, 1.8.10

Signed-off-by: Keith Packard <[email protected]>
@keith-packard keith-packard force-pushed the multilib-space branch 3 times, most recently from bc8f5cf to 1cfc4b1 Compare April 22, 2025 15:12
keith-packard and others added 6 commits April 22, 2025 12:31
Add rx-zephyr target support and multilib options.

Signed-off-by: Keith Packard <[email protected]>
This adds basic RX architecture information along with the rx.sh
helper script.

Signed-off-by: Keith Packard <[email protected]>
This commit only add minimal require part to enable Renesas
RX architecture gcc toolchain build on Zephyr SDK

Signed-off-by: Duy Nguyen <[email protected]>
This provides -Os versions of every toolchain library for these two
targets. Other targets that want to add the -Os versions can include
CT_MULTILIB_SPACE=y to their config files.

Signed-off-by: Keith Packard <[email protected]>
@nashif nashif removed the DNM DO NOT MERGE label May 1, 2025
@nashif nashif merged commit 90d6193 into main May 1, 2025
41 checks passed
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.

5 participants