[cfe-dev] A new builtin: __builtin_stack_pointer()

Behan Webster behanw at converseincode.com
Mon Nov 11 13:50:25 PST 2013


On 11/10/13 13:46, PaX Team wrote:
> now with that background let me try to answer your questions:
>
> - __builtin_frame_address is indeed good enough for this purpose (and i can't
>   find more use of the stack register in C, but maybe Behan knows of more where
>   an exact value is important)
It is "good enough" in the case where you're merely trying to find the
beginning or end of the stack, however it's not acceptable to kernel
upstream (precisely for situations where there is no frame pointer
register). I've tried that already. They want to use the stack pointer.

In the other use case, where the stack pointer is saved for later it is
not good enough however.

> - the resulting value is expected to be a valid address (at the time it's taken)
>   as the kernel *will* dereference it later but there're no other requirements.
Exactly.

>> Do you *also* need a guarantee that the stack pointer will not change
>> between the call to __builtin_stack_address and the end of the function
>> (except in callees)? 
Actually I'm proposing calling it __builtin_stack_pointer()  The reason
being that we're accessing the "esp" register on x86 and the "sp"
register on ARM. The register is generally known as the "stack pointer"
which seems the best thing to call it. (Principle of least surprise).

> no, it just has to be an address that belongs to the current stack frame at the
> time. basically it'll define the start address from which the kernel will look
> for certain things (such as code addresses in the hope that saved return addresses
> will be found this way) on the stack.
I haven't actually looked further into the stack walking code. All I
know is that the return address, frame address, and stack pointer are
all saved for later use in multiple places. I'm trying not to break how
it currently works with gcc, as well as have it work with clang using
the same code.

>> Can we reorder a call to alloca() past __builtin_stack_address?
>> Can we reorder the initialization of a VLA past a call to
>> __builtin_stack_address? Can the backend choose to perform a stack
>> adjustment afterwards?
> yes for all.
Agreed.

Incidentally, the LLVMLinux project is working on a ::stackpointer()
version of the __builtin_stack_pointer() patch (as suggested by Chris)
which we're just testing.

Thanks,

Behan

-- 
Behan Webster
behanw at converseincode.com




More information about the cfe-dev mailing list