Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 8 Dec 1998 14:03:51 +0100
From:      Eivind Eklund <eivind@yes.no>
To:        Greg Lehey <grog@lemis.com>, jobaldwi@vt.edu, freebsd-chat@FreeBSD.ORG
Subject:   Re: gcc and dup variables...
Message-ID:  <19981208140351.A13839@follo.net>
In-Reply-To: <19981208150459.Q12688@freebie.lemis.com>; from Greg Lehey on Tue, Dec 08, 1998 at 03:04:59PM %2B1030
References:  <XFMail.981207232041.jobaldwi@vt.edu> <19981208150459.Q12688@freebie.lemis.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Dec 08, 1998 at 03:04:59PM +1030, Greg Lehey wrote:
> > It seems that ld has merged these two references into the same
> > thing, 
> 
> This is a feature, not a bug.

Your feature - my bug.

I consider this a very long-standing bug in Unix ld.

> > with some rather interesting side effects when I tried to print the
> > string out after opening the file.
> 
> Indeed :-)
> 
> > I would've thought that I would have gotten a linker
> > error for duplicate symbols of conflicting types, but I guess that ld treats
> > all pointers the same as it doesn't know types?  But, I also thought that if
> > two modules both had non-external vars of the same name ld should've flagged
> > that instead of silently merging the two.  So a) is this how ld is supposed to
> > work 
> 
> Yes.

No.

5 An external definition is an external declaration that is also a definition of a function
or an object.  If an identifier declared with external linkage is used in an expression
(other than as part of the operand of a sizeof operator), somewhere in the entire
program there shall be exactly one external definition for the identifier; otherwise,
there shall be no more than one.117

Section 6.7.5 of the draft standard (I don't have the original handy;
the text for this part is just about identical).

> > and b) if so, why?
> 
> Because nobody ever got round to defining arbitrary types for the C
> linker.

Beep!  Operator error - please try again at another time.  This has
been done at various times by various parties.  I believe one example
of such a definition is contained in a standard for something called
'ELF'.

> > I can see how if one was two lazy to declare variables extern
> > everywhere but once that this would be helpful, but I'd rather ld
> > give me a link error as it can lead to some interesting bugs.
> 
> This is one of the reasons why people like Bruce snoop around and put
> 'static' in front of every variable which will take it.

I believe I took care all of 'em last week, except for the ones in
CAM, which I just bounced to Justin.  You should expect a commit Real
Soon Now.

Eivind.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-chat" in the body of the message



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