Copyright © 2018,2019 Keith Packard
PicoLibc is library offering standard C library APIs that targets small embedded systems with limited RAM. PicoLibc was formed by blending code from Newlib and AVR Libc.
Picolibc source comes from a variety of places and has a huge variety of copyright holders and license texts. While much of the code comes from newlib, none of the GPL-related bits are left in the repository, so all of the source code uses BSD-like licenses, a mixture of 2- and 3- clause BSD itself and a variety of other (mostly older) licenses with similar terms.
Please see the file COPYING.NEWLIB in this distribution for newlib license terms.
Picolibc inherited code for a lot of architectures from newlib, but at this point only has code to build for the following targets:
- ARM (32-bit only)
- i386 (Linux hosted, for testing)
- RISC-V (both 32- and 64- bit)
- x86_64 (Linux hosted, for testing)
- PowerPC
Supporting architectures that already have newlib code requires:
- newlib/libc/machine/architecture/meson.build to build any architecture-specific libc bits
- newlib/libm/machine/architecture/meson.build to build any architecture-specific libm bits
- picocrt/machine/architecture source code and build bits if you need custom startup code for the architecture.
- cross-gcc-triple.txt to configure the meson cross-compilation mechanism to use the right tools
- do-architecture-configure to make testing the cross-compilation setup easier.
Picolibc is mostly built from pieces of newlib, and retains the directory structure of that project. While there have been a lot of changes in the build system and per-thread data storage, the bulk of the source code remains unchanged.
To keep picolibc and newlib code in sync, newlib changes will be regularly incorporated. To ease integration of these changes into picolibc, some care needs to be taken while editing the code:
- Files should not be renamed.
- Fixes that also benefit users of newlib should also be sent to the newlib project
- Changes, where possible, should be made in a way compatible with newlib design. For example, instead of using 'errno' (which is valid in picolibc), use __errno_r(r), even when 'r' is not defined in the local context.
The bulk of newlib changes over the last several years have been in areas unrelated to the code used by picolibc, so keeping things in sync has not been difficult so far.
This release includes important fixes in picolibc.ld and more semihosting support.
-
File I/O and clock support for semihosting. This enables fopen/fdopen support in tinystdio along with an API to fetch a real time clock value.
-
Fix picolibc.ld to not attempt to use redefined symbols for memory space definitions. These redefinitions would fail and the default values be used for system memory definitions. Instead, just use the ? : operators each place the values are needed. Linker scripts continue to mystify.
-
Expose library definitions in 'picolibc.h', instead of 'newlib.h' and '_newlib_version.h'
-
Define HAVE_SEMIHOST when semihosting support is available. This lets the 'hello-world' example do some semihost specific things.
A minor update from 1.0, this release includes:
-
semihost support. This adds console I/O and exit(3) support on ARM and RISC-V hosts using the standard semihosting interfaces.
-
Posix I/O support in tinystdio. When -Dposix-io=true is included in the meson command line (which is the default), tinystdio adds support for fopen and fdopen by using malloc, open, close, read, write and lseek. If -Dposix-console=true is also passed to meson, then picolibc will direct stdin/stdout/stderr to the posix standard file descriptors (0, 1, 2).
-
Merge recent upstream newlib code. This brings picolibc up to date with current newlib sources.
-
Hello world example. This uses a simple Makefile to demonstrate how to us picolibc when installed for ARM and RISC-V embedded processors. The resulting executables can be run under qemu.
-
Remove newlib/libm/mathfp directory. This experimental code never worked correctly anyways.
This is the first release of picolibc. Major changes from newlib include:
-
Remove all non-BSD licensed code. None of it was used in building the embedded library, and removing it greatly simplifies the license situation.
-
Move thread-local values to native TLS mechanism
-
Add smaller stdio from avr-libc, which is enabled by default
-
Switch build system to meson. This has two notable benefits; the first is that building the library is much faster, the second is that it isolates build system changes from newlib making merging of newlib changes much easier.
-
Add simple startup code. This can be used in environments that don't have complicated requirements, allowing small applications to avoid needing to figure this out.