Skip to content

Conversation

@cfriedt
Copy link
Member

@cfriedt cfriedt commented Nov 12, 2025

Due to slight differences in the way that LLVM and GNU linkers work, the call to z_stack_space_get() is not dead-stripped when linking with LLVM lld but it is dead-stripped when linking with GNU ld.

The z_stack_space_get() function is only available when CONFIG_INIT_STACKS and CONFIG_THREAD_STACK_INFO are defined. So add a workaround to arch_thread_priv_stack_space_get() for riscv, x86, and xtensa, to return an error earlier if those Kconfig options are not enabled. This triggers LLVM to strip the call to z_stack_space_get() as dead code.

The issue is reproducible (although requires building LLVM and setting up some environment variables) and goes away with the proposed workaround.

Fixes #98491

Due to slight differences in the way that LLVM and GNU linkers work, the call to `z_stack_space_get()` is not dead-stripped when linking with `lld` but it is dead-stripped when linking with GNU `ld`. The `z_stack_space_get()` function is only available when `CONFIG_INIT_STACKS` and `CONFIG_THREAD_STACK_INFO` are defined. The issue is reproducible (although requires building LLVM and setting up some environment variables) and goes away with the proposed workaround. Signed-off-by: Robin Kastberg <robin.kastberg@iar.com> Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
@cfriedt cfriedt force-pushed the riscv-userspace-undefined-symbol-z-stack-space-get branch from 9339aed to 4d78eed Compare November 12, 2025 19:15
@RobinKastberg RobinKastberg self-requested a review November 14, 2025 12:14
@cfriedt cfriedt marked this pull request as ready for review November 14, 2025 23:44
@zephyrbot zephyrbot added area: Xtensa Xtensa Architecture area: RISCV RISCV Architecture (32-bit & 64-bit) area: X86 x86 Architecture (32-bit) labels Nov 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: RISCV RISCV Architecture (32-bit & 64-bit) area: X86 x86 Architecture (32-bit) area: Xtensa Xtensa Architecture

6 participants