Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

duplicate symbol link error with clang-compiled DLL #18729

Open Quuxplusone opened 10 years ago

Quuxplusone commented 10 years ago
Bugzilla Link PR18730
Status NEW
Importance P normal
Reported by Yaron Keren (yaron.keren@gmail.com)
Reported on 2014-02-04 16:22:13 -0800
Last modified on 2017-06-10 12:48:16 -0700
Version trunk
Hardware PC Windows NT
CC anton@korobeynikov.info, geek4civic@gmail.com, llvm-bugs@lists.llvm.org, rafael@espindo.la
Fixed by commit(s)
Attachments c1.bat (522 bytes, application/octet-stream)
e.cpp (70 bytes, text/plain)
c2.bat (721 bytes, application/octet-stream)
d.cpp (69 bytes, text/plain)
c.sh (277 bytes, application/octet-stream)
Blocks
Blocked by
See also
Created attachment 12008
batch file to compile

I have a problem when linking C++ DLLs compiled with MinGW 4.8.2 with clang-
produced object file. The linker complains about multiple definitions for
several typeinfos. The scenario is rather complex but I had reduced the issue
to differences between the typeinfos emitted for a simple testcase.

The same include files and libraries were used, MinGW 4.8.2 MinGW-w64 rev2 with
trivial compilation flags. Attached is a simple batch file to reproduce the
issue. Clang is svn few days old, gcc is MinGW-w64 rev2, the latest.

The source code is:

 #include <stdexcept>
 int main() { throw std::exception(); return 0; }

When compiling with clang, nm --demangle e_clang.o =
00000000 d .eh_frame
00000000 t .text
00000000 t .text
00000001 a @feat.00
         U __cxa_allocate_exception
         U __cxa_throw
         U __main
00000000 T std::exception::exception()
         U std::exception::~exception()
         U typeinfo for std::exception
         U vtable for std::exception
00000000 T main

but with gcc, nm --demangle e_gcc.o
00000000 b .bss
00000000 d .data
00000000 r .eh_frame
00000000 r .eh_frame$_ZNSt9exceptionC1Ev
00000000 r .rdata$_ZTISt9exception
00000000 r .rdata$_ZTSSt9exception
00000000 r .rdata$zzz
00000000 t .text
00000000 t .text$_ZNSt9exceptionC1Ev
         U __cxa_allocate_exception
         U __cxa_throw
         U __main
00000000 T std::exception::exception()
         U std::exception::~exception()
00000000 R typeinfo for std::exception
00000000 R typeinfo name for std::exception
         U vtable for __cxxabiv1::__class_type_info
         U vtable for std::exception
00000000 T main

there are couple of differences:

* clang producing U typeinfo for std::exception whereas gcc produces R typeinfo
for std::exception.
* The R typeinfo name for std::exception is not produced by clang.
* r .rdata$ records are also not produced by clang.

One or more of these differences causes typeinfos merging failure while linking
the above object files with C++ DLLs compiled with MinGW.
I suspect the first difference is the critical one.
In any case, clang output of typeinfos should match gcc.
Quuxplusone commented 10 years ago

Attached e.cpp (70 bytes, text/plain): testcase source code

Quuxplusone commented 10 years ago

Will you please linker output here as well?

Quuxplusone commented 10 years ago
Yes. Let's create a trivial DLL :

#include <stdexcept>
int ddd() { throw std::exception(); return 0; }

compiled with:

  gcc -shared d.cpp -o d.dll -lstdc++

e_gcc.o can link against it OK:

  gcc e_gcc.o -o e_gcc.exe -lstdc++ d.dll

without error, but linking the clang-compiled object against it:

  gcc e_clang.o -o e_clang.exe -lstdc++ d.dll

produces error of multiple definition of the typename exception.

d000001.o:(.idata$5+0x0): multiple definition of `_imp___ZTISt9exception'
c:/mingw-builds/i686-4.8.2-release-win32-dwarf-rt_v3-
rev2/mingw32/bin/../lib/gcc/i686-w64-
mingw32/4.8.2/libstdc++.dll.a(d003499.o):(.idata$5+0x0): first defined here
d000001.o:(.idata$6+0x0): multiple definition of `_nm___ZTISt9exception'
c:/mingw-builds/i686-4.8.2-release-win32-dwarf-rt_v3-
rev2/mingw32/bin/../lib/gcc/i686-w64-
mingw32/4.8.2/libstdc++.dll.a(d003499.o):(.idata$6+0x0): first defined here
collect2.exe: error: ld returned 1 exit status

I will attach the DLL source and updated compile script.
Quuxplusone commented 10 years ago

Oh, linking with the additional DLL works for both gcc and clang.

Quuxplusone commented 10 years ago

Oh, linking without the additional DLL works for both gcc and clang.

Quuxplusone commented 10 years ago

Attached c1.bat (522 bytes, application/octet-stream): batch file to compile

Quuxplusone commented 10 years ago

Attached d.cpp (69 bytes, text/plain): Trivial DLL source

Quuxplusone commented 10 years ago

Attached c2.bat (721 bytes, application/octet-stream): Updated batch file to compile and link against a trivial DLL

Quuxplusone commented 9 years ago

Attached c.sh (277 bytes, application/octet-stream): shell script to run example

Quuxplusone commented 7 years ago

still fails as of mingw 5.4 and clang r305089