This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: mudflap problem
- From: "Doug Graham" <dgraham at nortelnetworks dot com>
- To: gcc at gcc dot gnu dot org
- Date: Tue, 5 Oct 2004 19:32:57 -0400
- Subject: Re: mudflap problem
- References: <4159BBC2.8010504@home.nl> <y0mmzzagl06.fsf@toenail.toronto.redhat.com> <20040929205648.GT4804@nortelnetworks.com> <y0m655whgsb.fsf@toenail.toronto.redhat.com> <20040929225040.GU4804@nortelnetworks.com>
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.