Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libc/picolibc: Don't enable malloc by default #63259

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
6c50f28
tests/mem_alloc: Make tests labeled 'minimal' use the minimal C library
keith-packard Sep 29, 2023
e8f0d51
tests/mem_alloc: Skip minimal C library tests on full libc targets
keith-packard Nov 17, 2023
2328c5e
libc: Add REQUIRES_MALLOC to indirectly select malloc support
keith-packard Sep 28, 2023
d086012
libc: Add REQUIRED_MALLOC_ARENA_SIZE to indirectly request heap size
keith-packard Sep 29, 2023
9a34e08
lib/cpp: Imply REQUIRES_MALLOC when using C++
keith-packard Sep 29, 2023
567d231
net/sockets: Add REQUIRES_MALLOC when needed in sockets
keith-packard Sep 29, 2023
71c2230
fs/littlefs: Add REQUIRES_MALLOC when using littlefs
keith-packard Sep 29, 2023
e1efe60
modules: Add REQUIRES_MALLOC to various modules
keith-packard Sep 29, 2023
17ce908
modules/mcux: Add REQUIRES_MALLOC
keith-packard Nov 17, 2023
f28c25a
soc/renasas_smartbond: Add REQUIRES_MALLOC to the da1469x configuration
keith-packard Sep 29, 2023
c984dbf
samples,tests: Add REQUIRES_MALLOC=y to hash_map tests
keith-packard Sep 29, 2023
25d652f
samples/ivshmem: Add CONFIG_REQUIRES_MALLOC=y
keith-packard Sep 29, 2023
fd8467f
samples/maxim_ds3231: Add REQUIRES_MALLOC (for strftime)
keith-packard Nov 17, 2023
f9fb0aa
tests/cmsis: Add REQUIRES_MALLOC
keith-packard Nov 18, 2023
c7b0366
tests/cmsis_nn: Add REQUIRES_MALLOC
keith-packard Nov 17, 2023
769d81c
tests/basicmath: Add REQUIRES_MALLOC
keith-packard Nov 17, 2023
bd3da72
libc/minimal: Select common malloc when applications require it
keith-packard Sep 28, 2023
6a901af
libc/picolibc: Only enable malloc when required
keith-packard Sep 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/cpp/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ menu "C++ Language Support"

config CPP
bool "C++ support for the application"
imply REQUIRES_MALLOC
help
This option enables the use of applications built with C++.

Expand Down
20 changes: 19 additions & 1 deletion lib/libc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ config REQUIRES_FLOAT_PRINTF
Select a printf implementation that provides a complete
implementation including floating point support.

config REQUIRES_MALLOC
bool "Requires malloc APIs"
help
Indicates that the malloc family of functions are required by the
application.

config REQUIRED_MALLOC_ARENA_SIZE
int "Required malloc arena size"
default -1
help
Indicates the minimum desired size of the malloc arena. This is
only a hint; some malloc implementations may not be able to
guarantee that this amount will be available at runtime.

If set to -1, then the underlying C library default value will
be used.

config FULL_LIBC_SUPPORTED
bool
help
Expand Down Expand Up @@ -75,6 +92,7 @@ config MINIMAL_LIBC
imply COMPILER_FREESTANDING
select COMMON_LIBC_ABORT
select COMMON_LIBC_STRNLEN
select COMMON_LIBC_MALLOC if REQUIRES_MALLOC
help
Build with minimal C library.

Expand All @@ -84,7 +102,7 @@ config PICOLIBC
imply THREAD_LOCAL_STORAGE if ARCH_HAS_THREAD_LOCAL_STORAGE && TOOLCHAIN_SUPPORTS_THREAD_LOCAL_STORAGE
select LIBC_ERRNO if THREAD_LOCAL_STORAGE
select NEED_LIBC_MEM_PARTITION
imply COMMON_LIBC_MALLOC
select COMMON_LIBC_MALLOC if REQUIRES_MALLOC
depends on !NATIVE_APPLICATION
depends on PICOLIBC_SUPPORTED
help
Expand Down
1 change: 1 addition & 0 deletions lib/libc/common/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ config COMMON_LIBC_MALLOC
config COMMON_LIBC_MALLOC_ARENA_SIZE
int "Size of the common C library malloc arena"
depends on COMMON_LIBC_MALLOC
default REQUIRED_MALLOC_ARENA_SIZE if REQUIRED_MALLOC_ARENA_SIZE >= 0
default 0 if MINIMAL_LIBC
default 16384 if MMU
default 2048 if USERSPACE && MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT
Expand Down
1 change: 1 addition & 0 deletions lib/libc/newlib/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ config NEWLIB_LIBC_MAX_MAPPED_REGION_SIZE

config NEWLIB_LIBC_MIN_REQUIRED_HEAP_SIZE
int "Newlib minimum required heap size"
default REQUIRED_MALLOC_ARENA_SIZE if REQUIRED_MALLOC_ARENA_SIZE >= 0
default 2048 if NEWLIB_LIBC_NANO
default 8192 if !NEWLIB_LIBC_NANO
help
Expand Down
1 change: 1 addition & 0 deletions modules/Kconfig.mcux
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

config HAS_MCUX
bool
select REQUIRES_MALLOC
depends on SOC_FAMILY_KINETIS || SOC_FAMILY_IMX || SOC_FAMILY_LPC || \
SOC_FAMILY_NXP_ADSP || SOC_FAMILY_NXP_S32

Expand Down
1 change: 1 addition & 0 deletions modules/lz4/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ config ZEPHYR_LZ4_MODULE

config LZ4
bool "Lz4 data compression and decompression"
select REQUIRES_MALLOC
help
This option enables lz4 compression & decompression library
support.
1 change: 1 addition & 0 deletions modules/mbedtls/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ choice MBEDTLS_IMPLEMENTATION

config MBEDTLS_BUILTIN
bool "Use Zephyr in-tree mbedTLS version"
select REQUIRES_MALLOC
help
Link with mbedTLS sources included with Zephyr distribution.
Included mbedTLS version is well integrated with and supported
Expand Down
1 change: 1 addition & 0 deletions modules/tflite-micro/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ config ZEPHYR_TFLITE-MICRO_MODULE
config TENSORFLOW_LITE_MICRO
bool "TensorFlow Lite Micro Support"
select REQUIRES_FULL_LIBCPP
select REQUIRES_MALLOC
help
This option enables the TensorFlow Lite Micro library.

Expand Down
1 change: 1 addition & 0 deletions modules/thrift/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ config ZEPHYR_THRIFT_MODULE
menuconfig THRIFT
bool "Support for Thrift [EXPERIMENTAL]"
select EXPERIMENTAL
select REQUIRES_MALLOC
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One day, It would be cool to not require a global allocator for Thrift

depends on CPP
depends on STD_CPP17
depends on CPP_EXCEPTIONS
Expand Down
2 changes: 2 additions & 0 deletions samples/basic/hash_map/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ CONFIG_SYS_HASH_FUNC32=y
CONFIG_SYS_HASH_MAP=y

CONFIG_TEST_LIB_HASH_MAP_MAX_ENTRIES=40

CONFIG_REQUIRES_MALLOC=y
3 changes: 3 additions & 0 deletions samples/drivers/counter/maxim_ds3231/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ CONFIG_COUNTER_INIT_PRIORITY=65
# Minimal libc doesn't have strftime()
CONFIG_REQUIRES_FULL_LIBC=y

# picolibc strftime require malloc (currently)
CONFIG_REQUIRES_MALLOC=y

# Optional step that syncs RTC and local clock. Don't enable this if
# your RTC has already been synchronized and you want to keep its
# setting.
Expand Down
2 changes: 2 additions & 0 deletions samples/drivers/virtualization/ivshmem/doorbell/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ CONFIG_POLL=y
CONFIG_VIRTUALIZATION=y
CONFIG_IVSHMEM=y
CONFIG_IVSHMEM_DOORBELL=y

CONFIG_REQUIRES_MALLOC=y
1 change: 1 addition & 0 deletions soc/arm/renesas_smartbond/da1469x/Kconfig.series
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ config SOC_SERIES_DA1469X
select HAS_SEGGER_RTT if ZEPHYR_SEGGER_MODULE
select CLOCK_CONTROL
select CLOCK_CONTROL_SMARTBOND
select REQUIRES_MALLOC
help
Enable support for Renesas SmartBond(tm) DA1469x MCU series
1 change: 1 addition & 0 deletions subsys/fs/Kconfig.littlefs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ config FILE_SYSTEM_LITTLEFS
bool "LittleFS support"
depends on FILE_SYSTEM
depends on ZEPHYR_LITTLEFS_MODULE
select REQUIRES_MALLOC
help
Enables LittleFS file system support.

Expand Down
1 change: 1 addition & 0 deletions subsys/net/lib/sockets/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
menuconfig NET_SOCKETS
bool "BSD Sockets compatible API"
select FDTABLE
select REQUIRES_MALLOC if DNS_RESOLVER || NET_IP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically, getaddrinfo and freeaddrinfo could maybe use a slab if malloc is unavailable. What do you think @rlubos ? Not a change required here, but maybe a good future enhancement. Even malloc-less systems should be able to resolve.

help
Provide BSD Sockets like API on top of native Zephyr networking API.

Expand Down
1 change: 1 addition & 0 deletions tests/lib/cmsis_dsp/statistics/prj.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CONFIG_ZTEST=y
CONFIG_REQUIRES_FULL_LIBC=y
CONFIG_CMSIS_DSP=y
CONFIG_REQUIRES_MALLOC=y
1 change: 1 addition & 0 deletions tests/lib/cmsis_dsp/transform/prj.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CONFIG_ZTEST=y
CONFIG_REQUIRES_FULL_LIBC=y
CONFIG_CMSIS_DSP=y
CONFIG_REQUIRES_MALLOC=y

# Test Options
CONFIG_CMSIS_DSP_TEST_TRANSFORM_CQ15=y
Expand Down
1 change: 1 addition & 0 deletions tests/lib/cmsis_dsp/transform/prj_base.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CONFIG_ZTEST=y
CONFIG_REQUIRES_FULL_LIBC=y
CONFIG_CMSIS_DSP=y
CONFIG_REQUIRES_MALLOC=y
1 change: 1 addition & 0 deletions tests/lib/cmsis_nn/prj.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
CONFIG_ZTEST=y
CONFIG_REQUIRES_FULL_LIBC=y
CONFIG_REQUIRES_MALLOC=y
CONFIG_CMSIS_DSP=y
CONFIG_CMSIS_NN=y
CONFIG_CMSIS_NN_ACTIVATION=y
Expand Down
3 changes: 3 additions & 0 deletions tests/lib/hash_map/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

CONFIG_ZTEST=y

CONFIG_REQUIRES_MALLOC=y
CONFIG_REQUIRED_MALLOC_ARENA_SIZE=8192

CONFIG_SYS_HASH_FUNC32=y
CONFIG_SYS_HASH_MAP=y

Expand Down
1 change: 1 addition & 0 deletions tests/lib/mem_alloc/prj.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CONFIG_ZTEST=y
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=2048
CONFIG_TEST_USERSPACE=y
CONFIG_MINIMAL_LIBC=y
1 change: 1 addition & 0 deletions tests/lib/mem_alloc/prj_negative_testing.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CONFIG_ZTEST=y
CONFIG_COMMON_LIBC_MALLOC_ARENA_SIZE=0
CONFIG_TEST_USERSPACE=y
CONFIG_MINIMAL_LIBC=y
1 change: 1 addition & 0 deletions tests/lib/mem_alloc/prj_picolibc.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
CONFIG_ZTEST=y
CONFIG_PICOLIBC=y
CONFIG_TEST_USERSPACE=y
CONFIG_REQUIRES_MALLOC=y
2 changes: 2 additions & 0 deletions tests/lib/mem_alloc/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ tests:
libraries.libc.minimal.mem_alloc:
extra_args: CONF_FILE=prj.conf
platform_exclude: twr_ke18f
filter: not CONFIG_REQUIRES_FULL_LIBC
tags:
- minimal_libc
libraries.libc.minimal.mem_alloc_negative_testing:
extra_args: CONF_FILE=prj_negative_testing.conf
platform_exclude: twr_ke18f
filter: not CONFIG_REQUIRES_FULL_LIBC
tags:
- minimal_libc
libraries.libc.newlib.mem_alloc:
Expand Down
1 change: 1 addition & 0 deletions tests/subsys/dsp/basicmath/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ CONFIG_REQUIRES_FULL_LIBC=y
CONFIG_DSP=y
CONFIG_CMSIS_DSP=y
CONFIG_DSP_BACKEND_CMSIS=y
CONFIG_REQUIRES_MALLOC=y
Loading