[PATCH v9 1/5] x86/boot: Remove "cc" clobber from memcmp()

From: Mauricio Faria de Oliveira

Date: Sat Aug 22 2026 - 14:33:30 EST


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]
---
arch/x86/boot/string.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/boot/string.c b/arch/x86/boot/string.c
index 1632d40e1f545ae0665597069b568ea6b6c263e5..03278b4393887cb71cb063818d3378c4f52b06f8 100644
--- 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");
return diff;
}


--
2.47.3