Re: [PATCH v6 0/4] Compile-time stack validation

From: Josh Poimboeuf
Date: Tue Jul 07 2015 - 18:35:32 EST


On Tue, Jul 07, 2015 at 09:54:09AM -0500, Josh Poimboeuf wrote:
> I did some more looking and it turns out that inline assembly doesn't
> play nicely with frame pointers at all. If the inline asm is at the
> beginning of the function, gcc sometimes emits the inline asm code
> before setting up the frame pointer. That can break stack traces
> when the inline asm has a call instruction.
>
> That turns out to be a very common problem. Stackvalidate found 37 C
> object files which break frame pointer rules, thanks to inline asm.
>
> I don't know of a solution to this problem yet. Basically I think we
> need a way to ensure that gcc emits the frame pointer setup before
> inserting any inline asm (particularly when the inline asm has a call
> instruction).

A solution to this problem was posted by Segher Boessenkool in a related
thread on the gcc mailing list:

https://gcc.gnu.org/ml/gcc/2015-07/msg00080.html

The suggestion is to use something like:

register void *sp asm("%sp");
asm volatile("call func" : "+r"(sp));

I can confirm that it seems to fix the issue. (I had tried something
like this before, but I guess I wasn't able to get the incantation just
right.)

Thanks to Jiri for the pointer to the thread, and Martin for raising the
issue on the gcc list.

--
Josh
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/