<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 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
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;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
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=MsoNormal>Hi,<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I am experimenting with an inline strategy wherein I postpone inlining to link time rather than inlining at compile time, but I am facing runtime failure and wonder if anyone else saw this.<o:p></o:p></p><p class=MsoNormal>Here is my sample test case:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>$ cat test.cpp<o:p></o:p></p><p class=MsoNormal>#include <sstream><o:p></o:p></p><p class=MsoNormal>int main() {<o:p></o:p></p><p class=MsoNormal> std::stringstream ss;<o:p></o:p></p><p class=MsoNormal> ss << "hello";<o:p></o:p></p><p class=MsoNormal> ss.str();<o:p></o:p></p><p class=MsoNormal>}<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>To test my inline strategy, I compile at O1 and use flto with gold plugin as below:<o:p></o:p></p><p class=MsoNormal>clang -O1 -flto -Wl,-fuse-ld=gold -static test.cpp –o test.exe<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>But the executable segfaults due to a weak undefined symbol:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Program received signal SIGSEGV, Segmentation fault.<o:p></o:p></p><p class=MsoNormal>0x00000000 in ?? ()<o:p></o:p></p><p class=MsoNormal>(gdb) bt<o:p></o:p></p><p class=MsoNormal>#0 0x00000000 in ?? ()<o:p></o:p></p><p class=MsoNormal>#1 0x000221e6 in std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::str() const ()<o:p></o:p></p><p class=MsoNormal>#2 0x00009020 in main ()<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>$ nm test.exe|grep _ZNSs12_S_constructIPcEES0_T_S1_RKSaIcESt20forward_iterator_tag<o:p></o:p></p><p class=MsoNormal> w _ZNSs12_S_constructIPcEES0_T_S1_RKSaIcESt20forward_iterator_tag<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Note that the symbol value is null for the symbol _ZNSs12_S_constructIPcEES0_T_S1_RKSaIcESt20forward_iterator_tag in the symbol table.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>However, when I compile at O3 and use flto with gold plugin, the linker is able to resolve the symbol correctly and there is no runtime failure:<o:p></o:p></p><p class=MsoNormal>clang –O3 -flto -Wl,-fuse-ld=gold -static test.cpp –o test.exe<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>$ nm test.exe|grep _ZNSs12_S_constructIPcEES0_T_S1_RKSaIcESt20forward_iterator_tag<o:p></o:p></p><p class=MsoNormal>00030139 W _ZNSs12_S_constructIPcEES0_T_S1_RKSaIcESt20forward_iterator_tag<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Has anyone seen this issue before? Could this be an issue with the gold linker? <o:p></o:p></p><p class=MsoNormal>Is it a bad design strategy to postpone inlining to link stage?<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Thanks,<o:p></o:p></p><p class=MsoNormal>Balaram<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>