[Picolibc] Integrating Picolibc into a GCC toolchain
R. Diez
rdiezmail-newlib at yahoo.de
Sun Jan 23 13:02:59 PST 2022
Hi Keith:
I have been using the following makefile for years to build a cross-compiler GCC toolchain with Newlib:
https://github.com/rdiez/JtagDue/blob/master/Toolchain/Makefile
I would like to replace Newlib with Picolibc.
The main problem I am facing is that I need to carefully control the compiler flags. This is the file where the flags for my target are specified:
scripts/cross-arm-none-eabi.txt
I need to replace this line:
c_args = [ '-nostdlib', '-fno-common']
with something like this:
c_args = [ '-nostdlib', '-fno-common',
'-g', '-O2',
'-mcpu=cortex-m3', '-mthumb',
'-fno-omit-frame-pointer',
'-fdata-sections', '-ffunction-sections',
'-DHAVE_ASSERT_FUNC'
]
Or whatever the flags are for today's toolchain.
Newlib's configuration script honours CFLAGS_FOR_TARGET and CXXFLAGS_FOR_TARGET to that effect, but Picolibc uses Meson which has known shortcomings in this area when cross-compiling.
I heard that some users generate scripts/cross-arm-none-eabi.txt with the right flags. However, I would rather not change anything else in that file, only the c_args line, in case the next version of Picolibc ships with different settings before or after c_args unrelated to the compiler flags.
What are my options?
Is there a ready-made example somewhere of a script of makefile that builds a complete cross-compilation toolchain with Picolibc instead of Newlib?
There are ways to make a standard GCC toolchain use a different libc than the one built-in, but
creating a GCC toolchain with an integrated Picolib has the following advantages:
1) It is convenient. No need to mess around with some weird --specs=picolibc.specs argument or the like.
2) No need to worry about the C++ support library. Normally, GCC comes with an integrated C++ support library that has been built against the integrated libc (such as Newlib). I haven't figured out yet how to rebuild that C++ support library against Picolibc and tell GCC it should be using another version when it is using a different libc. My firmware is actually written in C++.
Thanks in advance,
rdiez
--
rdiez
More information about the Picolibc
mailing list