This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: PROPOSAL: Extend inline asm syntax with size spec
- From: Segher Boessenkool <segher at kernel dot crashing dot org>
- To: Borislav Petkov <bp at alien8 dot de>
- Cc: gcc at gcc dot gnu dot org, Richard Biener <rguenther at suse dot de>, Michael Matz <matz at suse dot de>, Nadav Amit <namit at vmware dot com>, Ingo Molnar <mingo at redhat dot com>, linux-kernel at vger dot kernel dot org, x86 at kernel dot org, Masahiro Yamada <yamada dot masahiro at socionext dot com>, Sam Ravnborg <sam at ravnborg dot org>, Alok Kataria <akataria at vmware dot com>, Christopher Li <sparse at chrisli dot org>, Greg Kroah-Hartman <gregkh at linuxfoundation dot org>, "H. Peter Anvin" <hpa at zytor dot com>, Jan Beulich <JBeulich at suse dot com>, Josh Poimboeuf <jpoimboe at redhat dot com>, Juergen Gross <jgross at suse dot com>, Kate Stewart <kstewart at linuxfoundation dot org>, Kees Cook <keescook at chromium dot org>, linux-sparse at vger dot kernel dot org, Peter Zijlstra <peterz at infradead dot org>, Philippe Ombredanne <pombredanne at nexb dot com>, Thomas Gleixner <tglx at linutronix dot de>, virtualization at lists dot linux-foundation dot org, Linus Torvalds <torvalds at linux-foundation dot org>, Chris Zankel <chris at zankel dot net>, Max Filippov <jcmvbkbc at gmail dot com>, linux-xtensa at linux-xtensa dot org
- Date: Sun, 7 Oct 2018 10:14:28 -0500
- Subject: Re: PROPOSAL: Extend inline asm syntax with size spec
- References: <20181003213100.189959-1-namit@vmware.com> <20181007091805.GA30687@zn.tnic> <20181007132228.GJ29268@gate.crashing.org> <20181007141349.GD30687@zn.tnic>
On Sun, Oct 07, 2018 at 04:13:49PM +0200, Borislav Petkov wrote:
> On Sun, Oct 07, 2018 at 08:22:28AM -0500, Segher Boessenkool wrote:
> > GCC already estimates the *size* of inline asm, and this is required
> > *for correctness*.
>
> I didn't say it didn't - but the heuristic could use improving.
How? It is as sharp an estimate as can be *already*: number of insns
times maximum size per insn.
If you get this wrong, conditional branches (and similar things, but
conditional branches usually hit first, and hurt most) will stop working
correctly, unless binutils uses relaxation for those on your architecture
(most don't).
> > So I guess the real issue is that the inline asm size estimate for x86
> > isn't very good (since it has to be pessimistic, and x86 insns can be
> > huge)?
>
> Well, the size thing could be just a "parameter" or "hint" of sorts, to
> tell gcc to inline the function X which is inlining the asm statement
> into the function Y which is calling function X. If you look at the
> patchset, it is moving everything to asm macros where gcc is apparently
> able to do better inlining.
Yes, that will cause fewer problems I think: do not override size _at all_,
but give a hint to the inliner.
> > > 3) asm ("...") __attribute__((asm_size(<size-expr>)));
> >
> > Eww.
>
> Why?
Attributes are clumsy and clunky and kludgy.
It never is well-defined how attributes interact, and the more attributes
we define and use, the more that matters.
> > More precise *size* estimates, yes. And if the user lies he should not
> > be surprised to get assembler errors, etc.
>
> Yes.
>
> Another option would be if gcc parses the inline asm directly and
> does a more precise size estimation. Which is a lot more involved and
> complicated solution so I guess we wanna look at the simpler ones first.
>
> :-)
Which is *impossible* to do. Inline assembler is free-form text.
> > I don't like 2) either. But 1) looks interesting, depends what its
> > semantics would be? "Don't count this insn's size for inlining decisions",
> > maybe?
>
> Or simply "this asm statement has a size of 1" to mean, inline it
> everywhere. Which has the same caveats as above.
"Has minimum length" then (size 1 cannot work on most archs).
> > Another option is to just force inlining for those few functions where
> > GCC currently makes an inlining decision you don't like. Or are there
> > more than a few?
>
> I'm afraid they're more than a few and this should work automatically,
> if possible.
Would counting *all* asms as having minimum length for inlining decisions
work? Will that give bad side effects?
Or since this problem is quite specific to x86, maybe some target hook is
wanted? Things work quite well elsewhere as-is, degrading that is not a
good idea.
Segher