On Thu, Aug 28, 2025 at 02:24:33PM -0700, Andi Kleen wrote:
> Jakub Jelinek <[email protected]> writes:
>
> > On Wed, Aug 27, 2025 at 03:52:11PM +0200, Michal Jires wrote:
> >> This new pass heuristically detects symbols referenced by toplevel
> >> assembly to prevent their optimization.
> >>
> >> Heuristics is done by comparing identifiers in assembly to known
> >> symbols.
> >>
> >> The pass is split into 2 passes, in LGEN and in WPA.
> >> There must be one pass for WPA to be able to reference any symbol.
> >> However in WPA there may be multiple symbols with the same name,
> >> so we handle those local symbols in LGEN.
> >
> > Why the heuristics when in GCC 15+ toplevel assembly can express those
> > exactly?
>
> The kernel maintainers rejected that.
Then maybe they should reconsider, because nothing else can work reliably.
Gas supports macros, so even if you teach the compiler about the detailed
syntax of assembly syntax of each target, due to the macros it isn't
possible to find out if some identifier will end up being stringified, or
will have some prefixes/suffixes appended to it, or if it will end up being
say a register name rather than symbol, etc. Not to mention that GCC wants
inline asms to be black boxes and that various programs actually post
process the assembly created by the compiler, so what appears in inline
asm doesn't really have to be even valid assembler, it can be arbitrary
text.
Last time I've heard the kernel only has very few toplevel asms that would
need to be tweaked, and it can be done with macros.
If you have
asm (".section whatever; .globl foo; foo: ...; use bar; .previous");
as something that defines foo and uses bar, in GCC 15 that should be
written as
extern int foo, bar; // Can be functions too
asm (".section whatever; .globl %cc0; %cc0: ...; use %cc1; .previous"
:: ":" (&foo), "-s" (&bar));
Then the compiler reliably knows what to rename in the asm template and
what should be kept as unmodified.
Jakub