Re: pgcc and the kernel.. is this a fix? (nope.. chuckle)

Michael L. Galbraith (mikeg@weiden.de)
Thu, 14 Aug 1997 17:47:10 +0200 (MET DST)


Answering my own question :-/

Not only no, but heeeeeell no! (grin :) should have looked past the stack
setup to the inlined function I totally demolished.

> Changing constraints..
>
> - :"=c" (__res):"D" (s),"a" (0),"0" (0xffffffff):"di");
> + :"=r" (__res):"D" (s),"r" (0),"0" (0xffffffff):"di");
> return __res;
> }

For the benefit of others who are trying to break the gnu inline asm code,
the constraints apply to the entire __asm__ statement, and set up conditions
necessary for the body of the code to have a chance to work.

extern inline size_t strlen(const char * s)
{
register int __res;
__asm__ __volatile__(
"cld\n\t" /*
"repne\n\t"
"scasb\n\t"
"notl %0\n\t"
"decl %0"
:"=c" (__res):"D" (s),"a" (0),"0" (0xffffffff):"di");
return __res;
}

I _think_ that this is correct, but may be wrong. :"di" I haven't cracked yet.

movl $-1,%ecx / "0" (0xffffffff) constraint needed for repne
movl $.LC0,%edi / "D" (s) constraint needed for scasb
xorl %eax,%eax / "a" (0) constraint needed for scasb
#APP
cld / forward search direction
repne / loop the rest until cx==0 || ZF set
scasb / bytewise scan
notl %ecx / um.. er.. ones compliment it??
decl %ecx / decrement counter
#NO_APP
pushl %ecx / :"=c" (__res) constraint for the return

Changing the "=c" to "=r" and "a" to "r" says "just pick one gcc" which it does.
The resulting assembler output is um.. amusing.

Why doesn't pgcc like strlen?.. damned if I know. Maybe it really needs an
extra copy of eax on the stack. Further cryptographic analysis in progress.

This was a very educational day. I hope this helps some other poor sap along.

Now it's Miller(s) time by golly.

-Mike