Re: [PATCH v9 1/5] x86/boot: Remove "cc" clobber from memcmp()
From: Jan Beulich
Date: Tue Sep 01 2026 - 09:27:16 EST
On 22.08.2026 20:33, Mauricio Faria de Oliveira wrote:
> According to the GCC documentation, conditions in the flags register
> (e.g., "=@ccnz") are output operands [1] and the compiler is aware [2].
>
> Also, clobbers (e.g., "cc") may not overlap with an output operand [2].
>
> Thus, remove the "cc" clobber as it is redudant, and overlaps with, the
> "=@ccnz" output operand.
>
> """
> 6.11.2.4 Flag Output Operands
>
> On some targets, a special form of output operand exists by which
> conditions in the flags register may be outputs of the asm. [...]
>
> 6.11.2.6 Clobbers and Scratch Registers
>
> While the compiler is aware of changes to entries listed in the
> output operands, [...]
>
> Clobber descriptions may not in any way overlap with an input or
> output operand. [...]
> """
>
> Reported-by: "H. Peter Anvin" <hpa@xxxxxxxxx>
> Link: https://lore.kernel.org/all/5e19b195-0ca2-4510-81cb-497b40e4aaf5@xxxxxxxxx/
> Fixes: a8c171c107c0 ("x86/boot: Add volatile, clobbers and zero-length test in memcmp()")
> Signed-off-by: Mauricio Faria de Oliveira <mfo@xxxxxxxxxx>
> Link: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Flag-Output-Operands [1]
> Link: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Clobbers-and-Scratch-Registers-1 [2]
Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
> --- a/arch/x86/boot/string.c
> +++ b/arch/x86/boot/string.c
> @@ -40,7 +40,7 @@ int memcmp(const void *s1, const void *s2, size_t len)
> asm volatile("test %3, %3\n\t"
> "repe cmpsb"
> : "=@ccnz" (diff), "+D" (s1), "+S" (s2), "+c" (len)
> - : : "cc", "memory");
> + : : "memory");
In fact I'm using a modified gcc which properly rejects such conflicting
uses of output and clobber. ("cc" clobbers are redundant on x86 anyway.)
Jan