Re: [PATCH -tip 0/3] x86/asm: Use generic asm operand modifiers instead of %P in asm templates

From: Borislav Petkov
Date: Tue Mar 19 2024 - 08:45:57 EST


On Tue, Mar 19, 2024 at 11:40:11AM +0100, Uros Bizjak wrote:
> The "P" asm operand modifier is a x86 target-specific modifier.
>
> For x86_64, when used with a symbol reference, the "P" modifier
> emits "sym" instead of "sym(%rip)". When used with a constant, the
> "P" modifier emits "cst" instead of "$cst". This property is used to
> emit bare symbol references and bare constants without all
> syntax-specific prefixes.
>
> The generic "c", "n" and "a" operand modifiers should be used instead.
> The following table shows the modifiers supported by all targets and
> their effects:
>
> Modifier Description
> -----------------------------------------------------------
> 'c' Require a constant operand and print the
> constant expression with no punctuation.
> 'n' Like '%c' except that the value of the constant
> is negated before printing.
> 'a' Substitute a memory reference, with the actual
> operand treated as the address. This may be
> useful when outputting a "load address"
> instruction, because often the assembler syntax
> for such an instruction requires you to write
> the operand as if it were a memory reference.
>
> Also note that unlike GCC, clang emits %rip-relative symbol
> reference with "P" asm operand modifier, so the patch also unifies
> symbol handling with both compilers.

FTR, I really appreciate the clear explanations of the operand modifiers
along with an example in the commit messages. What they really do and
what they mean have caused some serious head-scratching in the past, up
to the point where I went through gcc sources with Matz' help to figure
out what some of them do.

So thanks!

:-)

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette