[Picolibc] Integrating Picolibc into a GCC toolchain

Keith Packard keithp at keithp.com
Sun Jan 23 19:20:36 PST 2022


"R. Diez" <rdiezmail-newlib at yahoo.de> writes:

> 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.

This is the preferred technique; the compiler flags set in that file are
only those which are target-specific and not required by picolibc
itself; anything picolibc requires would be set in the picolibc
meson.build files instead.

Those cross-compilation scripts are really intended to be examples, not
part of the "official" picolibc bits I happen to use them for testing
picolibc, and for building the debian packages of picolibc, but you
should feel free to do whatever works for you.

> Is there a ready-made example somewhere of a script of makefile that
> builds a complete cross-compilation toolchain with Picolibc instead of
> Newlib?

Yup, crosstool-ng can build picolibc as one of the supported C
libraries, and it does this by creating a suitable cross-compilation
control file.

> 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++.

If you use crosstool-ng, it has all of that sorted out; it will build
libstdc++ for each target C library. Similarly, debian has a
libstdc++-arm-none-eabi-picolibc package which is all ready for use.

I got the necessary libstdc++ changes submitted to the GCC project a
while ago, and I think they were included in version 10.

I test picolibc with libstdc++ to make sure <iostream> and exceptions
work; there's an example that works on debian in the 'hello-world'
directory in picolibc.

The trick with libstdc++ is that the include directives in the upstream
source break in the presence of more than one C library. Crosstool-ng
and debian both include fixes to work around that issue.

Yes, I'd love to get to the point where newlib wasn't the default C
library for embedded systems and I could assume that picolibc was the
only C library we needed to deal with, but until that point, I feel like
making sure things work even if you do have two C libraries installed is
the best solution achievable. Sigh.

-- 
-keith
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://keithp.com/pipermail/picolibc/attachments/20220123/c0f7bad2/attachment.sig>


More information about the Picolibc mailing list