[llvmlinux] Builtin: stack pointer
renato.golin at linaro.org
Thu Mar 27 09:38:11 UTC 2014
There is a common pattern on bare-metal code to refer to the value of
registers directly in a variable:
register unsigned long current_stack_pointer asm("sp");
But not only that depends on the register names (so you need to split
by arch with ifdefs), but it also uses a non-guaranteed fact about
register variables, and uses inline asm that is not supported by
Clang/LLVM (for several reasons).
The LLVMLinux team have submitted a proposal that works around this on
a target-independent way:
Basically, introducing the builtin: __builtin_stack_pointer() which
will return the stack pointer register's value. There's no guarantee
that the register will contain the information you want (for example,
if the surrounding code uses it) and is only meant to replace the
Here's what we're planning on implementing in LLVM (with docs
explaining the semantics):
Is this something that can be done in another target-independent way?
If not, is this something that GCC would also be willing to implement,
so that we can replace the register/asm patterns by it? It would make
kernel code simpler to have a single solution.
More information about the LLVMLinux