From c545699aca137204c9e435f2be70cda0723c92c5 Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Tue, 3 Feb 2004 18:32:36 -0800 Subject: [PATCH] [PATCH] string fixes for gcc 3.4 From: Andi Kleen gcc 3.4 optimizes sprintf(foo,"%s",string) into strcpy. Unfortunately that isn't seen by the inliner and linux/i386 has no out-of-line strcpy so you end up with a linker error. This patch adds out of line copies for most string functions to avoid this. Actually it doesn't export them to modules yet, that would be the next step. BTW In my opinion we shouldn't use inline string functions at all. The __builtin_str* in modern gcc are better (I used them very successfully on x86-64) and for the bigger functions like strrchr,strtok et.al. it just doesn't make any sense to inline them or even code them in assembler. Also fix the bcopy prototype gcc was complaining about. --- include/asm-i386/string.h | 14 ++++++-------- lib/string.c | 9 ++++++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/include/asm-i386/string.h b/include/asm-i386/string.h index daecfc479f355..a14f9f37d9c1f 100644 --- a/include/asm-i386/string.h +++ b/include/asm-i386/string.h @@ -23,7 +23,10 @@ * consider these trivial functions to be PD. */ -#define __HAVE_ARCH_STRCPY +/* AK: in fact I bet it would be better to move this stuff all out of line. + */ +#if !defined(IN_STRING_C) + static inline char * strcpy(char * dest,const char *src) { int d0, d1, d2; @@ -37,7 +40,6 @@ __asm__ __volatile__( return dest; } -#define __HAVE_ARCH_STRNCPY static inline char * strncpy(char * dest,const char *src,size_t count) { int d0, d1, d2, d3; @@ -56,7 +58,6 @@ __asm__ __volatile__( return dest; } -#define __HAVE_ARCH_STRCAT static inline char * strcat(char * dest,const char * src) { int d0, d1, d2, d3; @@ -73,7 +74,6 @@ __asm__ __volatile__( return dest; } -#define __HAVE_ARCH_STRNCAT static inline char * strncat(char * dest,const char * src,size_t count) { int d0, d1, d2, d3; @@ -96,7 +96,6 @@ __asm__ __volatile__( return dest; } -#define __HAVE_ARCH_STRCMP static inline int strcmp(const char * cs,const char * ct) { int d0, d1; @@ -117,7 +116,6 @@ __asm__ __volatile__( return __res; } -#define __HAVE_ARCH_STRNCMP static inline int strncmp(const char * cs,const char * ct,size_t count) { register int __res; @@ -140,7 +138,6 @@ __asm__ __volatile__( return __res; } -#define __HAVE_ARCH_STRCHR static inline char * strchr(const char * s, int c) { int d0; @@ -159,7 +156,6 @@ __asm__ __volatile__( return __res; } -#define __HAVE_ARCH_STRRCHR static inline char * strrchr(const char * s, int c) { int d0, d1; @@ -176,6 +172,8 @@ __asm__ __volatile__( return __res; } +#endif + #define __HAVE_ARCH_STRLEN static inline size_t strlen(const char * s) { diff --git a/lib/string.c b/lib/string.c index 3ba8cabedf84f..e660de079a576 100644 --- a/lib/string.c +++ b/lib/string.c @@ -18,6 +18,8 @@ * Matthew Hawkins * - Kissed strtok() goodbye */ + +#define IN_STRING_C 1 #include #include @@ -437,12 +439,13 @@ void * memset(void * s,int c,size_t count) * You should not use this function to access IO space, use memcpy_toio() * or memcpy_fromio() instead. */ -void bcopy(const char * src, char * dest, int count) +void bcopy(const void * srcp, void * destp, size_t count) { - char *tmp = dest; + const char *src = srcp; + char *dest = destp; while (count--) - *tmp++ = *src++; + *dest++ = *src++; } #endif -- 2.53.0