mudflap problem
Doug Graham
dgraham@nortelnetworks.com
Wed Oct 6 10:15:00 GMT 2004
On Wed, Sep 29, 2004 at 06:50:40PM -0400, Graham, Doug [CAR:QT96:EXCH] wrote:
> On Wed, Sep 29, 2004 at 06:05:56PM -0400, Frank Ch. Eigler wrote:
> >
> > > I thought that since b+16 points to the base of a, mudflap would not
> > > complain about the dereference in foo(). But it did somehow know that
> > > the pointer passed in to foo() was derived from 'b' rather than 'a'.
> >
> > I believe this is an optimization artifact. With "-O2", the declaration of
> > "a" is marked somehow as unused (it is), and libmudflap does not get
> > a startup-time registration call for it. Thus b[16] is checked and is found
> > to refer to an invalid address.
>
> Aha! You're right, only 'b' is passed to __mf_register. This happened
> without -O2; my compile line was just: gcc -fmudflap -o foo foo.c.
Hey wait a minute. Isn't this a bug? a[16] has external linkage,
so mudflap can't know that it isn't going to be accessed from some
other compilation unit. When I add a second source file that
does this:
extern int a[];
void baz() { a[0] = 42; }
mudflap complains during compilation of this new module that it can't
track the lifetime of `a', and then complains at runtime when legal
accesses to a[] are made. I'm not sure what the compilation warning
is all about, as a[]'s lifetime is obviously the lifetime of the program,
but the runtime warning occurs because a[] wasn't registered.
--Doug.
More information about the Gcc
mailing list