Skip to content

Commit d7d3ae5

Browse files
stephanosiodanieldegrasse
authored andcommitted
arch: arm: cortex_m: Force literal pool placement in inline asm block
When LTO is enabled, linker may relocate literal pools out of Thumb LDR instruction's reach causing "offset out of range" errors while linking. This commit adds `.ltorg` directive in the inline asm blocks where absolute addresses are loaded using the `ldr` instructions, in order to ensure that the literal pool containing the absolute addresses are placed near the `ldr` instructions. Note that the `.ltorg` directive is recognised by all toolchains supported by Zephyr and no toolchain abstraction is provided for now. Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
1 parent d7ff0e4 commit d7d3ae5

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

arch/arm/core/cortex_m/thread.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,8 @@ void arch_switch_to_main_thread(struct k_thread *main_thread, char *stack_ptr,
557557
"ldr r4, =z_thread_entry\n"
558558
/* We don’t intend to return, so there is no need to link. */
559559
"bx r4\n"
560+
/* Force a literal pool placement for the addresses referenced above */
561+
".ltorg\n"
560562
:
561563
: "r"(_main), "r"(stack_ptr)
562564
: "r0", "r1", "r2", "r3", "r4", "ip", "lr", "memory");
@@ -623,6 +625,8 @@ FUNC_NORETURN void z_arm_switch_to_main_no_multithreading(k_thread_entry_t main_
623625
"ldr r0, =arch_irq_lock_outlined\n"
624626
"blx r0\n"
625627
"loop: b loop\n\t" /* while (true); */
628+
/* Force a literal pool placement for the addresses referenced above */
629+
".ltorg\n"
626630
:
627631
: [_p1] "r"(p1), [_p2] "r"(p2), [_p3] "r"(p3), [_psp] "r"(psp),
628632
[_main_entry] "r"(main_entry)

0 commit comments

Comments
 (0)