<html><head></head><body><div>I've been quite busy lately and lost track on recent fixes.</div><div>Is there any progress on this or should I apply for bugzilla account and forward it there?</div><div><br></div><div>On Mon, 2017-04-17 at 11∶56 -0700, Reid Kleckner wrote:</div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><div dir="ltr">The __imp___cxa_begin_catch error seems related to this code in CodeGenModule::CreateRuntimeFunction:<div><div> if (!Local && getTriple().isOSBinFormatCOFF() &&</div><div> !getCodeGenOpts().LTOVisibilityPublicStd) {</div><div> const FunctionDecl *FD = GetRuntimeFunctionDecl(Context, Name);</div><div> if (!FD || FD->hasAttr<DLLImportAttr>()) {</div><div> F->setDLLStorageClass(llvm::GlobalValue::DLLImportStorageClass);</div><div> F->setLinkage(llvm::GlobalValue::ExternalLinkage);</div><div> }</div><div> }</div></div><div><br></div><div>This code assumes that all compiler-referenced runtime functions on COFF are dllimport, unless we happen to see a prototype for them during compilation that says otherwise. Saleem felt we shouldn't rely on the import thunks that the linker generates when you reference an imported function but forget to declare it as dllimport during compilation. It has some performance benefits, but it never really bothered me. Most users don't complain about the extra absolute branch imposed by the PLT on ELF, and those that do are getting -fno-plt soon.</div><div><br></div><div>Anyway, you can see the code difference easily here:</div><div><br></div><div><div>$ cat t.cpp</div><div>void g();</div><div>void f() {</div><div> try {</div><div> g();</div><div> } catch (...) {</div><div> }</div><div>}</div><div><br></div><div>$ clang -O1 -S t.cpp --target=x86_64-windows-gnu -o - | grep __cxa</div><div> callq *__imp___cxa_begin_catch(%rip)</div><div> rex64 jmpq *__imp___cxa_end_catch(%rip) # TAILCALL</div><div><br></div><div>$ gcc -O1 -S t.cpp -o - | grep __cxa</div><div> call __cxa_begin_catch</div><div> call __cxa_end_catch</div><div> .def __cxa_begin_catch; .scl 2; .type 32; .endef</div><div> .def __cxa_end_catch; .scl 2; .type 32; .endef</div></div><div><br></div><div>The other error looks like some kind of COMDAT disagreement between GCC and Clang that will require further investigation. It might relate to our choice to stop using ".text$function_name" for the section.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 17, 2017 at 11:06 AM, Mateusz Mikuła via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<p>Clang doesn't work very well with static libstdc++ build for
MinGW resulting in "multiple definition ..." or "undefined
reference" to the symbols.<br>
</p>
<p>Let's consider following code (removed includes and main for
readability):</p>
<ol>
<li>multiple definition:<br>
<br>
<div style="color:#d4d4d4;background-color:#1e1e1e;font-family:Consolas,'Courier New',monospace;font-weight:normal;font-size:14px;line-height:19px;white-space:pre-wrap"><div><span style="color:#d4d4d4"> std::string a = </span><span style="color:#ce9178">"a"</span><span style="color:#d4d4d4">;</span></div><div><span style="color:#d4d4d4"> std::string b = </span><span style="color:#ce9178">'@'</span><span style="color:#d4d4d4"> + a;</span></div></div>
<br>
This simple code build with `-static` flag will cause this
error:<br>
<br>
D:\msys64\mingw64\lib\gcc\x86_<wbr>64-w64-mingw32\6.3.0\libstdc++<wbr>.a(string-inst.o):(.text$_<wbr>ZStplIcSt11char_<wbr>traitsIcESaIcEENSt7__<wbr>cxx1112basic_stringIT_T0_T1_<wbr>EES5_RKS8_[_ZStplIcSt11char_<wbr>traitsIcESaIcEENSt7__<wbr>cxx1112basic_stringIT_T0_T1_<wbr>EES5_RKS8_]+0x0):
multiple definition of `std::__cxx11::basic_string<<wbr>char,
std::char_traits<char>, std::allocator<char> >
std::operator+<char, std::char_traits<char>,
std::allocator<char> >(char,
std::__cxx11::basic_string<<wbr>char,
std::char_traits<char>, std::allocator<char> >
const&)'<br>
D:\msys64\tmp\string-e39e30.o:<wbr>(.text[_ZStplIcSt11char_<wbr>traitsIcESaIcEENSt7__<wbr>cxx1112basic_stringIT_T0_T1_<wbr>EES5_RKS8_]+0x0):
first defined here<br>
clang++.exe: error: linker command failed with exit code 1 (use
-v to see invocation)<br>
<br>
</li>
<li>undefined reference<br>
<br>
<div style="color:#d4d4d4;background-color:#1e1e1e;font-family:Consolas,'Courier New',monospace;font-weight:normal;font-size:14px;line-height:19px;white-space:pre-wrap"><div><span style="color:#d4d4d4"> std::u16string b;</span></div></div>
<br>
This time adding `-static` to clang arguments will cause this
error (note: `__imp___cxa_call_unexpected` exists only in
dynamic libstdc++):<br>
<br>
D:\msys64\tmp\string-7062fd.o:<wbr>(.text[_ZNSt7__cxx1112basic_<wbr>stringIDsSt11char_<wbr>traitsIDsESaIDsEED2Ev]+0x4a):
undefined reference to `__imp___cxa_call_unexpected'<br>
D:\msys64\tmp\string-7062fd.o:<wbr>(.text[__clang_call_terminate]<wbr>+0x7):
undefined reference to `__imp___cxa_begin_catch'<br>
D:\msys64\tmp\string-7062fd.o:<wbr>(.text[_ZNSt7__cxx1112basic_<wbr>stringIDsSt11char_<wbr>traitsIDsESaIDsEE10_M_<wbr>destroyEy]+0x72):
undefined reference to `__imp___cxa_call_unexpected'<br>
clang++.exe: error: linker command failed with exit code 1 (use
-v to see invocation)<br>
<br>
</li>
</ol>
<p>It is probably related to the way the symbols are build into
static libstdc++ for MinGW.<br>
Let's take a look at weak symbol from different test cases:</p>
<ol>
<li>MinGW, dynamic libstdc++:<br>
0000000000000000 I
__imp__ZNSt7__cxx1112basic_<wbr>stringIcSt11char_<wbr>traitsIcESaIcEE12_M_<wbr>constructIPKcEEvT_S8_<wbr>St20forward_iterator_tag<br>
0000000000000000 T
_ZNSt7__cxx1112basic_<wbr>stringIcSt11char_<wbr>traitsIcESaIcEE12_M_<wbr>constructIPKcEEvT_S8_<wbr>St20forward_iterator_tag<br>
<br>
</li>
<li>MinGW, static libstdc++:<br>
0000000000000000 p
.pdata$_ZNSt7__cxx1112basic_<wbr>stringIcSt11char_<wbr>traitsIcESaIcEE12_M_<wbr>constructIPKcEEvT_S8_<wbr>St20forward_iterator_tag<br>
0000000000000000 t
.text$_ZNSt7__cxx1112basic_<wbr>stringIcSt11char_<wbr>traitsIcESaIcEE12_M_<wbr>constructIPKcEEvT_S8_<wbr>St20forward_iterator_tag<br>
0000000000000000 r
.xdata$_ZNSt7__cxx1112basic_<wbr>stringIcSt11char_<wbr>traitsIcESaIcEE12_M_<wbr>constructIPKcEEvT_S8_<wbr>St20forward_iterator_tag<br>
0000000000000000 T
_ZNSt7__cxx1112basic_<wbr>stringIcSt11char_<wbr>traitsIcESaIcEE12_M_<wbr>constructIPKcEEvT_S8_<wbr>St20forward_iterator_tag<br>
<br>
</li>
<li>Linux, static libstdc++:<br>
0000000000000000 W
_ZNSt7__cxx1112basic_<wbr>stringIcSt11char_<wbr>traitsIcESaIcEE12_M_<wbr>constructIPKcEEvT_S8_<wbr>St20forward_iterator_tag</li>
</ol>
<p>This greatly reduces Clang usefulness on Windows with MinGW.<br>
All responses are welcome.</p>
<p>Best Regards,<br>
Mateusz<br>
</p>
</div>
<br>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div>
</blockquote></body></html>