From RISKS: secret scrubbing code removed by optimizers

Gary E. Miller gem at rellim.com
Fri Nov 8 17:08:24 EST 2002


Yo All!

On Fri, 8 Nov 2002, Darren Tucker wrote:

> Dan Kaminsky wrote:
> >     Has somebody actually verified this optimizing behavior in any build
> > of GCC?  Does voliatile actually stop it?
>
> Yes (gcc-3.2 on a SPARC). Yes.

Same test on gcc 3.2 and gcc 2.95.2 with i686-linux.

I can not get memset() to optimize away.  Maybe with other switches it will.

Normal compile, gcc 3.2:

gcc -S  testfunc.c

myfunc1:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $136, %esp
        movl    $.LC0, (%esp)
        leal    -120(%ebp), %eax
        movl    %eax, 4(%esp)
        call    scanf
        leal    -120(%ebp), %eax
        movl    %eax, (%esp)
        movl    $0, 4(%esp)
        movl    $100, 8(%esp)
        call    memset
        leave
        ret

gcc -S -O1  testfunc.c
myfunc1:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $136, %esp
        movl    %edi, -4(%ebp)
        movl    $.LC0, (%esp)
        leal    -120(%ebp), %edi
        movl    %edi, 4(%esp)
        call    scanf
        cld
        movl    $25, %ecx
        movl    $0, %eax
        rep
        stosl
        movl    -4(%ebp), %edi
        movl    %ebp, %esp
        popl    %ebp
        ret

gcc -S -O2 testfunc.c
and
gcc -S -O3 testfunc.c

myfunc1:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $136, %esp
        movl    %edi, -4(%ebp)
        leal    -120(%ebp), %edi
        movl    %edi, 4(%esp)
        movl    $.LC0, (%esp)
        call    scanf
        xorl    %eax, %eax
        movl    $25, %ecx
        cld
        rep
        stosl
        movl    -4(%ebp), %edi
        movl    %ebp, %esp
        popl    %ebp
        ret

Similar results w/ gcc 2.95.3



RGDS
GARY
---------------------------------------------------------------------------
Gary E. Miller Rellim 20340 Empire Blvd, Suite E-3, Bend, OR 97701
	gem at rellim.com  Tel:+1(541)382-8588 Fax: +1(541)382-8676





More information about the openssh-unix-dev mailing list