Re: [PATCH 8/8] x86/alternative: Convert alternatives to assembler macros

From: Peter Zijlstra
Date: Mon Dec 08 2025 - 04:51:20 EST


On Sat, Dec 06, 2025 at 01:41:15PM -0800, Josh Poimboeuf wrote:
> Improve code generation readability by converting the alternatives into
> assembler macros which are created when alternative.h is included.
>
> Before:
>
> # ./arch/x86/include/asm/smap.h:47: alternative("", "stac", X86_FEATURE_SMAP);
> # 47 "./arch/x86/include/asm/smap.h" 1
> # ALT: oldinstr
> 771:
>
> 772:
> # ALT: padding
> .skip -(((775f-774f)-(772b-771b)) > 0) * ((775f-774f)-(772b-771b)),0x90
> 773:
> .pushsection .altinstructions, "aM", @progbits, 14
> .long 771b - .
> .long 774f - .
> .4byte ( 9*32+20)
> .byte 773b-771b
> .byte 775f-774f
> .popsection
> .pushsection .altinstr_replacement, "ax"
> ANNOTATE_DATA_SPECIAL
> # ALT: replacement
> 774:
> stac
> 775:
> .popsection
>
> After:
>
> # ./arch/x86/include/asm/smap.h:47: alternative("", "stac", X86_FEATURE_SMAP);
> # 47 "./arch/x86/include/asm/smap.h" 1
> ALTERNATIVE "", "stac", "( 9*32+20)"
>

So the problem with the gas macro thing is that it doesn't allow for
that nesting. I don't think we currently use it other than to define the
ALTERNATIVE_2 and ALTERNATIVE_3 macros, but IIRC the reason I started
all that was because it was fairly trivial to use things like
CALL_NOSPEC in an alternative (where CALL_NOSPEC is already an
alternative).

Anyway, yes, the macro variant is easier to read in the .s output.