Open Ivan171 opened 10 years ago
Also experiencing this issue. Here's a minimal test case which demonstrates the linker errors:
https://gist.github.com/hlandau/f6d77b2778e87a6d859940822775b8ca
I believe i've figured whats happening. The problem is not specific to "_S_construct" or -Os. The problem is that the weak symbols generated by Clang, have different section names than the ones generated by GCC. This is causing incompatibilities.
Clang generate simple section names, like: .rdata or .text. GCC generate sections like: .section$SymbolName. Note: The symbol name doesn't have the '_' global prefix.
For example, this is one of the many multiple definitions i've got while trying to build wxWidgets.
Original output: .section .rdata,"r",discard,_IID_IShellItem
Should be: .section .rdata$IID_IShellItem,"r",discard,_IID_IShellItem
This incompatibility may have been introduced by r195798 (to fix llvm/llvm-project#18292 ).
Extended Description
I'm having problems with wxWidgets (static library) built with Clang (trunk + Mingw-w64 4.8.2). The build of wxWidgets went fine, the problem is when i try to link against it.
The wxWidgets -Os build doesn't work with static libstdc++. I get a "multiple definition of `char std::string::_S_construct<char>(char, char, std::allocator const&, std::forward_iterator_tag)'" error.
The -O2/-O3 build works fine.
Here's a litle test case:
$ cat > Test.cpp
include
include
// This is a stripped version of the wxWidgets method. std::string FromCDouble(double val, int precision) { std::ostringstream os; os << val; return os.str(); }
int main() { return 0; }
$ clang++ -Os Test.cpp -std=c++11 -static c:/dev/mingw32/bin/../lib/gcc/i686-w64-mingw32/4.8.2/../../../../lib\libstdc++.a(string-inst.o):(.text$_ZNSs12_S_constructIPcEES0_T_S1_RKSaIcESt20forward_iterator_tag[__ZNSs12_S_constructIPcEES0_T_S1_RKSaIcESt20forward_iterator_tag]+0x0): multiple definition of `char std::string::_S_construct<char>(char, char, std::allocator const&, std::forward_iterator_tag)'
C:\Dev\MSys2\tmp\Test2-525d5d.o:(.text[__ZNSs12_S_constructIPcEES0_T_S1_RKSaIcESt20forward_iterator_tag]+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
clang++.exe: error: linker (via gcc) command failed with exit code 1 (use -v to see invocation)