Problems with egcs-1.0.1-/gcc-2.8.0-inline assembly [causes a kernel-oops in de4x5-driver]
Franz Sirl
Franz.Sirl-kernel@lauterbach.com
Mon Jan 19 09:27:00 GMT 1998
This is probably due to a bug in the string macros of Linux, see
< http://linuxwww.db.erau.edu/mail_archives/linux-kernel/Jan_98/2155.html >
for patches and
< http://linuxwww.db.erau.edu/mail_archives/linux-kernel/Jan_98/2151.html >
for an explanation.
How about an entry for the FAQ?
Bye,
Franz.
At 16:28 19.01.98 , Bernd Nottelmann wrote:
>Hi,
>
>consider the following C-program (a very very simplified version
>of de4x5.c :-):
>
>-----------------------snip-----------------------
>
>
>
>extern inline char * strstr(const char * cs,const char * ct)
>{
>register char * __res;
>__asm__ __volatile__(
> "cld\n\t" \
> "movl %4,%%edi\n\t"
> "repne\n\t"
> "scasb\n\t"
> "notl %%ecx\n\t"
> "decl %%ecx\n\t" /* NOTE! This also sets Z if searchstring='' */
> "movl %%ecx,%%edx\n"
> "1:\tmovl %4,%%edi\n\t"
> "movl %%esi,%%eax\n\t"
> "movl %%edx,%%ecx\n\t"
> "repe\n\t" /* <- SEGMENTATION FAULT HERE */
> "cmpsb\n\t"
> "je 2f\n\t" /* also works for empty string, see above */
> "xchgl %%eax,%%esi\n\t"
> "incl %%esi\n\t"
> "cmpb $0,-1(%%eax)\n\t"
> "jne 1b\n\t"
> "xorl %%eax,%%eax\n\t"
> "2:"
> :"=a" (__res):"0" (0),"c" (0xffffffff),"S" (cs),"g" (ct)
> :"cx","dx","di","si");
>return __res;
>}
>
>#include <stdio.h>
>
>main() {
> int i, siglen;
> char ManCode[8];
> const char *signatures[]={"DE425","DE434","DE435","DE450","DE500"};
> siglen = sizeof(signatures)/sizeof(const char *);
> ManCode[0]='_'; ManCode[1]='_';
> ManCode[2]='?'; ManCode[3]='?'; ManCode[5]='?';
> ManCode[6]='\0';
>
> for (i=0;i<siglen;i++)
> if (strstr(ManCode, signatures[i]) != NULL)
> printf("Found\n");
> else
> printf("Not found\n");
>}
>
>-----------------------snip-----------------------
>
>Compiled with
>gcc strtst.c -o strtst
>it runs without any error messages:
>
># ./strtst
>Not found
>Not found
>Not found
>Not found
>Not found
>
>but when I compile it with -O and higher optimizations
>it gives a seg fault (it occurs in the assembler line with
>the corresponding comment).
>My egcs has been only build from the gcc-subtree
>I hope I have given enough information to you.
>
>Bernd
>
> .file "strtst.c"
> .version "01.01"
>/ GNU C version egcs-2.90.23 980102 (egcs-1.0.1 release)
(i686-pc-linux-gnulibc1) compiled by GNU C version egcs-2.90.23 980102
(egcs-1.0.1 release).
>/ options passed:
>/ options enabled: -fpeephole -ffunction-cse -fkeep-static-consts
>/ -fpcc-struct-return -fsched-interblock -fsched-spec -fcommon
>/ -fverbose-asm -fgnu-linker -fargument-alias -m80387 -mhard-float
>/ -mno-soft-float -mieee-fp -mfp-ret-in-387 -mschedule-prologue
>/ -mcpu=pentiumpro -march=pentium
>
>gcc2_compiled.:
>.section .rodata
>.LC0:
> .string "DE425"
>.LC1:
> .string "DE434"
>.LC2:
> .string "DE435"
>.LC3:
> .string "DE450"
>.LC4:
> .string "DE500"
>.LC5:
> .string "Found\n"
>.LC6:
> .string "Not found\n"
>.text
> .align 4
>.globl main
> .type main,@function
>main:
> pushl %ebp
> movl %esp,%ebp
> subl $36,%esp
> leal -36(%ebp),%eax
> movl $.LC0,-36(%ebp)
> movl $.LC1,-32(%ebp)
> movl $.LC2,-28(%ebp)
> movl $.LC3,-24(%ebp)
> movl $.LC4,-20(%ebp)
> movl $5,-8(%ebp)
> movb $95,-16(%ebp)
> movb $95,-15(%ebp)
> movb $63,-15(%ebp)
> movb $63,-15(%ebp)
> movb $63,-15(%ebp)
> movb $0,-10(%ebp)
> movl $0,-4(%ebp)
>.L3:
> movl -4(%ebp),%eax
> cmpl %eax,-8(%ebp)
> jg .L6
> jmp .L4
> .align 4
>.L6:
> movl -4(%ebp),%eax
> movl %eax,%edx
> leal 0(,%edx,4),%eax
> leal -36(%ebp),%edx
> movl (%eax,%edx),%eax
> pushl %eax
> leal -16(%ebp),%eax
> pushl %eax
> call strstr
> addl $8,%esp
> movl %eax,%eax
> testl %eax,%eax
> je .L7
> pushl $.LC5
> call printf
> addl $4,%esp
> jmp .L5
> .align 4
>.L7:
> pushl $.LC6
> call printf
> addl $4,%esp
>.L8:
>.L5:
> incl -4(%ebp)
> jmp .L3
> .align 4
>.L4:
>.L2:
> movl %ebp,%esp
> popl %ebp
> ret
>.Lfe1:
> .size main,.Lfe1-main
> .ident "GCC: (GNU) egcs-2.90.23 980102 (egcs-1.0.1 release)"
> .file "strtst.c"
> .version "01.01"
>/ GNU C version egcs-2.90.23 980102 (egcs-1.0.1 release)
(i686-pc-linux-gnulibc1) compiled by GNU C version egcs-2.90.23 980102
(egcs-1.0.1 release).
>/ options passed: -O
>/ options enabled: -fdefer-pop -fthread-jumps -fpeephole -ffunction-cse
>/ -finline -fkeep-static-consts -fpcc-struct-return -fsched-interblock
>/ -fsched-spec -fcommon -fverbose-asm -fgnu-linker -falias-check
>/ -fargument-alias -m80387 -mhard-float -mno-soft-float -mieee-fp
>/ -mfp-ret-in-387 -mschedule-prologue -mcpu=pentiumpro -march=pentium
>
>gcc2_compiled.:
>.section .rodata
>.LC0:
> .string "DE425"
>.LC1:
> .string "DE434"
>.LC2:
> .string "DE435"
>.LC3:
> .string "DE450"
>.LC4:
> .string "DE500"
>.LC5:
> .string "Found\n"
>.LC6:
> .string "Not found\n"
>.text
> .align 4
>.globl main
> .type main,@function
>main:
> pushl %ebp
> movl %esp,%ebp
> subl $40,%esp
> pushl %edi
> pushl %esi
> pushl %ebx
> movl $.LC0,-28(%ebp)
> movl $.LC1,-24(%ebp)
> movl $.LC2,-20(%ebp)
> movl $.LC3,-16(%ebp)
> movl $.LC4,-12(%ebp)
> movb $95,-8(%ebp)
> movb $63,-7(%ebp)
> movb $0,-2(%ebp)
> movl $0,-40(%ebp)
> leal -28(%ebp),%edx
> movl %edx,-32(%ebp)
> leal -8(%ebp),%ecx
> movl %ecx,-36(%ebp)
> .align 4
>.L6:
> xorl %eax,%eax
> movl $-1,%ecx
> movl -36(%ebp),%esi
> movl -40(%ebp),%edx
> movl -32(%ebp),%ebx
>#APP
> cld
> movl (%ebx,%edx,4),%edi
> repne
> scasb
> notl %ecx
> decl %ecx
> movl %ecx,%edx
>1: movl (%ebx,%edx,4),%edi
> movl %esi,%eax
> movl %edx,%ecx
> repe
> cmpsb
> je 2f
> xchgl %eax,%esi
> incl %esi
> cmpb $0,-1(%eax)
> jne 1b
> xorl %eax,%eax
> 2:
>#NO_APP
> testl %eax,%eax
> je .L7
> pushl $.LC5
> jmp .L11
> .align 4
>.L7:
> pushl $.LC6
>.L11:
> call printf
> addl $4,%esp
> incl -40(%ebp)
> cmpl $5,-40(%ebp)
> jl .L6
> leal -52(%ebp),%esp
> popl %ebx
> popl %esi
> popl %edi
> movl %ebp,%esp
> popl %ebp
> ret
>.Lfe1:
> .size main,.Lfe1-main
> .ident "GCC: (GNU) egcs-2.90.23 980102 (egcs-1.0.1 release)"
>
More information about the Gcc-bugs
mailing list