Re: egcs 1.0.1 miscompiles Linux 2.0.33

Jeffrey A Law (law@cygnus.com)
Sun, 01 Mar 1998 13:29:39 -0700


In message <Pine.HPP.3.96.980227155318.28492P-100000@gra-ux1.iram.es>you write:
> #include <linux/string.h>
>
> int count_substring_matches(char **haystacks, char **needles)
> {
> int hits=0, i, j;
> for(i=0; haystacks[i]; i++) {
> for(j=0; needles[j]; j++) {
> if (strstr(haystacks[i], needles[j])) hits++;
> }
> }
> return hits;
> }
Thanks. In general, you're better off running testcases like this though
the compiler with "-save-temps" and sending the .i file. That way it
doesn't depend on whatever include files happen to be on my system.
Doing so also allows me to test it with a cross compiler from my
normal work machines instead of having to go to one of my linux
machines to create the .i file, then move it back to one of my normal
work machines.

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"
"movl %%ecx,%%edx\n"
"1:\tmovl %4,%%edi\n\t"
"movl %%esi,%%eax\n\t"
"movl %%edx,%%ecx\n\t"
"repe\n\t"
"cmpsb\n\t"
"je 2f\n\t"
"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;
}

This asm has some serious problems. Any attempt to fix the compiler
to be more strict with how it uses registers which are clobbered by
the asm is going to lead to problems.

Note that cx and si are mentioned in both the input and clobber
list. This is wrong. You've set up a case where the inputs
and clobbers must be in the same register. This can't work and
is just going to cause problems.

I'm not an x86 hacker, so it's not really clear to me how you
would rewrite that asm. But it's clearly going to need to be
rewritten. And until it is, I can't do much on the compiler
side as I don't have a valid testcase.

jeff

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu