Re: [PATCH] compiler/gcc: Make asm() templates asm __inline__() by default

From: Uros Bizjak
Date: Wed Mar 19 2025 - 00:58:24 EST


On Tue, Mar 18, 2025 at 9:11 PM Ingo Molnar <mingo@xxxxxxxxxx> wrote:

> #ifdef CONFIG_CC_HAS_ASM_INLINE
> # define asm_inline __asm__ __inline
> # define asm(...) asm_inline(__VA_ARGS__)
> #else
> # define asm_inline asm
> #endif
>
> And I fixed up the places where this isn't syntactically correct:
>
> 35 files changed, 82 insertions(+), 79 deletions(-)
>
> I haven't looked at code generation much yet, but text size changes are
> minimal:
>
> text data bss dec hex filename
> 29429076 7931870 1401196 38762142 24f769e vmlinux.before
> 29429631 7931870 1401200 38762701 24f78cd vmlinux.after
>
> Which is promising, assuming I haven't messed up anywhere.

Please use bloat-o-meter, it is more precise.

Actually, functions with the most impact (x86 locking functions and
__arch_hweight) were recently converted to asm_inline, so besides
__untagged_addr, the remaining have very little impact, if at all
(c.f. amd_clear_divider() ). There is also no need to convert asm()
without directives inside.

My proposal would be to convert the remaining few cases (the remaining
asms involving ALTERNATIVE and exceptions) "by hand" to asm_inline()
and stick a rule in checkpatch to use asm_inline() in the code
involving asm(), like we have the rule with asm volatile.

I don't think redefining an important C keyword is a good approach, it
obfuscates its meaning too much. And as has been shown by Ingo's
experiment, there is a substantial effort to fix false positives.
Instead of fixing these, we can trivially convert the remaining cases
to asm_volatile() as well, without obfuscating asm(). Checkpatch can
take care of future cases.

Thanks,
Uros.