Picolibc is a fork of newlib designed and tested on embedded systems. It
offers a smaller memory footprint (both ROM and RAM), and native TLS
support, which uses the Zephyr TLS support.
By default, the full printf version is included in the executable, which
includes exact floating point and long long input and output. A
configuration option has been added to switch to the integer-only
version (which also omits long long support).
Here are some size comparisons using qemu-cortex-m3 and this application
(parameters passed to printf to avoid GCC optimizing it into puts):
void main(void)
{
printf("Hello World! %s %d\n", CONFIG_BOARD, 12);
}
FLASH SRAM
minimal 8696 3952
picolibc int 7600 3960
picolibc float 12304 3960
newlib-nano int 11696 4128
newlib-nano float 30516 4496
newlib 34800 6112
---
v2:
Include picolibc-tls.ld
v3:
Document usage in guides/c_library.rst and
getting_started/toolchain_other_x_compilers.rst
v4:
Lost the lib/libc/picolibc directory somehow!
v5:
Add PICOLIBC_ALIGNED_HEAP_SIZE configuration option.
Delete PICOLIBC_SEMIHOST option support code
v6:
Don't allocate static RAM for TLS values; TLS
values only need to be allocated for each thread.
v7:
Use arm coprocessor for TLS pointer storage where supported for
compatibility with the -mtp=cp15 compiler option (or when the
target cpu type selects this option)
Add a bunch of tests
Round TLS segment up to stack alignment so that overall stack
remains correctly aligned
Add aarch64 support
Rebase to upstream head
v8:
Share NEWLIB, NEWLIB_NANO and PICOLIBC library configuration
variables in a single LIBC_PARTITIONS variable instead of
having separate PICOLIBC_PART and NEWLIB_PART variables.
v9:
Update docs to reference pending sdk-ng support for picolibc
v10:
Support memory protection by creating a partition for
picolibc shared data and any pre-defined picolibc heap.
v11:
Fix formatting in arch/arm/core/aarch64/switch.S
v12:
Remove TLS support from this patch now that TLS is upstream
Require THREAD_LOCAL_STORAGE when using PICOLIBC for architectures
that support it.
v13:
Merge errno changes as they're only needed for picolibc.
Adapt cmake changes suggested by Torsten Tejlmand Rasmussen
v14:
Update to picolibc 1.7 and newer (new stdin/stdout/stderr ABI)
v15:
Respond to comments from dcpleung:
* switch kernel/errno to use CONFIG_LIBC_ERRNO instead of
CONFIG_PICOLIBC
* Add comment to test/lib/sprintf as to why the %n test
was disabled for picolibc.
v16:
Switch picolibc to a module built with Zephyr. This eliminates
toolchain dependencies and allows compiler settings for Zephyr
to also be applied to picolibc.
v17:
Provide Zephyr-specific 'abort' implementation.
Support systems with MMU
v18:
Allow use of toolchain picolibc version.
v19:
Use zephyr/ for zephyr headers
v20:
Add locking
Use explicit commit for picolibc module
v21:
Create PICOLIBC_SUPPORTED config param. Set on arc, arm, arm64,
mips and riscv architectures.
Signed-off-by: Keith Packard <keithp@keithp.com>
240 lines
6.7 KiB
Plaintext
240 lines
6.7 KiB
Plaintext
# C library
|
|
|
|
# Copyright (c) 2016 Intel Corporation
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
menu "C Library"
|
|
|
|
config REQUIRES_FULL_LIBC
|
|
bool
|
|
help
|
|
Helper symbol to indicate some feature requires a C library implementation
|
|
with more functionality than what MINIMAL_LIBC provides
|
|
|
|
config SUPPORT_MINIMAL_LIBC
|
|
bool
|
|
default y
|
|
|
|
config PICOLIBC_SUPPORTED
|
|
bool
|
|
depends on ARC || ARM || ARM64 || MIPS || RISCV
|
|
default y
|
|
help
|
|
Selected when the target has support for picolibc.
|
|
|
|
choice LIBC_IMPLEMENTATION
|
|
prompt "C Library Implementation"
|
|
default EXTERNAL_LIBC if NATIVE_APPLICATION
|
|
default NEWLIB_LIBC if REQUIRES_FULL_LIBC
|
|
default MINIMAL_LIBC
|
|
|
|
config MINIMAL_LIBC
|
|
bool "Minimal C library"
|
|
depends on !NATIVE_APPLICATION
|
|
depends on !REQUIRES_FULL_LIBC
|
|
depends on SUPPORT_MINIMAL_LIBC
|
|
help
|
|
Build with minimal C library.
|
|
|
|
config PICOLIBC
|
|
bool "Picolibc library"
|
|
select LIBC_ERRNO
|
|
select THREAD_LOCAL_STORAGE if ARCH_HAS_THREAD_LOCAL_STORAGE
|
|
depends on !NATIVE_APPLICATION
|
|
help
|
|
Build with picolibc library. The picolibc library is built as
|
|
a module if PICOLIBC_MODULE is set, otherwise picolibc is
|
|
expected to be provided by the toolchain.
|
|
|
|
config NEWLIB_LIBC
|
|
bool "Newlib C library"
|
|
depends on !NATIVE_APPLICATION
|
|
help
|
|
Build with newlib library. The newlib library is expected to be
|
|
part of the SDK in this case.
|
|
|
|
config ARCMWDT_LIBC
|
|
bool "ARC MWDT C library"
|
|
depends on !NATIVE_APPLICATION
|
|
depends on "$(ZEPHYR_TOOLCHAIN_VARIANT)" = "arcmwdt"
|
|
help
|
|
C library provided by ARC MWDT toolchain.
|
|
|
|
config EXTERNAL_LIBC
|
|
bool "External C library"
|
|
help
|
|
Build with external/user provided C library.
|
|
|
|
endchoice # LIBC_IMPLEMENTATION
|
|
|
|
config HAS_NEWLIB_LIBC_NANO
|
|
bool
|
|
|
|
if PICOLIBC
|
|
|
|
source "lib/libc/picolibc/Kconfig"
|
|
|
|
endif # PICOLIBC
|
|
|
|
if NEWLIB_LIBC
|
|
|
|
config NEWLIB_LIBC_NANO
|
|
bool "Build with newlib-nano C library"
|
|
depends on HAS_NEWLIB_LIBC_NANO
|
|
default y
|
|
help
|
|
Build with newlib-nano library, for small embedded apps.
|
|
The newlib-nano library for ARM embedded processors is a part of the
|
|
GNU Tools for ARM Embedded Processors.
|
|
|
|
config NEWLIB_LIBC_MAX_MAPPED_REGION_SIZE
|
|
int "Maximum memory mapped for newlib heap"
|
|
depends on MMU
|
|
default 1048576
|
|
help
|
|
On MMU-based systems, indicates the maximum amount of memory which
|
|
will be used for the newlib malloc() heap. The actual amount of
|
|
memory used will be the minimum of this value and the amount of
|
|
free physical memory at kernel boot.
|
|
|
|
config NEWLIB_LIBC_MIN_REQUIRED_HEAP_SIZE
|
|
int "Newlib minimum required heap size"
|
|
default 2048 if NEWLIB_LIBC_NANO
|
|
default 8192 if !NEWLIB_LIBC_NANO
|
|
help
|
|
Specifies the amount of memory space that must be available for the
|
|
newlib heap. An assertion failure message will be displayed during
|
|
initialization if the memory space available for the newlib heap is
|
|
smaller than this value.
|
|
|
|
config NEWLIB_LIBC_ALIGNED_HEAP_SIZE
|
|
int "Newlib aligned heap size"
|
|
depends on MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT
|
|
depends on USERSPACE
|
|
default 0
|
|
help
|
|
If user mode is enabled, and MPU hardware has requirements that
|
|
regions be sized to a power of two and aligned to their size,
|
|
and user mode threads need to access this heap, then this is necessary
|
|
to properly define an MPU region for the heap.
|
|
|
|
If this is left at 0, then remaining system RAM will be used for this
|
|
area and it may not be possible to program it as an MPU region.
|
|
|
|
config NEWLIB_LIBC_FLOAT_PRINTF
|
|
bool "Build with newlib float printf"
|
|
help
|
|
Build with floating point printf enabled. This will increase the size of
|
|
the image.
|
|
|
|
config NEWLIB_LIBC_FLOAT_SCANF
|
|
bool "Build with newlib float scanf"
|
|
help
|
|
Build with floating point scanf enabled. This will increase the size of
|
|
the image.
|
|
|
|
config NEWLIB_LIBC_HEAP_LISTENER
|
|
bool "Notify heap listeners of newlib libc heap events"
|
|
select HEAP_LISTENER
|
|
help
|
|
Notify registered heap listeners upon certain events related to the newlib
|
|
libc heap usage, such as the heap resize.
|
|
|
|
endif # NEWLIB_LIBC
|
|
|
|
if MINIMAL_LIBC
|
|
|
|
config MINIMAL_LIBC_NON_REENTRANT_FUNCTIONS
|
|
bool "Non-reentrant functions"
|
|
default y if !USERSPACE
|
|
select NEED_LIBC_MEM_PARTITION
|
|
help
|
|
Enable non-reentrant functions that make use of the globals; e.g.
|
|
rand() and gmtime(). The globals must be put into a dedicated C
|
|
library memory partition when CONFIG_USERSPACE=y, and enabling this
|
|
option may require an additional memory protection region.
|
|
|
|
config MINIMAL_LIBC_MALLOC
|
|
bool "Minimal libc malloc implementation"
|
|
default y
|
|
help
|
|
Enable the minimal libc's implementation of malloc, free, and realloc.
|
|
Disable if you wish to provide your own implementations of these functions.
|
|
|
|
config MINIMAL_LIBC_MALLOC_ARENA_SIZE
|
|
int "Size of the minimal libc malloc arena"
|
|
default 0
|
|
depends on MINIMAL_LIBC_MALLOC
|
|
help
|
|
Indicate the size in bytes of the memory arena used for
|
|
minimal libc's malloc() implementation.
|
|
|
|
config MINIMAL_LIBC_CALLOC
|
|
bool "Minimal libc trivial calloc implementation"
|
|
default y
|
|
help
|
|
Enable the minimal libc's trivial implementation of calloc, which
|
|
forwards to malloc and memset.
|
|
|
|
config MINIMAL_LIBC_REALLOCARRAY
|
|
bool "Minimal libc trivial reallocarray implementation"
|
|
default y
|
|
help
|
|
Enable the minimal libc's trivial implementation of reallocarray, which
|
|
forwards to realloc.
|
|
|
|
config MINIMAL_LIBC_LL_PRINTF
|
|
bool "Build with minimal libc long long printf" if !64BIT
|
|
default y if 64BIT
|
|
help
|
|
Build with long long printf enabled. This will increase the size of
|
|
the image.
|
|
|
|
config MINIMAL_LIBC_OPTIMIZE_STRING_FOR_SIZE
|
|
bool "Use size optimized string functions"
|
|
default y if SIZE_OPTIMIZATIONS
|
|
help
|
|
Enable smaller but potentially slower implementations of memcpy and
|
|
memset. On the Cortex-M0+ this reduces the total code size by 120 bytes.
|
|
|
|
config MINIMAL_LIBC_RAND
|
|
bool "Rand and srand functions"
|
|
help
|
|
Enable rand_r() for the minimal libc.
|
|
|
|
In order to make use of the non-reentrant rand() and srand(), it is
|
|
necessary to set CONFIG_MINIMAL_LIBC_NON_REENTRANT_FUNCTIONS=y.
|
|
|
|
config MINIMAL_LIBC_TIME
|
|
bool "Time functions"
|
|
default y
|
|
help
|
|
Enable time() and gmtime_r() for the minimal libc.
|
|
|
|
time() requires CONFIG_POSIX_CLOCK=y because it relies on the POSIX
|
|
clock_gettime() function.
|
|
|
|
In order to make use of the non-reentrant gmtime(), it is necessary
|
|
to set CONFIG_MINIMAL_LIBC_NON_REENTRANT_FUNCTIONS=y.
|
|
|
|
endif # MINIMAL_LIBC
|
|
|
|
config STDOUT_CONSOLE
|
|
bool "Send stdout to console"
|
|
depends on CONSOLE_HAS_DRIVER
|
|
depends on !NATIVE_APPLICATION
|
|
default y
|
|
help
|
|
This option directs standard output (e.g. printf) to the console
|
|
device, rather than suppressing it entirely. See also EARLY_CONSOLE
|
|
option.
|
|
|
|
config NEED_LIBC_MEM_PARTITION
|
|
bool
|
|
help
|
|
Hidden option to signal that a memory partition is needed for
|
|
the C library even though it would not have been enabled
|
|
otherwise.
|
|
|
|
endmenu
|