Skip to content

Fix current_stack_pointer for LLVM#134

Open
xtexx wants to merge 1 commit intoloongson:loongarch-portfrom
xtexx:la64-read-sp-fix
Open

Fix current_stack_pointer for LLVM#134
xtexx wants to merge 1 commit intoloongson:loongarch-portfrom
xtexx:la64-read-sp-fix

Conversation

@xtexx
Copy link
Copy Markdown

@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 liushuyu@aosc.io for pointing out the reason (GitHub @liushuyu).

@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
@xtexx
Copy link
Copy Markdown
Author

xtexx commented Jan 31, 2026

#136 (comment)

@xtexx xtexx closed this Jan 31, 2026
@xtexx xtexx reopened this Feb 7, 2026
Comment thread src/hotspot/os_cpu/linux_loongarch/os_linux_loongarch.cpp Outdated
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 <liushuyu@aosc.io> for pointing out the reason
(GitHub @liushuyu).

Signed-off-by: Bingwu Zhang <xtex@aosc.io>
@xtexx xtexx marked this pull request as ready for review February 7, 2026 13:51
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.

2 participants