Messages in this thread Patch in this message | | | Date | Wed, 02 Jun 1999 09:13:06 +0200 | From | Giacomo Amabile Catenazzi <> | Subject | [PATCH] {asm-i386,linux}/string.h:Adjustments for **NOT** using gcc builtins |
| |
This patch (to linux-2.3.4) fixes: 1- Force the compiler not to use the builtin (in compiler) str* and mem* function, by rename it with preprocessor NOTE: I have modified more function that actually need. 2- __inline__ instead of inline (This is a header included in external program [indirectly!]) 3- use __kernel_size_t instead of size_t as in linux/string.h
Note: I change (actually) only asm-i386, because in some other arch. there are other change, so I want have some feedback. (e.g. in asm-m68k there are some function NEVER full defined has memcmp)
I've changed linux/string.h in this manner, because I want to include in linux/string.h some inline C functions (as asm-m68k/string.h do), but before this change, we must be sure that the other change is OK.
Maybe it is better instead of change -2-, to add at the top of linux/string.h: +#ifndef __KERNEL__ +#include <string.h> +#else ...all the file... +#endif This is cleaner, but I don't like it. Maybe it is better don't include <string.h> but there can be some inline that use/require it.
This patch works on egcs and gcc-2.7.2.3.
Test it!
Giacomo Catenazzi <cate@student.ethz.ch> diff -ur linux/include/asm-i386/string.h linux.mydevel/include/asm-i386/string.h --- linux/include/asm-i386/string.h Wed May 19 19:22:17 1999 +++ linux.mydevel/include/asm-i386/string.h Tue Jun 1 22:58:14 1999 @@ -28,7 +28,8 @@ */ #define __HAVE_ARCH_STRCPY -extern inline char * strcpy(char * dest,const char *src) +#define strcpy __kernel_strcpy +extern __inline__ char * strcpy(char * dest,const char *src) { int d0, d1, d2; __asm__ __volatile__( @@ -43,7 +44,8 @@ } #define __HAVE_ARCH_STRNCPY -extern inline char * strncpy(char * dest,const char *src,size_t count) +#define strncpy __kernel_strncpy +extern __inline__ char * strncpy(char * dest,const char *src,__kernel_size_t count) { int d0, d1, d2, d3; __asm__ __volatile__( @@ -63,7 +65,7 @@ } #define __HAVE_ARCH_STRCAT -extern inline char * strcat(char * dest,const char * src) +extern __inline__ char * strcat(char * dest,const char * src) { int d0, d1, d2, d3; __asm__ __volatile__( @@ -81,7 +83,7 @@ } #define __HAVE_ARCH_STRNCAT -extern inline char * strncat(char * dest,const char * src,size_t count) +extern __inline__ char * strncat(char * dest,const char * src,__kernel_size_t count) { int d0, d1, d2, d3; __asm__ __volatile__( @@ -105,7 +107,8 @@ } #define __HAVE_ARCH_STRCMP -extern inline int strcmp(const char * cs,const char * ct) +#define strcmp __kernel_strcmp +extern __inline__ int strcmp(const char * cs,const char * ct) { int d0, d1; register int __res; @@ -127,7 +130,8 @@ } #define __HAVE_ARCH_STRNCMP -extern inline int strncmp(const char * cs,const char * ct,size_t count) +#define strncmp __kernel_strncmp +extern __inline__ int strncmp(const char * cs,const char * ct,__kernel_size_t count) { register int __res; int d0, d1, d2; @@ -151,7 +155,7 @@ } #define __HAVE_ARCH_STRCHR -extern inline char * strchr(const char * s, int c) +extern __inline__ char * strchr(const char * s, int c) { int d0; register char * __res; @@ -171,7 +175,7 @@ } #define __HAVE_ARCH_STRRCHR -extern inline char * strrchr(const char * s, int c) +extern __inline__ char * strrchr(const char * s, int c) { int d0, d1; register char * __res; @@ -189,7 +193,8 @@ } #define __HAVE_ARCH_STRLEN -extern inline size_t strlen(const char * s) +#define strlen __kernel_strlen +extern __inline__ __kernel_size_t strlen(const char * s) { int d0; register int __res; @@ -203,7 +208,7 @@ return __res; } -extern inline void * __memcpy(void * to, const void * from, size_t n) +extern __inline__ void * __kernel_memcpy(void * to,const void * from,__kernel_size_t n) { int d0, d1, d2; __asm__ __volatile__( @@ -226,7 +231,7 @@ * This looks horribly ugly, but the compiler can optimize it totally, * as the count is constant. */ -extern inline void * __constant_memcpy(void * to, const void * from, size_t n) +extern inline void * __kernel_constant_memcpy(void * to,const void * from,__kernel_size_t n) { switch (n) { case 0: @@ -295,11 +300,12 @@ #define __HAVE_ARCH_MEMCPY #define memcpy(t, f, n) \ (__builtin_constant_p(n) ? \ - __constant_memcpy((t),(f),(n)) : \ - __memcpy((t),(f),(n))) + __kernel_constant_memcpy((t),(f),(n)) : \ + __kernel_memcpy((t),(f),(n))) #define __HAVE_ARCH_MEMMOVE -extern inline void * memmove(void * dest,const void * src, size_t n) +#define memmove __kernel_memmove +extern __inline__ void * memmove(void * dest,const void * src,__kernel_size_t n) { int d0, d1, d2; if (dest<src) @@ -324,10 +330,11 @@ return dest; } +/* use builtin (in gcc compiler) memcmp */ #define memcmp __builtin_memcmp #define __HAVE_ARCH_MEMCHR -extern inline void * memchr(const void * cs,int c,size_t count) +extern __inline__ void * memchr(const void * cs,int c,__kernel_size_t count) { int d0; register void * __res; @@ -344,7 +351,7 @@ return __res; } -extern inline void * __memset_generic(void * s, char c,size_t count) +extern __inline__ void * __memset_generic(void * s,char c,__kernel_size_t count) { int d0, d1; __asm__ __volatile__( @@ -365,7 +372,7 @@ * things 32 bits at a time even when we don't know the size of the * area at compile-time.. */ -extern inline void * __constant_c_memset(void * s, unsigned long c, size_t count) +extern __inline__ void * __constant_c_memset(void * s,unsigned long c,__kernel_size_t count) { int d0, d1; __asm__ __volatile__( @@ -386,7 +393,8 @@ /* Added by Gertjan van Wingerde to make minix and sysv module work */ #define __HAVE_ARCH_STRNLEN -extern inline size_t strnlen(const char * s, size_t count) +#define strnlen __kernel_strnlen +extern __inline__ __kernel_size_t strnlen(const char * s,__kernel_size_t count) { int d0; register int __res; @@ -410,7 +418,7 @@ * This looks horribly ugly, but the compiler can optimize it totally, * as we by now know that both pattern and count is constant.. */ -extern inline void * __constant_c_and_count_memset(void * s, unsigned long pattern, size_t count) +extern __inline__ void * __constant_c_and_count_memset(void * s,unsigned long pattern,__kernel_size_t count) { switch (count) { case 0: @@ -469,7 +477,7 @@ * find the first occurrence of byte 'c', or 1 past the area if none */ #define __HAVE_ARCH_MEMSCAN -extern inline void * memscan(void * addr, int c, size_t size) +extern __inline__ void * memscan(void * addr,int c,__kernel_size_t size) { if (!size) return addr; Only in linux.mydevel/include/asm-i386: string.h~ diff -ur linux/include/linux/string.h linux.mydevel/include/linux/string.h --- linux/include/linux/string.h Wed May 19 19:28:13 1999 +++ linux.mydevel/include/linux/string.h Tue Jun 1 22:59:00 1999 @@ -7,40 +7,80 @@ #define NULL ((void *) 0) #endif -#ifdef __cplusplus -extern "C" { -#endif - -extern char * ___strtok; -extern char * strcpy(char *,const char *); -extern char * strncpy(char *,const char *, __kernel_size_t); -extern char * strcat(char *, const char *); -extern char * strncat(char *, const char *, __kernel_size_t); -extern char * strchr(const char *,int); -extern char * strrchr(const char *,int); -extern char * strpbrk(const char *,const char *); -extern char * strtok(char *,const char *); -extern char * strstr(const char *,const char *); -extern __kernel_size_t strlen(const char *); -extern __kernel_size_t strnlen(const char *,__kernel_size_t); -extern __kernel_size_t strspn(const char *,const char *); -extern int strcmp(const char *,const char *); -extern int strncmp(const char *,const char *,__kernel_size_t); -extern int strnicmp(const char *, const char *, __kernel_size_t); - -extern void * memset(void *,int,__kernel_size_t); -extern void * memcpy(void *,const void *,__kernel_size_t); -extern void * memmove(void *,const void *,__kernel_size_t); -extern void * memscan(void *,int,__kernel_size_t); -extern int memcmp(const void *,const void *,__kernel_size_t); - /* * Include machine specific inline routines */ #include <asm/string.h> + #ifdef __cplusplus -} + #define externC extern "C" +#else + #define externC extern +#endif + +extern char * ___strtok; +#ifndef __HAVE_ARCH_STRCPY + externC char * strcpy(char *,const char *); +#endif +#ifndef __HAVE_ARCH_STRNCPY + externC char * strncpy(char *,const char *, __kernel_size_t); +#endif +#ifndef __HAVE_ARCH_STRCAT + externC char * strcat(char *, const char *); +#endif +#ifndef __HAVE_ARCH_STRNCAT + externC char * strncat(char *, const char *, __kernel_size_t); +#endif +#ifndef __HAVE_ARCH_STRCHR + externC char * strchr(const char *,int); +#endif +#ifndef __HAVE_ARCH_STRRCHR + externC char * strrchr(const char *,int); +#endif +#ifndef __HAVE_ARCH_STRPBRK + externC char * strpbrk(const char *,const char *); #endif +#ifndef __HAVE_ARCH_STRTOK + externC char * strtok(char *,const char *); +#endif +#ifndef __HAVE_ARCH_STRSTR + externC char * strstr(const char *,const char *); +#endif +#ifndef __HAVE_ARCH_STRLEN + externC __kernel_size_t strlen(const char *); +#endif +#ifndef __HAVE_ARCH_STRNLEN + externC __kernel_size_t strnlen(const char *,__kernel_size_t); +#endif +#ifndef __HAVE_ARCH_STRSPN + externC __kernel_size_t strspn(const char *,const char *); +#endif +#ifndef __HAVE_ARCH_STRCMP + externC int strcmp(const char *,const char *); +#endif +#ifndef __HAVE_ARCH_STRNCMP + externC int strncmp(const char *,const char *,__kernel_size_t); +#endif +#ifndef __HAVE_ARCH_STRNICMP + externC int strnicmp(const char *, const char *, __kernel_size_t); +#endif +#ifndef __HAVE_ARCH_MEMSET + externC void * memset(void *,int,__kernel_size_t); +#endif +#ifndef __HAVE_ARCH_MEMCPY + externC void * memcpy(void *,const void *,__kernel_size_t); +#endif +#ifndef __HAVE_ARCH_MEMMOVE + externC void * memmove(void *,const void *,__kernel_size_t); +#endif +#ifndef __HAVE_ARCH_MEMSCAN + externC void * memscan(void *,int,__kernel_size_t); +#endif +#ifndef __HAVE_ARCH_MEMCMP + externC int memcmp(const void *,const void *,__kernel_size_t); +#endif + +#undef externC #endif /* _LINUX_STRING_H_ */ | |