This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [C++] GCC tree linkage types


Chris Lattner <sabre@nondot.org> writes:

> > But the uses of common symbols and linkonce symbols are quite
> > different.  In practice, a linkonce symbol always has a non-zero
> > initializer.  By definition, a common symbol always has a zero
> > initializer.  The linker normally simply uses the first definition of
> > a linkonce symbol, and discards subsequent ones; is there a benefit to
> > choosing the largest one?
> 
> A linkonce symbol doesn't always have a non-zero initializer.  For
> example, in C++:
> 
> inline int foo(int X) {
>   static int linkoncevar = 0;
>   return linkoncevar += X;
> }
> 
> linkoncevar should have common or linkonce linkage, because it's in an
> inline function which may be included into multiple translation units, but
> the initializer could have an arbitrary value.

Ah, right.

> The next question is, what representation should the GCC front-end use?
> Is there any way to reduce the mish-mash of flags used to a minimum, or at
> least document what the semantics of various globals are with different
> flag combinations?

Well, gcc needs to support at least these types of symbols by
adjusting the assembler output in one way or another:

* global
* local (i.e., file static)
* common
* alias
* weak defined
* weak undefined
* linkonce
* constructor/destructor

Also gcc needs to support extern inline symbols and external
references (i.e., undefined symbols--some targets need
assemble_external() to be called in this case).

Related to the above, gcc needs to know what section to put the
symbols into: text, data, read-only, bss, or user-specified.

Right now I think a global symbol is TREE_PUBLIC, a local symbol is
not TREE_PUBLIC, a common symbol is DECL_COMMON, an alias is
represented by an "alias" attribute in DECL_ATTRIBUTES, a weak defined
symbol is DECL_WEAK, a weak undefined symbol is DECL_WEAK with no
definition, a linkonce symbol is DECL_ONE_ONLY, a
constructor/destructor is DECL_STATIC_CONSTRUCTOR or
DECL_STATIC_DESTRUCTOR.  An extern inline symbol is DECL_EXTERNAL, as
is an external reference.  But I could be wrong on any of these.

It's certainly fairly confusing.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]