From: "Kacvinsky, Tom" <Tom.Kacvinsky@vector.com>
To: "gcc-help@gcc.gnu.org" <gcc-help@gcc.gnu.org>
Subject: Anonymous namespaces and global vs.local symbols in nm output
Date: Tue, 24 Nov 2020 19:02:45 +0000 [thread overview]
Message-ID: <60df078038824a71bd34e65773e770b8@vector.com> (raw)
This code
#include <string>
#include <istream>
#include <iostream>
#include <vector>
typedef std::vector<unsigned char> Signature;
namespace foo {
bool bar (const std::string& input,
const Signature& signature,
std::istream& key)
{
return true;
}
}
when compiled with
g++ -fPIC -o global_noans.so -shared -static-libgcc -static-libstdc++ -Wl,-h,global.so -fuse-ld=gold global_noans.cpp
produces this nm output
0000000000082745 T _ZN3foo3barERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIhSaIhEERSi
Notice how it is a global symbol?
On the other hand, this code#include <string>
#include <istream>
#include <iostream>
#include <vector>
typedef std::vector<unsigned char> Signature;
namespace foo {
namespace {
bool bar(const std::string& input,
const Signature& signature,
std::istream& key)
{
return true;
}
}
}
when compiled with
g++ -fPIC -o global.so -shared -static-libgcc -static-libstdc++ -Wl,-h,global.so -fuse-ld=gold global.cpp
produces this nm output
00000000000826b5 t _ZN3foo12_GLOBAL__N_13barERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERKSt6vectorIhSaIhEERSi
And now we note the symbolis local. I tried building the shared library with a -Wl,--version-script=global.map, where global.map
is set up to make the symbol glocal instead of local, and that did not work. I also tried compiling the source code with
void __attribute__ ((visibility ("default")))
but that made no difference, either, in the anonymous namespace symbol being lobal. I have pinged the binutils list and they said
this might be a g++ version issue (I am using GCC 8.3.0 with binutils 2.34, gold linker). If this is a g++ issues, I am assuming the issue
is anonymous name spaces make the symbol local, but if that isn't the cause, I'll got back to the binutils folks. I am also going to try
a later version of GCC and binutils.
Thanks,
TOm
next reply other threads:[~2020-11-24 19:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-24 19:02 Kacvinsky, Tom [this message]
2020-11-24 19:23 ` Xi Ruoyao
2020-11-24 20:03 ` Jonathan Wakely
2020-11-25 1:28 ` Kacvinsky, Tom
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=60df078038824a71bd34e65773e770b8@vector.com \
--to=tom.kacvinsky@vector.com \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).