Skip to content

Adding picolibc as a module #44143

@keith-packard

Description

@keith-packard

Origin

Picolibc is available on github. The "official" upstream
repository is hosted in my own domain keithp.com/picolibc

Purpose

Picolibc provides a full libc implementation based on a combination of code from newlib, avr libc along with substantial new code, including the ryu floating point conversion code which provides malloc-free exact decimal/binary conversion of 32 and 64 bit IEEE floating point values.

Mode of integration

As picolibc is used in numerous other projects, it should be integrated into zephyr as a module.

Pull Request

The PR is #44096 has been modified to take advantage of cmake support which has been added to picolibc.

Description

Right now, Zephyr provides developers with several C library options, Newlib, Newlib-nano and a tiny 'minimal C library' included in tree. Picolibc fits in between these offerings with a full POSIX implementation like newlib/newlib-nano, but with a footprint similar to the included minimal library.

I think Picolibc could replace the current minimal C library, reducing the maintenance burden on the Zephyr project while offering users a better tested and more standards-conforming implementation, while potentially decreasing the amount of memory used by the resulting applications.

Picolibc could be made available through the Zephyr SDK as Crosstool-ng has the necessary support. However, that would mean selecting from the small number of binary configurations provided in that SDK, and would mean it wasn't available when using a different toolchain. Picolibc is routinely tested using GCC and Clang, and has been used with the CompCert verified C compiler. The codebase is tested using --std=c18 to ensure it remains in compliance with ISO/IEC 9899:2018.

Compared with newlib or newlib-nano, picolibc eliminates the 'struct _reent' by using TLS variables, replaces the large stdio stack with a lighter weight implementation which doesn't require malloc and has an integrated test suite which is used as part of the CI system to validate changes. Picolibc is also regularly tested using significant portions of the glibc test suite. All of that testing has led to dozens of bug fixes, many of which have been sent upstream to newlib, but many cannot as the picolibc code has diverged in significant ways, especially the math library.

Picolibc has very clear BSD licensing for the library source code; all of the non-BSD code included in the newlib repository has been removed. There are some tests and sample scripts which are not BSD licensed, but none of those are involved in building the library itself.

Dependencies

The library itself only requires a C compiler (tested with GCC in C99, C11 and C18 modes), and Picolibc now has native cmake support. Picolibc is designed to work with systems that support thread local storage; all C library APIs which need per-thread storage use this mechanism, including errno.

Revision

Picolibc includes a zephyr branch which has the necessary fixes and cmake support. When we're ready to merge this PR, that should shift to using a specific revision in the west configuration file.

License

Picolibc is "BSD" licensed, but that includes numerous versions of BSD-2 and BSD-3 licenses, along with some other variants.

Resources

Metadata

Metadata

Assignees

No one assigned

    Labels

    RFCRequest For Comments: want input from the communityarea: C LibraryC Standard Library

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions