[PATCH] PR880088 Enable -Wtrampolines for no-exec-stack targets with -Wall.

Mark Wielaard mark@klomp.org
Mon Nov 26 19:23:00 GMT 2018


On Mon, 2018-11-26 at 18:29 +0000, Joseph Myers wrote:
> On Mon, 26 Nov 2018, Mark Wielaard wrote:
> 
> > Define a new target macro TARGET_HAS_DEFAULT_NOEXEC_STACK for those
> > targets
> > that have a non-executable default stack based on when they call
> > file_end_indicate_exec_stack.
> 
> Some targets (e.g. ia64) may default to no-exec stacks without
> needing 
> that hook (e.g. if they use function descriptors, so trampolines have
> no 
> need for an executable stack).

Yes, but for such targets it doesn't really matter whether or not they
define this new target macro. The -Wtrampolines warning only warns when
creating an executable runtime trampoline on the stack. It won't for
non-executable trampolines. So yes, then this target macro doesn't have
to be defined even if the stack is non-executable by default. Defining
the TARGET_HAS_DEFAULT_NOEXEC_STACK macro for such a target will then
make it so that -Wall enables -Wtrampolines by default, but
-Wtrampolines still won't warn because the trampolines aren't
executable code on the stack. But I believe that is the correct
behavior. The warning should only happen if gcc would otherwise
silently make the stack executable for a target that has a default non-
executable stack (and it won't for target that uses function
descriptors).

I thought the documentation updates for the warning made that more
clear, but maybe they can be improved even more?

A case could be made that taking a nested function pointer that escapes
the lexical scope from which it takes some context variable always is a
dangerous thing to do and that it should even warn if supporting that
doesn't involve placing an executable runtime trampoline on the stack.
Which is actually the case I made in the original bug. But I don't
believe I got consensus for that.

Thanks,

Mark



More information about the Gcc-patches mailing list