On Tue, 24 Nov 2020 at 19:11, Kacvinsky, Tom via Gcc-help <gcc-help@xxxxxxxxxxx> wrote: > > 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. Why do you want to change it? G++ is doing the right thing. What are you trying to achieve?