Re: [PATCH 4/6] objtool: Replace STACK_FRAME_NON_STANDARD annotation

Peter Zijlstra
2019-02-25T16:17:32Z

On Mon, Feb 25, 2019 at 10:11:24AM -0600, Josh Poimboeuf wrote:
> On Mon, Feb 25, 2019 at 01:43:34PM +0100, Peter Zijlstra wrote:
> > Replace the existing STACK_FRAME_NON_STANDARD annotation with a
> > 'better' scheme.
> >
> > The old annotation works by taking the address of a function; this
> > is visible to the compiler and might affect code generation (the
> > function pointer escapes). The new annotation simply stores the
> > function name and has objtool do a symtab lookup.
> >
> > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
> > ---
> > include/linux/frame.h | 19 +++++++++++++---
> > tools/objtool/check.c | 58 +++++++++++++++++++++-----------------------------
> > tools/objtool/check.h | 1
> > 3 files changed, 41 insertions(+), 37 deletions(-)
> >
> > --- a/include/linux/frame.h
> > +++ b/include/linux/frame.h
> > @@ -11,9 +11,22 @@
> > *
> > * For more information, see tools/objtool/Documentation/stack-validation.txt.
> > */
> > -#define STACK_FRAME_NON_STANDARD(func) \
> > - static void __used __section(.discard.func_stack_frame_non_standard) \
> > - *__func_stack_frame_non_standard_##func = func
> > +#define STACK_FRAME_NON_STANDARD(func) \
> > + asm (".pushsection .discard.nonstd_frame_strtab, \"S\", @3\n\t" \
> > + "999: .ascii \"" #func "\"\n\t" \
> > + " .byte 0\n\t" \
> > + ".popsection\n\t" \
> > + ".pushsection .discard.nonstd_frame\n\t" \
> > + ".long 999b - .\n\t" \
> > + ".popsection\n\t")
> > +
>
> I don't think this will work in the case where GCC does an IPA
> optimization and renames the function (e.g., renames func to
> func.isra.1234), right? That might be a deal breaker...

*groan*... indeed :/ So back to the old scheme then? Andy, any other
clever ideas?

> > +/*
> > + * SHT_STRTAB(@3) sections should start with a \0 byte such that the 0 offset
> > + * encodes the NULL string.
> > + */
> > +asm (".pushsection .discard.nonstd_frame_strtab, \"S\", @3\n\t"
> > + ".byte 0\n\t"
> > + ".popsection\n\t");
>
> Including the file creates the section, which is a bit nasty. Instead
> just change STACK_FRAME_NON_STANDARD to prefix every string with a \0?

That would get us \0\0 between every string, which I suppose is in-spec,
but weird. I figured that since it is a .discard. section, getting it
wasn't a problem.