Re: [PATCH v9 1/5] x86/boot: Remove "cc" clobber from memcmp()
From: David Laight
Date: Wed Sep 02 2026 - 04:46:34 EST
On Tue, 1 Sep 2026 15:16:58 +0200
Jan Beulich <jbeulich@xxxxxxxx> wrote:
> 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.)
And, if "cc" clobber wasn't redundant, you'd need clobbers for the cc flags
that weren't being used as output values.
David
>
> Jan
>