-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Support toolchain with optimization levels included in multilib configurations #79887
base: main
Are you sure you want to change the base?
Support toolchain with optimization levels included in multilib configurations #79887
Conversation
In addition to warning about a mismatch between Zephyr's optimization setting and the CMAKE_BUILD_TYPE, apply Zephyr's optimization flags to the relevant CMAKE_C_FLAGS_ value so that when those are used, the right value is applied. When the warning is disabled, leave things alone. Signed-off-by: Keith Packard <[email protected]>
Cover the other common C library Signed-off-by: Keith Packard <[email protected]>
Instead of pre-computing the toolchain library path using options available early in the configuration process, delay until the related file names are actually needed, by which time the remaining compiler options have been computed (most notably ${OPTIMIZATION_FLAG}). Remove the computatlib of LIBGCC_DIR entirely; that will be done by the compiler driver at link time without needed any help. Signed-off-by: Keith Packard <[email protected]>
This obviously requires a new toolchain to be useful; that work is visible here: zephyrproject-rtos/sdk-ng#821 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No complaints here, though I still maintain that the sudden interest in optimized libc is really a symptom of a poorly-thought-out API in msgq that demands a general copy vs. the ThreadX equivalent which is word-chunked.
I mean, sure, better to have a fast memcpy() than not (and, OK, picolibc looked to be benching a bit behind our own built-in and newlib). But really we shouldn't have been calling libc at all in that case and eating complexity here may not be as good a tradeoff as it sounds (though this doesn't look so bad at all).
Picolibc is providing the size-optimized version by default while newlib is build with speed optimizations turned on. We could always hack up the picolibc code to always provide speed-optimized copy code; it already has the |
That actually sounds like it might be the best default to me if the rig is there to change the optimizations on per-module levels. Really just mem{cpy,move,set}() would surely be all that Zephyr cares about (we make very sparing use of the string library). |
Getting the toolchain libraries all built with -Os means we also get -Os versions of libgcc and libstdc++. The latter is probably of interest to anyone using C++ in their apps where space is an issue (hard for me to imagine, but?). And, of course, applications using more of the C library than core Zephyr might have a deeper interest in the space/speed tradeoff here. I just don't know; using the multilib stuff to enable this feature seems like a modest change, instead of having a wealth of per-API configuration bits? I assume we wouldn't always want speed-optimized memcpy? |
As a way to provide both space and speed optimized versions of every library provided by a toolchain, one option I'm exploring is adding optimization level to the existing multilib infrastructure. With this, specifying -Os during the linking phase will cause the compiler driver to adjust the link path to point at a directory containing libraries also build with -Os.
To make this work in Zephyr, a couple of changes are required:
crtbegin.o
andcrtend.o
. I've created a function,compiler_file_name
which uses the gcc--print-file-name
option to search for those files. Because those file names are needed well after OPTIMIZATION_FLAG is set, we can add that to the gcc command line and have it perform the full multi-lib search for us.With these changes, I've got -Os and -O2 tests for at least a few cases working using locally-built SDK toolchains that include the necessary changes.
Size:
Speed:
Note that this extends to all toolchain-provided libraries, including newlib and libstdc++.