From 7e457684ea05795be91265cc5bc0320995288871 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 7 Jan 2021 17:21:39 -0800 Subject: picolibc: Convert to companion library This allows configurations to include picolibc without excluding another C library. Signed-off-by: Keith Packard --- config/comp_libs/picolibc.in | 121 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 config/comp_libs/picolibc.in (limited to 'config/comp_libs') diff --git a/config/comp_libs/picolibc.in b/config/comp_libs/picolibc.in new file mode 100644 index 00000000..a3f07d63 --- /dev/null +++ b/config/comp_libs/picolibc.in @@ -0,0 +1,121 @@ +# picolibc options + +## depends on BARE_METAL && CONFIGURE_has_meson && CONFIGURE_has_ninja + +## help This option adds Picolibc to an existing configuration which may have +## help a C library, allowing you to install both and select between them +## help when compiling applications using the toolchain +## help +## help Picolibc is a C library intended for use on embedded systems. It is a +## help conglomeration of several library parts, all under BSD-compatible software +## help licenses that make them easily usable on embedded products. + +config PICOLIBC_CXA_ATEXIT + def_bool y + select LIBC_PROVIDES_CXA_ATEXIT + +config LIBC_PICOLIBC_TARGET_CFLAGS + string + prompt "Target CFLAGS for picolibc" + 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_PICOLIBC_TARGET_CFLAGS are used + to compile the libraries. + + Leave blank if you don't know better. + +config LIBC_PICOLIBC_IO_C99FMT + bool + prompt "Enable IOs on C99 formats" + default y + help + Enable support for IOs on C99 formats. + +config LIBC_PICOLIBC_REGISTER_FINI + bool + prompt "Enable finalization function registration using atexit" + help + Enable finalization function registration using atexit. + +config LIBC_PICOLIBC_ATEXIT_DYNAMIC_ALLOC + bool + prompt "Enable dynamic allocation of atexit entries" + help + Enable dynamic allocation of atexit entries. + +config LIBC_PICOLIBC_GLOBAL_ATEXIT + bool + prompt "Enable atexit data structure as global variable" + help + Enable atexit data structure as global variable, instead + of being thread-local. + +config LIBC_PICOLIBC_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_PICOLIBC_MULTITHREAD + bool + prompt "Enable support for multiple threads" + default y + help + Enable support for multiple threads. + +config LIBC_PICOLIBC_RETARGETABLE_LOCKING + bool + prompt "Enable retargetable locking" + help + Enable retargetable locking to allow the operating system to override + the dummy lock functions defined within picolibc. + +config LIBC_PICOLIBC_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_PICOLIBC_ENABLE_TARGET_OPTSPACE + bool + prompt "Optimize picolibc for size" + default y + help + Pass --enable-target-optspace to picolibc configure. + + This will compile picolibc with -Os. + +config LIBC_PICOLIBC_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_PICOLIBC_NANO_MALLOC + bool + prompt "Enable Nano Malloc" + default y + help + PICOLIBC 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_PICOLIBC_EXTRA_CONFIG_ARRAY + string + prompt "Extra config for picolibc" + default "" + help + Extra flags to pass to meson when configuring picolibc. -- cgit v1.2.3 From 74949b1d3578873af031f9ad67a8fdb571c5f1bc Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 11 Jan 2021 22:42:26 -0800 Subject: picolibc: Clean up configuration a bit Use LIBC_PICOLIBC_CXA_ATEXIT to keep this name in the same 'namespace' as the other picolibc config names. Enable retargetable locking by default. This allows the few locks in picolibc to be implemented by the execution environment, rather than disabling the locking code. Signed-off-by: Keith Packard --- config/comp_libs/picolibc.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'config/comp_libs') diff --git a/config/comp_libs/picolibc.in b/config/comp_libs/picolibc.in index a3f07d63..62ab22b4 100644 --- a/config/comp_libs/picolibc.in +++ b/config/comp_libs/picolibc.in @@ -10,7 +10,7 @@ ## help conglomeration of several library parts, all under BSD-compatible software ## help licenses that make them easily usable on embedded products. -config PICOLIBC_CXA_ATEXIT +config LIBC_PICOLIBC_CXA_ATEXIT def_bool y select LIBC_PROVIDES_CXA_ATEXIT @@ -72,6 +72,7 @@ config LIBC_PICOLIBC_MULTITHREAD config LIBC_PICOLIBC_RETARGETABLE_LOCKING bool prompt "Enable retargetable locking" + default y help Enable retargetable locking to allow the operating system to override the dummy lock functions defined within picolibc. -- cgit v1.2.3 From 27b18d2fc70a7788c97f57a02a768214a2548ee0 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 11 Jan 2021 22:28:38 -0800 Subject: picolibc: Build libstdc++ against picolibc if requested This uses the gcc support for building libstdc++ using alternate lib header files. Signed-off-by: Keith Packard --- config/comp_libs/picolibc.in | 10 ++++++ samples/arm-picolibc-eabi/crosstool.config | 1 + scripts/build/companion_libs/340-picolibc.sh | 46 ++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) (limited to 'config/comp_libs') diff --git a/config/comp_libs/picolibc.in b/config/comp_libs/picolibc.in index 62ab22b4..cb7a1e4f 100644 --- a/config/comp_libs/picolibc.in +++ b/config/comp_libs/picolibc.in @@ -10,6 +10,16 @@ ## help conglomeration of several library parts, all under BSD-compatible software ## help licenses that make them easily usable on embedded products. +config LIBC_PICOLIBC_GCC_LIBSTDCXX + bool + prompt "Compile libstdc++ picolibc variant" + default y + depends on CC_LANG_CXX + help + This option compiles an additional target libstdc++ for use with + picolibc. This version is linked when "--specs=picolibcpp.specs" + is specified. + config LIBC_PICOLIBC_CXA_ATEXIT def_bool y select LIBC_PROVIDES_CXA_ATEXIT diff --git a/samples/arm-picolibc-eabi/crosstool.config b/samples/arm-picolibc-eabi/crosstool.config index 48a45437..1da16169 100644 --- a/samples/arm-picolibc-eabi/crosstool.config +++ b/samples/arm-picolibc-eabi/crosstool.config @@ -8,3 +8,4 @@ CT_CC_GCC_CONFIG_TLS=y CT_TARGET_CFLAGS="-ftls-model=local-exec" CT_CC_GCC_MULTILIB_LIST="rmprofile" CT_COMP_LIBS_PICOLIBC=y +CT_CC_LANG_CXX=y diff --git a/scripts/build/companion_libs/340-picolibc.sh b/scripts/build/companion_libs/340-picolibc.sh index c0128c1b..525497ae 100644 --- a/scripts/build/companion_libs/340-picolibc.sh +++ b/scripts/build/companion_libs/340-picolibc.sh @@ -22,6 +22,50 @@ do_picolibc_extract() { CT_ExtractPatch PICOLIBC } +#------------------------------------------------------------------------------ +# Build an additional target libstdc++ with "-Os" (optimise for speed) option +# flag for libstdc++ "picolibc" variant. +do_cc_libstdcxx_picolibc() +{ + local -a final_opts + local final_backend + + if [ "${CT_LIBC_PICOLIBC_GCC_LIBSTDCXX}" = "y" ]; then + final_opts+=( "host=${CT_HOST}" ) + final_opts+=( "libstdcxx_name=picolibc" ) + final_opts+=( "prefix=${CT_PREFIX_DIR}" ) + final_opts+=( "complibs=${CT_HOST_COMPLIBS_DIR}" ) + final_opts+=( "cflags=${CT_CFLAGS_FOR_HOST}" ) + final_opts+=( "ldflags=${CT_LDFLAGS_FOR_HOST}" ) + final_opts+=( "lang_list=c,c++" ) + final_opts+=( "build_step=libstdcxx" ) + final_opts+=( "extra_config+=('--enable-stdio=stdio_pure')" ) + if [ "${CT_LIBC_PICOLIBC_ENABLE_TARGET_OPTSPACE}" = "y" ]; then + final_opts+=( "enable_optspace=yes" ) + fi + + if [ "${CT_BARE_METAL}" = "y" ]; then + final_opts+=( "mode=baremetal" ) + final_opts+=( "build_libgcc=yes" ) + final_opts+=( "build_libstdcxx=yes" ) + final_opts+=( "build_libgfortran=yes" ) + if [ "${CT_STATIC_TOOLCHAIN}" = "y" ]; then + final_opts+=( "build_staticlinked=yes" ) + fi + final_backend=do_gcc_core_backend + else + final_backend=do_gcc_backend + fi + + CT_DoStep INFO "Installing libstdc++ picolibc" + CT_mkdir_pushd "${CT_BUILD_DIR}/build-cc-libstdcxx-picolibc" + "${final_backend}" "${final_opts[@]}" + CT_Popd + + CT_EndStep + fi +} + do_picolibc_for_target() { local -a picolibc_opts local cflags_for_target @@ -119,6 +163,8 @@ EOF CT_Popd CT_EndStep + + do_cc_libstdcxx_picolibc } fi -- cgit v1.2.3