Skip to content

Conversation

@xtexx
Copy link

@xtexx xtexx commented Mar 1, 2025

Due to limitations of LLVM IR, clang cannot pin sp to $r3 unless sp is used by another line of inline assembly
(asm volatile ("" : "=r" (sp))).
When compiling with Clang, os::current_stack_pointer will return an unexpected value (from a randomly assigned register).

This patch changes os::current_stack_pointer to use inline assembly to obtain the stack pointer, which avoids the limitation of LLVM IR.

Thanks to Zixing Liu [email protected] for pointing out the reason (GitHub @liushuyu).

Due to limitations of LLVM IR, clang cannot pin `sp` to `$r3` unless
`sp` is used by another line of inline assembly
(`asm volatile ("" : "=r" (sp))`).
When compiling with Clang, `os::current_stack_pointer` will return an
unexpected value (from a randomly assigned register).

This patch changes `os::current_stack_pointer` to use inline assembly to
obtain the stack pointer, which avoids the limitation of LLVM IR.

Thanks to Zixing Liu <[email protected]> for pointing out the reason
(GitHub @liushuyu).

Signed-off-by: Bingwu Zhang <[email protected]>
@xtexx xtexx marked this pull request as draft March 1, 2025 04:08
@xtexx xtexx changed the title Fix current_stack_pointer Fix current_stack_pointer for LLVm Mar 1, 2025
@xtexx xtexx changed the title Fix current_stack_pointer for LLVm Fix current_stack_pointer for LLVM Mar 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant