Hi there,

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:

http://lists.cs.uiuc.edu/pipermail/llvmdev/2013-October/066325.html

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
construct above.

Here's what we're planning on implementing in LLVM (with docs
explaining the semantics):

http://llvm-reviews.chandlerc.com/D3184

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.

cheers,
--renato

Reply via email to