This is the mail archive of the
mailing list for the GCC project.
Builtin: stack pointer
- From: Renato Golin <renato dot golin at linaro dot org>
- To: gcc <gcc at gcc dot gnu dot org>
- Cc: "Compiling the Linux Kernel with Clang/LLVM" <llvmlinux at lists dot linuxfoundation dot org>
- Date: Thu, 27 Mar 2014 09:38:11 +0000
- Subject: Builtin: stack pointer
- Authentication-results: sourceware.org; auth=none
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.