This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [C++] GCC tree linkage types
- From: Chris Lattner <sabre at nondot dot org>
- To: Ian Lance Taylor <ian at wasabisystems dot com>
- Cc: Matt Austern <austern at apple dot com>, <gcc at gcc dot gnu dot org>,Gabriel Dos Reis <gdr at integrable-solutions dot net>,Richard Henderson <rth at redhat dot com>
- Date: Thu, 6 Nov 2003 23:17:47 -0600 (CST)
- Subject: Re: [C++] GCC tree linkage types
On 6 Nov 2003, Ian Lance Taylor wrote:
> Chris Lattner <sabre@nondot.org> writes:
> > In LLVM, we currently have the following linkage types:
> >
> > * internal linkage (ie, static)
> > * linkonce (globals which merge when linking, but can be deleted from a
> > translation unit if they are not used, basically like 'extern inline').
>
> I would normally say that linkonce means that all but one copy can be
> deleted.
Exactly, but what about the last copy? If it is unreferenced, can it be
deleted? In LLVM, linkonce is used for things like vtables and extern
inline functions. These things are guaranteed to be emitted in each
translation unit that uses them, so it is ok for the optimizer to delete
any copy that is not locally used. The front-ends already have a notion
of this: if a logically "linkonce" global is not used, RTL code is not
even generated for it.
The distinction between linkonce and weak is much more important for
link-time optimizations than it is for a compiler like GCC, though the
compiler server and Apple IPO projects could definately use it.
> It may be that the way gcc uses linkonce ensures that it is OK to delete
> all copies, but it is logically possible to make a global constructor
> linkonce, and it would not be OK to delete that even if nothing referred
> to it.
If there is something using the global, it will not be deleted. Though
they are not explicitly used in GCC, they are in LLVM, so global ctors
will not be deleted if they are used. Also, the 'linkonce' linkage I
described above is not the same as any existing GCC linkage type that I
know of: it is the same as some wierd combination of GCC linkage types,
which I have not yet nailed down. :(
> > * weak (like linkonce, but cannot be deleted if they are unused in a
> > xlation unit)
>
> I wouldn't say that weak symbols merge; I would say that weak symbols
> are hidden by strong symbols, or by earlier weak symbols.
In a compiler where you can _physically delete_ globals, the definitions
are the same: "hiding" is the same as deleting one copy.
> > * external (normal strong, externally visible symbol)
> >
> > Is there anything wrong with this classification of linkage types? Is
> > there something we are missing?
>
> You didn't mention common symbols, which really do merge. Even g++
> can generate common symbols when using the -fconserve-space option.
What is the difference between common symbols, and either weak or linkonce
symbols, as defined above?
> The GNU linker supports more exotic linkage types like `indirect',
> `warning', and `set'. But these are probably not of interest to the
> compiler.
True. What do these linkage types do? Are they documented somewhere? A
google search didn't turn up anything obvious.
-Chris
--
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/