<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<style>
<!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.MsoPlainText, li.MsoPlainText, div.MsoPlainText
{mso-style-priority:99;
mso-style-link:"Plain Text Char";
margin:0cm;
margin-bottom:.0001pt;
font-size:10.5pt;
font-family:Consolas;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
span.PlainTextChar
{mso-style-name:"Plain Text Char";
mso-style-priority:99;
mso-style-link:"Plain Text";
font-family:Consolas;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=WordSection1>
<p class=MsoPlainText>Hi All,<o:p></o:p></p>
<p class=MsoPlainText><o:p> </o:p></p>
<p class=MsoPlainText>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.<o:p></o:p></p>
<p class=MsoPlainText><o:p> </o:p></p>
<p class=MsoPlainText>A quick worked example:<o:p></o:p></p>
<p class=MsoPlainText><o:p> </o:p></p>
<p class=MsoPlainText>/////////////////////////////////<o:p></o:p></p>
<p class=MsoPlainText>/////// foo.cpp<o:p></o:p></p>
<p class=MsoPlainText>class Foo<o:p></o:p></p>
<p class=MsoPlainText>{<o:p></o:p></p>
<p class=MsoPlainText>public:<o:p></o:p></p>
<p class=MsoPlainText> static const int* Bar()<o:p></o:p></p>
<p class=MsoPlainText> {<o:p></o:p></p>
<p class=MsoPlainText> const static int _bar[] = { 1,2,3,4 };<o:p></o:p></p>
<p class=MsoPlainText> return _bar;<o:p></o:p></p>
<p class=MsoPlainText> }<o:p></o:p></p>
<p class=MsoPlainText>};<o:p></o:p></p>
<p class=MsoPlainText><o:p> </o:p></p>
<p class=MsoPlainText>void __attribute__((visibility("default")))
external_fn() {<o:p></o:p></p>
<p class=MsoPlainText> const int* i = Foo::Bar();<o:p></o:p></p>
<p class=MsoPlainText>}<o:p></o:p></p>
<p class=MsoPlainText><o:p> </o:p></p>
<p class=MsoPlainText>//////////////////////////////////////<o:p></o:p></p>
<p class=MsoPlainText><o:p> </o:p></p>
<p class=MsoPlainText><o:p> </o:p></p>
<p class=MsoPlainText>And the output from nm:<o:p></o:p></p>
<p class=MsoPlainText><o:p> </o:p></p>
<p class=MsoPlainText>$ clang++ -fvisibility=hidden -c foo.cpp $ clang++
-shared -fvisibility=hidden foo.o -o foo $ nm -D -C foo<o:p></o:p></p>
<p class=MsoPlainText> w _Jv_RegisterClasses<o:p></o:p></p>
<p class=MsoPlainText>00000480 T external_fn()<o:p></o:p></p>
<p class=MsoPlainText>00000504 V Foo::Bar()::_bar <-- THIS IS THE
PROBLEM<o:p></o:p></p>
<p class=MsoPlainText>0000200c A __bss_start<o:p></o:p></p>
<p class=MsoPlainText> w __cxa_finalize<o:p></o:p></p>
<p class=MsoPlainText> w __gmon_start__<o:p></o:p></p>
<p class=MsoPlainText>0000200c A _edata<o:p></o:p></p>
<p class=MsoPlainText>00002014 A _end<o:p></o:p></p>
<p class=MsoPlainText>000004e8 T _fini<o:p></o:p></p>
<p class=MsoPlainText>00000358 T _init<o:p></o:p></p>
<p class=MsoPlainText><o:p> </o:p></p>
<p class=MsoPlainText>$ g++ -fvisibility=hidden -c foo.cpp<o:p></o:p></p>
<p class=MsoPlainText>$ g++ -shared -fvisibility=hidden foo.o -o foo.g $ nm -D
-C foo.g<o:p></o:p></p>
<p class=MsoPlainText> w _Jv_RegisterClasses<o:p></o:p></p>
<p class=MsoPlainText>0000049c T external_fn()<o:p></o:p></p>
<p class=MsoPlainText>0000200c A __bss_start<o:p></o:p></p>
<p class=MsoPlainText> w __cxa_finalize<o:p></o:p></p>
<p class=MsoPlainText> w __gmon_start__<o:p></o:p></p>
<p class=MsoPlainText> U __gxx_personality_v0<o:p></o:p></p>
<p class=MsoPlainText>0000200c A _edata<o:p></o:p></p>
<p class=MsoPlainText>00002014 A _end<o:p></o:p></p>
<p class=MsoPlainText>000004f8 T _fini<o:p></o:p></p>
<p class=MsoPlainText>00000380 T _init<o:p></o:p></p>
<p class=MsoPlainText><o:p> </o:p></p>
<p class=MsoPlainText>Now I am not sure which is correct (I know there is some
complex logic involved in inline member function static variables) but I am
relying on the gcc linkage for the plugin layer of my project.<o:p></o:p></p>
<p class=MsoPlainText><o:p> </o:p></p>
<p class=MsoPlainText>I have tried library sprinkling my code with
__attribute__((visibility("hidden"))) on each of the static variable
declarations, but that appears to make no difference, and is not required by
gcc either.<o:p></o:p></p>
<p class=MsoPlainText><o:p> </o:p></p>
<p class=MsoPlainText>Can someone more familiar with the clang codebase confirm
this as a bug or my stupidity please?<o:p></o:p></p>
<p class=MsoPlainText><o:p> </o:p></p>
<p class=MsoPlainText>Many thanks<o:p></o:p></p>
<p class=MsoPlainText><o:p> </o:p></p>
<p class=MsoPlainText>Rick Taylor<o:p></o:p></p>
<p class=MsoNormal><o:p> </o:p></p>
</div>
</body>
</html>