Skip to content

CONFIG_THREAD_LOCAL_STORAGE (selected by PICOLIBC) sends sparse into an infinite loop #63417

@marc-hb

Description

@marc-hb

Describe the bug

This is admittedly a bug in the sparse tool itself but it's triggered by very specific Zephyr conditions.

EDIT: the infinite loop has been confirmed and fixed in sparse. Other Zephyr issues mentioned below remain, tracked in other bugs if needed.

To Reproduce
Steps to reproduce the behavior:

west build  samples/hello_world -p -b rpi_4b -- -DZEPHYR_SCA_VARIANT=sparse
 => hangs forever, infinite loop in sparse tls.c

Crl-C
ninja -C build -j1
 Building C object zephyr/arch/arch/arm64/core/CMakeFiles/arch__arm64__core.dir/tls.c.obj
 => hangs forever

west build  samples/hello_world -p -b hifive1 -- -DZEPHYR_SCA_VARIANT=sparse
 => same infinite loop

Same infinite loop with intel_ish_5_4_1, arduino_due and others. No infinite loop with intel_adsp_cavs25 (which does not have THREAD_LOCAL_STORAGE)

Workaround 1
EDIT: a bit more complicated now, see below.

--- a/lib/libc/Kconfig
+++ b/lib/libc/Kconfig
@@ -72,7 +72,7 @@ config MINIMAL_LIBC
 config PICOLIBC
        bool "Picolibc library"
        select COMMON_LIBC_ABORT
-       select THREAD_LOCAL_STORAGE if ARCH_HAS_THREAD_LOCAL_STORAGE && TOOLCHAIN_SUPPORTS_THREAD_LOCAL_STORAGE
+#      select THREAD_LOCAL_STORAGE if ARCH_HAS_THREAD_LOCAL_STORAGE && TOOLCHAIN_SUPPORTS_THREAD_LOCAL_STORAGE
        select LIBC_ERRNO if THREAD_LOCAL_STORAGE
        imply COMMON_LIBC_MALLOC
        depends on !NATIVE_APPLICATION

Disabling tls.c still avoids the issue but it requires using the separate picolibc module as added to zephyr/west.yml by d0c75f3. Then the following command avoids the infinite loop:

west build  samples/hello_world  -b rpi_4b -- \
  -DCONFIG_PICOLIBC_USE_MODULE=y  -DZEPHYR_SCA_VARIANT=sparse -DCONFIG_THREAD_LOCAL_STORAGE=n

Workaround 2

west build  samples/hello_world -p -b rpi_4b -- -DZEPHYR_SCA_VARIANT=sparse -DCONFIG_MINIMAL_LIBC=y

CONFIG_MINIMAL_LIBC=y seems to also turn off THREAD_LOCAL_STORAGE

Expected behavior

No infinite loop.

Impact

Impossible to use sparse static analyzer on these platforms.

Harder to debug other sparse issues like #63003

Logs and console output
See above

Environment (please complete the following information):

Linux
Zephyr SDK 0.16.1
Zephyr commit ea4a463
marc-hb/sparse@3848a76ba49f

Additional context

Metadata

Metadata

Assignees

Labels

area: Build SystembugThe issue is a bug, or the PR is fixing a bugpriority: lowLow impact/importance bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions