anonymous namespaces and local versus global symbol

Simon Richter Simon.Richter@hogyros.de
Wed Nov 25 10:00:32 GMT 2020


Hi Tom,

On Tue, Nov 24, 2020 at 09:18:46AM -0500, Tom Kacvinsky via Binutils wrote:

> I have a C++ method wrapped in a namespace.  What I have noticed is if
> there is an anonymous namespace wrapped around the function, the mangled
> name of the function
> show as a local symbol when running nm on the shared library I produced.

I believe that is by design. Objects in anonymous namespaces are only
visible in the current translation unit, and may not conflict even if the
same source file is compiled twice (e.g. with different preprocessor
flags), so gcc makes them local.

Symbol visibility doesn't change anything here, as it only applies to
symbols that are otherwise global.

   Simon


More information about the Binutils mailing list