Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 16 Jun 1997 09:43:27 -0400 (EDT)
From:      guhl@mitre.org (George Uhl)
To:        babkin@hq.icb.chel.su
Cc:        hackers@freebsd.org
Subject:   Re: C optimizer bug ?
Message-ID:  <v02130501afcab1c0f1ba@[128.29.114.90]>

next in thread | raw e-mail | index | archive | help
Indeed, it was a bug in the code.

>Hmmm, deja vu all over again?  See the post below from Garrett; I also
>found a post from Thomas David Rivers who mentioned the possibility that
>automatic variables could have static extent when the code is compiled
>without optimization.  TDR suggested that perhaps the questionable code
>was saving the address of an auto and then trying to dereference it later.
>Works fine until you compile with optimization and the variable is
>actually constructed/destructed as control flows in and out of the block
>in which it is defined (i.e. local extent.)
>

Actually, it was a pointer problem.  Not that the pointer
referenced a bad address, but  rather I used the back
pointer of a linked list instead of the forward pointer.
The back pointer is actually a double pointer which ultimately
references the same address that the previous element's
forward pointer references (that is, the current element).
See the LIST macros in sys/queue.h for specifics.  I can't
remember why I used the back pointer in the first place, but
I was just beginning to change the FreeBSD kernel to support
the OSI (sigh) and X.25 protocol processing we use in our lab
and I just didn't know what I was doing at the time.

The strange thing about this bug, was that the code "appeared"
to work when the code was unoptimized.   With more exhaustive
testing the bug should have manifested itself in other ways.  The
difficult task was isolating the bug because the part of the kernel
that was crashing did not pinpoint the bug's location.  I found it
where I didn't expect it to be. When the obvious fails only the
unobvious remains!

>caveat: I do not know exactly how gcc behaves in this regard; it just
>seemed like the two threads might be concerned with the same phenomenon.
>
>-Chris
>

You might want to examine your code again.

>(from the archives...)
>
>Date:      Tue, 11 Feb 1997 15:22:52 -0500
>From:      Garrett Wollman <wollman@lcs.mit.edu>
>To:        guhl@mitre.org (George Uhl)
>Cc:        freebsd-hackers@FreeBSD.ORG, freebsd-bugs@FreeBSD.ORG
>Sender:    owner-hackers@FreeBSD.ORG
>Subject:   Fix to Interrupt/Terminate Signal causes page fault in kernel
>mode
>
><<On Tue, 11 Feb 1997 14:09:16 -0500, guhl@mitre.org (George Uhl) said:
>
>> I posted the following to freebsd-hackers and freebsd-bugs a couple
>> of days ago.   I have fixed the problem, not by making any code
>> changes, but by compiling the kernel unoptimized!
>
>Your code is almost certainly broken.  It probably has automatic
>variable initialization problems.
>
>-GAWollman

George Uhl
email: <guhl@mitre.org>
phone: 703-883-7305

The MITRE Corporation
1820 Dolley Madison Blvd.
McLean, VA. 22102






Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?v02130501afcab1c0f1ba>