Anonymous Namespaces

Zack Weinberg zack@codesourcery.com
Mon Feb 2 03:52:00 GMT 2004


Chris Lattner <sabre@nondot.org> writes:

> Ok, I will put this in GCC terms.  The "right" solution in my mind is to
> seperate the front-end notion of internal linkage from the back-end notion
> of internal linkage.  I am guessing this will not happen, so here is a
> proposal that I think would be acceptable to the GCC community.  Note that
> my knowledge of GCC is pretty limited (and I know nothing specifically
> about the C++ parser), so there are _likely_ to be technical problems with
> this decription.

I would be a bit more sanguine.  I think we can get agreement on a
change if you and Gabriel stop talking past each other.

In the rest of this email:

  "internal linkage" means exactly what the C++ standard defines it to
  mean.

  "local symbol" means a symbol that cannot be referenced from outside
  the object file that defines it.

It is clear from discussion to date that symbols defined in a C++
anonymous namespace do NOT have internal linkage.  However, in the
absence of 'export', I have not yet seen anyone assert that symbols
defined in an anonymous namespace are not local symbols.

In GCC's language-independent intermediate representation,
(TREE_PUBLIC(x) == false) means a local symbol.  The optimizers,
notably the inliner, rely on this to know when they can act.  Also,
local symbols are marked as such in the object file and the linker
acts on that.

In GCC's C++ front end, (TREE_PUBLIC(x) == false) means a symbol with
internal linkage.  This has implications for the meaning of the
program, but not for optimization.

It is wrong to conflate these two properties.  Symbols that should be
marked local in object files are not getting marked as such, leading
to use of get_file_function_name for inappropriate purposes (it's only
supposed to be used for obsolete object file formats that can't handle
proper .ctors sections).

The fix is to make the C++ front end not use (TREE_PUBLIC(x) == false)
to mean a symbol with internal linkage.  Instead, a language-specific
decl flag ought to be allocated to mean exactly 'internal linkage',
and all local symbols ought to get TREE_PUBLIC false.

zw



More information about the Gcc mailing list