Bug in strlen on old MIPS CPUs

Corinna Vinschen vinschen@redhat.com
Mon Jan 10 09:19:00 GMT 2011


On Dec 21 13:18, Steve Legg wrote:
> > but: is there a #define that can be checked to see if the CPU is
> R2000/R3000?
> 
> It appears that GCC defines __R3000, so this would be a safe patch.  The
> same issue would happen on R2000, so possibly add || defined(__R2000) too,
> but it's probably unlikely that anyone will ever compile newlib on such a
> machine (if any still exist that aren't in museums or landfills ;).
> 
> --- newlib-1.18.0.orig//newlib/libc/machine/mips/strlen.c	2002-03-14
> 02:41:43 +0000
> +++ newlib-1.18.0//newlib/libc/machine/mips/strlen.c	2010-12-21 05:22:00
> +0000
> @@ -20,7 +20,7 @@
>  
>  /* MIPS16 needs to come first.  */
>  
> -#if defined(__mips16)
> +#if defined(__mips16) || defined(__R3000)
>  size_t
>  strlen (const char *str)
>  {

Wouldn't it be better to add a nop, like this?

Index: libc/machine/mips/strlen.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/machine/mips/strlen.c,v
retrieving revision 1.2
diff -u -p -r1.2 strlen.c
--- libc/machine/mips/strlen.c	14 Mar 2002 02:41:43 -0000	1.2
+++ libc/machine/mips/strlen.c	10 Jan 2011 09:19:11 -0000
@@ -60,6 +60,9 @@ __asm__(""			/* 32-bit MIPS targets */
 	"	addiu	$2,$4,1\n"
 	"\n"
 	"1:	lbu	$3,0($4)\n"
+#ifdef (__R3000)
+	"	nop	\n"
+#endif
 	"	bnez	$3,1b\n"
 	"	addiu	$4,$4,1\n"
 	"\n"


Corinna

-- 
Corinna Vinschen
Cygwin Project Co-Leader
Red Hat



More information about the Newlib mailing list