Skip to contentSkip to conversation

x86: add missed clobber for 32-bit memmove

PATCH New Jike Song 3 participants 5 messages Oct 17, 2008 – Oct 20, 2008 x86

lore
Share & tools
lore

Jike Song

author
#0 lore raw

PATCH 1/1 x86: add missed clobber for 32-bit memmove

author
#1 lore raw

PATCH 1/1 x86: add missed clobber for 32-bit memmove

memmove() is implemented by inline assembly. It calls std at first and cld at last, but EFLAGS still should be clobbered.

---
 arch/x86/lib/memcpy_32.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/lib/memcpy_32.c +1 -1
index 5415a9d..99a8240 100644
@@ -36,7 +36,7 @@ void *memmove(void *dest, const void *src, size_t n)
 			:"0" (n),
 			 "1" (n-1+src),
 			 "2" (n-1+dest)
-			:"memory");
+			:"cc", "memory");
 	}
 	return dest;
 }
Signature · 1 line
1.6.0.1
#2 lore raw
Quoted 3 lines · Jike Song

memmove() is implemented by inline assembly. It calls std at first and cld at last, but EFLAGS still should be clobbered.

I think x86 gcc assumes "cc" is always clobbered by asms. Otherwise there'll need to be a lot more "cc" clobbers than this...

J

Quoted 19 lines
---
 arch/x86/lib/memcpy_32.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/x86/lib/memcpy_32.c +1 -1
index 5415a9d..99a8240 100644
@@ -36,7 +36,7 @@ void *memmove(void *dest, const void *src, size_t n)
 			:"0" (n),
 			 "1" (n-1+src),
 			 "2" (n-1+dest)
-			:"memory");
+			:"cc", "memory");
 	}
 	return dest;
 }
#3 lore raw
In reply to Jike Song
Quoted 2 lines · Jike Song

memmove() is implemented by inline assembly. It calls std at first and cld at last, but EFLAGS still should be clobbered.

gcc always treats EFLAGS as clobbered on x86. The "cc" clobber is needed on some platforms, but is a noop on x86.

-hpa

author
#4 lore raw
Quoted 7 lines · H. Peter Anvin
Quoted 3 lines · Jike Song

memmove() is implemented by inline assembly. It calls std at first and cld at last, but EFLAGS still should be clobbered.

gcc always treats EFLAGS as clobbered on x86. The "cc" clobber is needed on some platforms, but is a noop on x86.

No wonder there are inline asms that clobbered eflags/rflags but without declaring them as clobbered. Thanks for your information.

It turns out that I need to read through the gcc x86 back-end as long as I want to be a Linux/x86 developer, right? That sounds discouraging:)

Signature · 2 lines
Thanks,
Jike