On Monday 20 July 2009 23:00, Mike Frysinger wrote:
> > With attached config, and i486-linux-uclibc-XXX
> > toolchain, it works for me.
> >
> > Can you send me your .config, preprocessed source
> > and gcc command line which gives you trouble?
> >
> > What does your gcc -v say?
> 
> defconfig i386, then enable DODEBUG and DODEBUG_PT.  using gcc-4.1.1.

Thanks. The offending gcc command line is:


gcc -c libc/stdio/_fwrite.c -o libc/stdio/_fwrite.os -include 
./include/libc-symbols.h \
-Wall -Wstrict-prototypes -fno-strict-aliasing -Wnested-externs -Wshadow 
-Wmissing-noreturn \
-Wmissing-format-attribute -Wformat=2 -Wmissing-prototypes 
-Wmissing-declarations -Wnonnull \
-Wundef -funsigned-char -fno-builtin -fno-asm -std=gnu99 -ffunction-sections 
-fdata-sections \
-m32 -fno-stack-protector -nostdinc -I./include -I. -I./libc/sysdeps/linux/i386 
-DUCLIBC_INTERNAL \
\
-O0 \
\
-g3 -I./libpthread/linuxthreads.old/sysdeps/unix/sysv/linux/i386 \
-I./libpthread/linuxthreads.old/sysdeps/i386 
-I./libpthread/linuxthreads.old/sysdeps/unix/sysv/linux \
-I./libpthread/linuxthreads.old/sysdeps/pthread -I./libpthread/linuxthreads.old 
\
-I./libpthread -I/usr/include/ \
-isystem 
/.share/usr/app/gcc-4.2.1/bin/../lib/gcc/i386-pc-linux-gnu/4.2.1/include-fixed \
-isystem 
/.share/usr/app/gcc-4.2.1/bin/../lib/gcc/i386-pc-linux-gnu/4.2.1/include 
-DNDEBUG \
-fPIC -MT libc/stdio/_fwrite.os -MD -MP -MF libc/stdio/._fwrite.os.dep


-O0 is the problem, gcc becomes much dumber.

Please try attached patch. For me it compiles. Resulting code
from memchr(buffer, '\n', pending):

...
 132:   c7 45 e8 0a 00 00 00    movl   $0xa,-0x18(%ebp)  <=== !
 139:   8b 45 dc                mov    -0x24(%ebp),%eax
 13c:   89 45 e4                mov    %eax,-0x1c(%ebp)
 13f:   8b 7d ec                mov    -0x14(%ebp),%edi
 142:   8b 45 e8                mov    -0x18(%ebp),%eax  <=== wow!
 145:   8b 4d e4                mov    -0x1c(%ebp),%ecx
 148:   e3 07                   jecxz  151 <__stdio_fwrite+0x151>
 14a:   f2 ae                   repnz scas %es:(%edi),%al
 14c:   8d 7f ff                lea    -0x1(%edi),%edi
 14f:   74 02                   je     153 <__stdio_fwrite+0x153>
 151:   31 ff                   xor    %edi,%edi
...

-- 
vda

diff -d -urpN uClibc.6/libc/string/i386/string.h uClibc.7/libc/string/i386/string.h
--- uClibc.6/libc/string/i386/string.h	2009-07-20 21:53:21.000000000 +0200
+++ uClibc.7/libc/string/i386/string.h	2009-07-21 00:36:37.000000000 +0200
@@ -288,6 +288,7 @@ void *inlined_memchr(const void *s, int 
 static __always_inline
 void *inlined_memchr_const_c(const void *s, int c, size_t count)
 {
+#if defined __OPTIMIZE__
 	void *edi;
 	int ecx, eax;
 	__asm__ __volatile__(
@@ -304,6 +305,27 @@ void *inlined_memchr_const_c(const void 
 		/* : no clobbers */
 	);
 	return edi;
+#else
+	/* With -O0, gcc can't figure out how to encode CONST c
+	 * as an immediate operand. Generating slightly bigger code
+	 * (usually "movl CONST,%eax", 3 bytes bigger than needed):
+	 */
+	void *edi;
+	int ecx, eax;
+	__asm__ __volatile__(
+		"	jecxz	1f\n"
+		"	repne; scasb\n"
+		"	leal	-1(%%edi), %%edi\n"
+		"	je	2f\n"
+		"1:\n"
+		"	xorl	%%edi, %%edi\n"
+		"2:\n"
+		: "=&D" (edi), "=&c" (ecx), "=&a" (eax)
+		: "0" (s), "2" (c), "1" (count)
+		/* : no clobbers */
+	);
+	return edi;
+#endif
 }
 #if 1 /* +2 bytes on shared i386 build with gcc 4.3.0 */
 #define memchr(s, c, count) ( \
_______________________________________________
uClibc mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/uclibc

Reply via email to