Skip to content

Commit 9339aed

Browse files
committed
arch: riscv + xtensa + x86: workaround needed for LLVM linker
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: Chris Friedt <cfriedt@tenstorrent.com>
1 parent 9679395 commit 9339aed

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

arch/riscv/core/thread.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,15 @@ FUNC_NORETURN void arch_user_mode_enter(k_thread_entry_t user_entry,
207207
int arch_thread_priv_stack_space_get(const struct k_thread *thread, size_t *stack_size,
208208
size_t *unused_ptr)
209209
{
210+
if (!IS_ENABLED(CONFIG_INIT_STACKS) || !IS_ENABLED(CONFIG_THREAD_STACK_INFO)) {
211+
/*
212+
* This is needed to ensure that the call to z_stack_space_get() below is properly
213+
* dead-stripped when linking using LLVM / lld. For more info, please see issue
214+
* #98491.
215+
*/
216+
return -EINVAL;
217+
}
218+
210219
if ((thread->base.user_options & K_USER) != K_USER) {
211220
return -EINVAL;
212221
}

arch/x86/core/userspace.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,15 @@ FUNC_NORETURN void arch_user_mode_enter(k_thread_entry_t user_entry,
189189
int arch_thread_priv_stack_space_get(const struct k_thread *thread, size_t *stack_size,
190190
size_t *unused_ptr)
191191
{
192+
if (!IS_ENABLED(CONFIG_INIT_STACKS) || !IS_ENABLED(CONFIG_THREAD_STACK_INFO)) {
193+
/*
194+
* This is needed to ensure that the call to z_stack_space_get() below is properly
195+
* dead-stripped when linking using LLVM / lld. For more info, please see issue
196+
* #98491.
197+
*/
198+
return -EINVAL;
199+
}
200+
192201
struct z_x86_thread_stack_header *hdr_stack_obj;
193202

194203
if ((thread->base.user_options & K_USER) != K_USER) {

arch/xtensa/core/thread.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,15 @@ FUNC_NORETURN void arch_user_mode_enter(k_thread_entry_t user_entry,
240240
int arch_thread_priv_stack_space_get(const struct k_thread *thread, size_t *stack_size,
241241
size_t *unused_ptr)
242242
{
243+
if (!IS_ENABLED(CONFIG_INIT_STACKS) || !IS_ENABLED(CONFIG_THREAD_STACK_INFO)) {
244+
/*
245+
* This is needed to ensure that the call to z_stack_space_get() below is properly
246+
* dead-stripped when linking using LLVM / lld. For more info, please see issue
247+
* #98491.
248+
*/
249+
return -EINVAL;
250+
}
251+
243252
struct xtensa_thread_stack_header *hdr_stack_obj;
244253

245254
if ((thread->base.user_options & K_USER) != K_USER) {

0 commit comments

Comments
 (0)