[cfe-dev] Inline function static variable linkage visibility issue

Rick Taylor rick at tropicalstormsoftware.com
Tue Nov 9 03:06:17 PST 2010


Here is a repost of the problem, this time in plain text....

Hi All,

I have found an inconsistency between gcc and clang's handling of the linkage of static variables in visibility(hidden) member functions, when linked as shared objects.

A quick worked example:

/////////////////////////////////
/////// foo.cpp
class Foo
{
public:
	static const int* Bar()
	{
		const static int _bar[] = { 1,2,3,4 };
		return _bar;
	}
};

void __attribute__((visibility("default"))) external_fn()
{
	const int* i = Foo::Bar();
}

//////////////////////////////////////


And the output from nm:

$ clang++ -fvisibility=hidden -c foo.cpp
$ clang++ -shared -fvisibility=hidden foo.o -o foo
$ nm -D -C foo
         w _Jv_RegisterClasses
00000480 T external_fn()
00000504 V Foo::Bar()::_bar       <-- THIS IS THE PROBLEM
0000200c A __bss_start
         w __cxa_finalize
         w __gmon_start__
0000200c A _edata
00002014 A _end
000004e8 T _fini
00000358 T _init

$ g++ -fvisibility=hidden -c foo.cpp
$ g++ -shared -fvisibility=hidden foo.o -o foo.g
$ nm -D -C foo.g
         w _Jv_RegisterClasses
0000049c T external_fn()
0000200c A __bss_start
         w __cxa_finalize
         w __gmon_start__
         U __gxx_personality_v0
0000200c A _edata
00002014 A _end
000004f8 T _fini
00000380 T _init

///////////////////////////////////////////

As you can see the data member _bar is being exported in the symbol table with Vague linkage...




More information about the cfe-dev mailing list