Add newlib-nano as companion lib

This allows building newlib-nano in addition to newlib and picolibc,
allowing users to select between C libraries within the same toolchain.

Signed-off-by: Keith Packard <keithp@keithp.com>
This commit is contained in:
Keith Packard 2021-01-09 00:06:43 -08:00
parent fcf323336e
commit 945b4c6436
5 changed files with 364 additions and 0 deletions

View File

@ -0,0 +1,224 @@
# newlib-nano options
## depends on BARE_METAL
## help Newlib-nano is a C library intended for use on embedded systems. It is a
## help conglomeration of several library parts, all under free software
## help licenses that make them easily usable on embedded products. Newlib-nano
## help is only available in source form. It can be compiled for a wide
## help array of processors, and will usually work on any architecture with
## help the addition of a few low-level routines.
# maybe older versions of newlib will support it too, but this
# needs to be checked
config NEWLIB_NANO_CXA_ATEXIT
def_bool y
depends on NEWLIB_NANO_2_0_or_later
select LIBC_PROVIDES_CXA_ATEXIT
config NEWLIB_NANO_HAS_NANO_MALLOC
def_bool y
depends on NEWLIB_NANO_2_1_or_later
config NEWLIB_NANO_HAS_NANO_FORMATTED_IO
def_bool y
depends on NEWLIB_NANO_2_2_or_later
config LIBC_NEWLIB_NANO_TARGET_CFLAGS
string
prompt "Target CFLAGS for newlib"
default ""
help
Used to add specific options when compiling the target libraries
(eg. -ffunction-sections -fdata-sections), which can't be defined
in global TARGET_CFLAGS, because they shall be not used for the
gcc target libraries.
Note: Both TARGET_CFLAGS and LIBC_NEWLIB_NANO_TARGET_CFLAGS are used
to compile the libraries.
Leave blank if you don't know better.
config LIBC_NEWLIB_NANO_IO_C99FMT
bool
prompt "Enable IOs on C99 formats"
help
Enable support for IOs on C99 formats.
config LIBC_NEWLIB_NANO_IO_LL
bool
prompt "Enable IOs on long long"
help
Enable support for IOs on long long integers.
config LIBC_NEWLIB_NANO_IO_FLOAT
bool
prompt "Enable IOs on floats and doubles"
help
Enable support for IOs on floating point
values (float and double).
config LIBC_NEWLIB_NANO_IO_LDBL
bool
prompt "Enable IOs on long doubles"
depends on LIBC_NEWLIB_NANO_IO_FLOAT
help
Enable support for IOs on long doubles.
config LIBC_NEWLIB_NANO_IO_POS_ARGS
bool
prompt "Enable printf-family positional arg support"
help
Enable printf-family positional arg support.
config LIBC_NEWLIB_NANO_FVWRITE_IN_STREAMIO
bool
prompt "Vector buffer mechanism to support stream IO buffering"
default y
help
NEWLIB implements the vector buffer mechanism to support stream IO
buffering required by C standard. This feature is possibly
unnecessary for embedded systems which won't change file buffering
with functions like `setbuf' or `setvbuf'. The buffering mechanism
still acts as default for STDIN/STDOUT/STDERR even if this option
is specified.
config LIBC_NEWLIB_NANO_UNBUF_STREAM_OPT
bool
prompt "Optimize fprintf to unbuffered unix file"
help
NEWLIB does optimization when `fprintf to write only unbuffered unix
file'. It creates a temorary buffer to do the optimization that
increases stack consumption by about `BUFSIZ' bytes. Disabling this option
disables the optimization and saves size of text and stack.
config LIBC_NEWLIB_NANO_FSEEK_OPTIMIZATION
bool
prompt "Fseek optimisation"
help
Disabling fseek optimisation can decrease code size.
config LIBC_NEWLIB_NANO_DISABLE_SUPPLIED_SYSCALLS
bool
prompt "Disable the syscalls supplied with newlib"
help
Disable the syscalls that come with newlib. You
will have to implement your own _sbrk, _read,
_write... If you plan to port newlib to a new
platform/board, say Yes.
config LIBC_NEWLIB_NANO_REGISTER_FINI
bool
prompt "Enable finalization function registration using atexit"
help
Enable finalization function registration using atexit.
config LIBC_NEWLIB_NANO_ATEXIT_DYNAMIC_ALLOC
bool
prompt "Enable dynamic allocation of atexit entries"
default y
help
Enable dynamic allocation of atexit entries.
config LIBC_NEWLIB_NANO_GLOBAL_ATEXIT
bool
prompt "Enable atexit data structure as global variable"
default y
help
Enable atexit data structure as global variable. By doing so it is
move out of _reent structure, and can be garbage collected if atexit
is not referenced.
config LIBC_NEWLIB_NANO_LITE_EXIT
bool
prompt "Enable lite exit"
default y
help
Enable lite exit, a size-reduced implementation of exit that doesn't
invoke clean-up functions such as _fini or global destructors.
config LIBC_NEWLIB_NANO_REENT_SMALL
bool
prompt "Enable small reentrant struct support"
default y
help
Enable small reentrant struct support.
config LIBC_NEWLIB_NANO_MULTITHREAD
bool
prompt "Enable support for multiple threads"
default y
help
Enable support for multiple threads.
config LIBC_NEWLIB_NANO_RETARGETABLE_LOCKING
bool
prompt "Enable retargetable locking"
help
Enable retargetable locking to allow the operating system to override
the dummy lock functions defined within the newlib.
config LIBC_NEWLIB_NANO_EXTRA_SECTIONS
bool
prompt "Place each function & data element in their own section"
help
Place each function & data symbol in their own section. This allows
the linker to garbage collect unused symbols at link time.
config LIBC_NEWLIB_NANO_WIDE_ORIENT
bool
prompt "Allow wide C99 stream orientation"
default n
help
C99 states that each stream has an orientation, wide or byte. This
feature is possibly unnecessary for embedded systems which only do
byte input/output operations on stream. Disabling this feature can
decrease code size.
config LIBC_NEWLIB_NANO_ENABLE_TARGET_OPTSPACE
bool
prompt "Optimize newlib for size"
default y
help
Pass --enable-target-optspace to newlib configure.
This will compile newlib with -Os.
config LIBC_NEWLIB_NANO_LTO
bool
prompt "Enable Link Time Optimization"
depends on CC_GCC_USE_LTO
help
Builds the libraries with -flto to enable more aggressive link time
optimization. You will need to add -flto-partition=one to your
application's link line to keep the RETURN assembler macro together
with it's consumers.
config LIBC_NEWLIB_NANO_NANO_MALLOC
bool
prompt "Enable Nano Malloc"
default y
depends on NEWLIB_NANO_HAS_NANO_MALLOC
help
NEWLIB has two implementations of malloc family's functions, one in
`mallocr.c' and the other one in `nano-mallocr.c'. This options
enables the nano-malloc implementation, which is for small systems
with very limited memory. Note that this implementation does not
support `--enable-malloc-debugging' any more.
config LIBC_NEWLIB_NANO_NANO_FORMATTED_IO
bool
prompt "Enable Nano Formatted I/O"
default y
depends on NEWLIB_NANO_HAS_NANO_FORMATTED_IO
help
This builds NEWLIB with a special implementation of formatted I/O
functions, designed to lower the size of application on small systems
with size constraint issues. This option does not affect wide-char
formatted I/O functions.
config LIBC_NEWLIB_NANO_EXTRA_CONFIG_ARRAY
string
prompt "Extra config for newlib"
default ""
help
Extra flags to pass onto ./configure when configuring the newlib.

1
packages/newlib-nano/3.3.0 Symbolic link
View File

@ -0,0 +1 @@
../newlib/3.3.0/

View File

@ -0,0 +1,10 @@
origin='RedHat'
repository='git git://sourceware.org/git/newlib-cygwin.git'
# Do not use "$(CT_Mirrors sourceware newlib)" here: the mirrors (kernel.org
# and gnu.org) only store some older releases of newlib (2.0.0 and before).
mirrors='ftp://sourceware.org/pub/newlib'
milestones='2.0 2.1 2.2'
relevantpattern='*.*|.*. *.*|.'
archive_filename='newlib-@{version}'
archive_dirname='newlib-@{version}'
archive_formats='.tar.gz'

View File

@ -8,3 +8,4 @@ CT_LIBC_NEWLIB_DISABLE_SUPPLIED_SYSCALLS=y
CT_CC_LANG_CXX=y
CT_COMP_LIBS_PICOLIBC=y
CT_TARGET_CFLAGS="-ftls-model=local-exec"
CT_COMP_LIBS_NEWLIB_NANO=y

View File

@ -0,0 +1,128 @@
# This file adds functions to build the Newlib library using the 'nano' configuration
# Copyright © 2021 Keith Packard
# Licensed under the GPL v2 or later. See COPYING in the root of this package
#
# Edited by Keith Packard <keithp@keithp.com>
#
do_newlib_nano_get() { :; }
do_newlib_nano_extract() { :; }
do_newlib_nano_for_build() { :; }
do_newlib_nano_for_host() { :; }
do_newlib_nano_for_target() { :; }
if [ "${CT_COMP_LIBS_NEWLIB_NANO}" = "y" ]; then
# Download newlib_nano
do_newlib_nano_get() {
CT_Fetch NEWLIB_NANO
}
do_newlib_nano_extract() {
CT_ExtractPatch NEWLIB_NANO
}
do_newlib_nano_for_target() {
local -a newlib_nano_opts
local cflags_for_target
CT_DoStep INFO "Installing Newlib Nano library"
CT_mkdir_pushd "${CT_BUILD_DIR}/build-newlib_nano-build-${CT_BUILD}"
CT_DoLog EXTRA "Configuring Newlib Nano library"
# Multilib is the default, so if it is not enabled, disable it.
if [ "${CT_MULTILIB}" != "y" ]; then
newlib_nano_opts+=("-Dmultilib=false")
fi
if [ "${CT_LIBC_NEWLIB_NANO_IO_FLOAT}" = "y" ]; then
newlib_opts+=( "--enable-newlib-io-float" )
if [ "${CT_LIBC_NEWLIB_NANO_IO_LDBL}" = "y" ]; then
newlib_opts+=( "--enable-newlib-io-long-double" )
else
newlib_opts+=( "--disable-newlib-io-long-double" )
fi
else
newlib_opts+=( "--disable-newlib-io-float" )
newlib_opts+=( "--disable-newlib-io-long-double" )
fi
if [ "${CT_LIBC_NEWLIB_NANO_DISABLE_SUPPLIED_SYSCALLS}" = "y" ]; then
newlib_opts+=( "--disable-newlib-supplied-syscalls" )
else
newlib_opts+=( "--enable-newlib-supplied-syscalls" )
fi
yn_args="IO_POS_ARGS:newlib-io-pos-args
IO_C99FMT:newlib-io-c99-formats
IO_LL:newlib-io-long-long
REGISTER_FINI:newlib-register-fini
NANO_MALLOC:newlib-nano-malloc
NANO_FORMATTED_IO:newlib-nano-formatted-io
ATEXIT_DYNAMIC_ALLOC:newlib-atexit-dynamic-alloc
GLOBAL_ATEXIT:newlib-global-atexit
LITE_EXIT:lite-exit
REENT_SMALL:newlib-reent-small
MULTITHREAD:newlib-multithread
RETARGETABLE_LOCKING:newlib-retargetable-locking
WIDE_ORIENT:newlib-wide-orient
FSEEK_OPTIMIZATION:newlib-fseek-optimization
FVWRITE_IN_STREAMIO:newlib-fvwrite-in-streamio
UNBUF_STREAM_OPT:newlib-unbuf-stream-opt
ENABLE_TARGET_OPTSPACE:target-optspace
"
for ynarg in $yn_args; do
var="CT_LIBC_NEWLIB_NANO_${ynarg%:*}"
eval var=\$${var}
argument=${ynarg#*:}
if [ "${var}" = "y" ]; then
newlib_opts+=( "--enable-$argument" )
else
newlib_opts+=( "--disable-$argument" )
fi
done
[ "${CT_LIBC_NEWLIB_NANO_EXTRA_SECTIONS}" = "y" ] && \
CT_LIBC_NEWLIB_NANO_TARGET_CFLAGS="${CT_LIBC_NEWLIB_NANO_TARGET_CFLAGS} -ffunction-sections -fdata-sections"
[ "${CT_LIBC_NEWLIB_NANO_LTO}" = "y" ] && \
CT_LIBC_NEWLIB_NANO_TARGET_CFLAGS="${CT_LIBC_NEWLIB_NANO_TARGET_CFLAGS} -flto"
cflags_for_target="${CT_ALL_TARGET_CFLAGS} ${CT_LIBC_NEWLIB_NANO_TARGET_CFLAGS}"
# Note: newlib handles the build/host/target a little bit differently
# than one would expect:
# build : not used
# host : the machine building newlib
# target : the machine newlib runs on
CT_DoExecLog CFG \
CC_FOR_BUILD="${CT_BUILD}-gcc" \
CFLAGS_FOR_TARGET="${cflags_for_target}" \
AR_FOR_TARGET="`which ${CT_TARGET}-gcc-ar`" \
RANLIB_FOR_TARGET="`which ${CT_TARGET}-gcc-ranlib`" \
${CONFIG_SHELL} \
"${CT_SRC_DIR}/newlib-nano/configure" \
--host=${CT_BUILD} \
--target=${CT_TARGET} \
--prefix=${CT_PREFIX_DIR} \
--exec-prefix=${CT_PREFIX_DIR}/newlib-nano \
--libdir=${CT_PREFIX_DIR}/newlib-nano/${CT_TARGET}/lib \
"${newlib_opts[@]}" \
"${CT_LIBC_NEWLIB_NANO_EXTRA_CONFIG_ARRAY[@]}"
CT_DoLog EXTRA "Building Newlib Nano C library"
CT_DoExecLog ALL make ${CT_JOBSFLAGS}
CT_DoLog EXTRA "Installing Newlib Nano C library"
CT_DoExecLog ALL make install
CT_Popd
CT_EndStep
}
fi