Skip to contentSkip to conversation

explicitly defining memmove for x86_64

PATCH In review Scott Parish 3 participants 3 messages May 4, 2005 – May 7, 2005

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 explicitly defining memmove for x86_64

Without the attached patch ubuntu's gcc (3.3.5) was complaining about the implicit declaration of __builtin_memmove. Extern'ing past that, the linker wouldn't resolve the same symbol.

This patch just does the same thing that is already done for x86_32.

sRp

Signature · 1 line
Scott Parish
xen/include/asm-x86/x86_64/string.h +23 -1
@@ -3,7 +3,29 @@
 
 #define __HAVE_ARCH_MEMMOVE
 #define memmove(dest,src,n) (__memmove((dest),(src),(n)))
-#define __memmove(dest,src,n) (__builtin_memmove((dest),(src),(n)))
+static inline void *__memmove(void * dest,const void * src, size_t n)
+{
+int d0, d1, d2;
+if (dest<src)
+__asm__ __volatile__(
+	"rep\n\t"
+	"movsb"
+	: "=&c" (d0), "=&S" (d1), "=&D" (d2)
+	:"0" (n),"1" (src),"2" (dest)
+	: "memory");
+else
+__asm__ __volatile__(
+	"std\n\t"
+	"rep\n\t"
+	"movsb\n\t"
+	"cld"
+	: "=&c" (d0), "=&S" (d1), "=&D" (d2)
+	:"0" (n),
+	 "1" (n-1+(const char *)src),
+	 "2" (n-1+(char *)dest)
+	:"memory");
+return dest;
+}
 
 #define __HAVE_ARCH_MEMCPY
 #define memcpy(t,f,n) (__memcpy((t),(f),(n)))

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

#1 lore raw

I applied this patch, and it went further, but it is failing now with these errors:

gcc -DPIC -m64 -Wall -Werror -O3 -fno-strict-aliasing - I ../../tools/libxutil
-I. -Wp,-MD,.xc_ptrace.opic.d -fPIC -c -o xc_ptrace.opic xc_ptrace.c In file included from /usr/include/asm/sigcontext.h:4,

                 from /usr/include/asm-x86_64/processor.h:13,
                 from /usr/include/asm/processor.h:4,
                 from /usr/include/asm-x86_64/elf.h:10,
                 from /usr/include/asm/elf.h:4,
                 from xc_ptrace.c:4:

/usr/include/asm-x86_64/sigcontext.h:9: error: redefinition of `struct _fpstate'
/usr/include/asm-x86_64/sigcontext.h:23: error: redefinition of `struct sigconte
xt'
In file included from /usr/include/asm/pda.h:4,

                 from /usr/include/asm-x86_64/current.h:7,
                 from /usr/include/asm/current.h:4,
                 from /usr/include/asm-x86_64/processor.h:18,
                 from /usr/include/asm/processor.h:4,
                 from /usr/include/asm-x86_64/elf.h:10,
                 from /usr/include/asm/elf.h:4,
                 from xc_ptrace.c:4:

/usr/include/asm-x86_64/pda.h:26: error: `CONFIG_X86_L1_CACHE_SHIFT' undeclared
here (not in a function)
/usr/include/asm-x86_64/pda.h:26: error: requested alignment is not a constant
In file included from /usr/include/asm/system.h:4,

                 from /usr/include/asm-x86_64/processor.h:19,
                 from /usr/include/asm/processor.h:4,
                 from /usr/include/asm-x86_64/elf.h:10,
                 from /usr/include/asm/elf.h:4,
                 from xc_ptrace.c:4:

/usr/include/asm-x86_64/system.h: In function `__cmpxchg':
/usr/include/asm-x86_64/system.h:249: error: `LOCK_PREFIX' undeclared (first use
in this function)
/usr/include/asm-x86_64/system.h:249: error: (Each undeclared identifier is repo
rted only once
/usr/include/asm-x86_64/system.h:249: error: for each function it appears in.)
/usr/include/asm-x86_64/system.h:249: error: parse error before string constant
/usr/include/asm-x86_64/system.h:255: error: parse error before string constant
/usr/include/asm-x86_64/system.h:261: error: parse error before string constant
/usr/include/asm-x86_64/system.h:267: error: parse error before string constant
In file included from /usr/include/asm/processor.h:4,

                 from /usr/include/asm-x86_64/elf.h:10,
                 from /usr/include/asm/elf.h:4,
                 from xc_ptrace.c:4:

/usr/include/asm-x86_64/processor.h: At top level:
/usr/include/asm-x86_64/processor.h:229: error:
`CONFIG_X86_L1_CACHE_SHIFT' unde clared here (not in a
function)
/usr/include/asm-x86_64/processor.h:229: error: requested alignment is
not a con stant
/usr/include/asm-x86_64/processor.h: In function `prefetchw':
/usr/include/asm-x86_64/processor.h:396: error: called object is not a function
make[4]: *** [xc_ptrace.opic] Error 1
make[4]: Leaving directory `/tmp/xen-unstable/tools/libxc' make[3]: *** [build] Error 2
make[3]: Leaving directory `/tmp/xen-unstable/tools/libxc' make[2]: *** [install] Error 2
make[2]: Leaving directory `/tmp/xen-unstable/tools' make[1]: *** [tools] Error 2
make[1]: Leaving directory `/tmp/xen-unstable'
make: *** [world] Error 2
bl2-14:/tmp/xen-unstable #

Quoted 13 lines · Scott Parish

Without the attached patch ubuntu's gcc (3.3.5) was complaining about the implicit declaration of __builtin_memmove. Extern'ing past that, the linker wouldn't resolve the same symbol.

This patch just does the same thing that is already done for x86_32.

sRp

Signature · 2 lines
Scott Parish
_______________________________________________ Xen-devel mailing list [email protected] http://lists.xensource.com/xen-devel
#2 lore raw
In reply to Scott Parish
Quoted 9 lines

Without the attached patch ubuntu's gcc (3.3.5) was complaining about the implicit declaration of __builtin_memmove. Extern'ing past that, the linker wouldn't resolve the same symbol.

This patch just does the same thing that is already done for x86_32.

sRp

Thanks. I checked in a version that always uses the implementation in arch/x86/string.c. It's not worthwhile inlining since it's never used anywhere performance critical (should probably remove the version in x86_32/string.h as well).

-- Keir