This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Builtin: stack pointer

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:

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):

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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]