https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88088

--- Comment #17 from Mark Wielaard <mark at gcc dot gnu.org> ---
(In reply to Segher Boessenkool from comment #16)
> Something as trivial as this
> 
> ===
> void h(int (*)(void));
> void f(int x)
> {
>         int g(void) { return x; }
>         h(g);
> }
> ===
> 
> will already do.  *Anything* that needs trampolines will do.

Sure, if you pass around a nested function pointer that captures context that
the compiler cannot inline because it is passed to another function that cannot
capture that same context.

I just haven't seen any code base that does that. That is why I was asking for
a concrete example.

But I know it is possible to accidentally do this and that is why I like the
have -Wall/-Wtrampolines warn about it. The above example can trivially be
rewritten to not give the warning:

void h(int (*)(int), int);
void f(int x)
{
         int g(int i) { return i; }
         h(g, x);
}

And I believe that is what normally people would want. Having
-Wall/-Wtrampolines warn about it when they make the mistake of writing code
that would require executable code on the stack when they use nested functions.

I could be wrong of course, I might not have enough imagination to appreciate
that what I believe is the correct/trivial way to rewrite the code to avoid the
warning (and potential security issue) is in fact a real burden in some
environments.

Is your objection to add -Wtrampolines to -Wall because you have actual code
that would be hard to rewrite to avoid the warning? Or is it just that you
believe it should not be a default warning on some targets (those which already
have the security issue of having a default executable stack)?

Reply via email to