tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: gcc 3.3.3 is doing stupid shit



David Holland wrote:
On Sun, Feb 10, 2008 at 09:31:31AM +1100, Darren Reed wrote:
 > Can anyone explain why gcc is doing what it is below?
> > [...]
 > (gdb) print hlen
 > $1 = 4448

Does slen (set to l3len - hlen) come out correct? Given that it's
inlined htons, I'm assuming you compiled with a nontrivial -O level,
so it shouldn't be surprising either that it optimized out a local
variable or that the debug info gives you misleading results which may
or may not reflect what's actually happening.

A better example of how it is not getting things right:

Breakpoint 1, fr_cksum (m=0xbfbfc650, ip=0xbfbfc660, l4proto=17,
    l4hdr=0xbfbfc660, l3len=24) at ../../fil.c:3274
warning: Source file is more recent than executable.

3274            csump = NULL;
(gdb) s
3275            sumsave = 0;
(gdb)
3277            sp = NULL;
(gdb)
3278            slen = 0;
(gdb)
68              __asm __volatile ("rorw $8, %w1" : "=r" (x) : "0" (x));
(gdb)
67      {
(gdb)
3287            if (IP_V(ip) == 4) {
(gdb)
3298            } else if (IP_V(ip) == 6) {
(gdb)
3299                    ip6 = (ip6_t *)ip;
(gdb)
3301                    slen = l3len - hlen;
(gdb)
68              __asm __volatile ("rorw $8, %w1" : "=r" (x) : "0" (x));
(gdb) p l3len
$1 = 24
(gdb) p hlen
$2 = 4448
(gdb) p slen
$3 = 65520

Both the initialisation of hlen to 0 and assigning it 40 are missing.

Darren



Home | Main Index | Thread Index | Old Index