Open Quuxplusone opened 7 years ago
Note that this code compiles without warnings when given "-Wall -Wextra", but
if given "-Weverything" produces the following warnings:
't' has virtual functions but non-virtual destructor [-Wnon-virtual-dtor]
't2' has virtual functions but non-virtual destructor [-Wnon-virtual-dtor]
't' has no out-of-line virtual method definitions; its vtable will be emitted
in every translation unit [-Wweak-vtables]
't2' has no out-of-line virtual method definitions; its vtable will be emitted
in every translation unit [-Wweak-vtables]
It looks like GCC gives special treatment to dllexported classes without key
functions. If you compile x.cpp in your example, GCC emits and exports a vtable
for t. Clang does not, but it should. If you change the definition of main like
so:
int main() { t2 *p = new t2; }
Then GCC will reference __imp__ZTV1t from y.obj as well.
By the way, this all works fine in MS ABI mode. We just need to enable some of
that logic on mingw.
I tried looking at this for a quick hack, but there's too much going on.
There are too many differences in how msys2-mingw64-g++ 7.1.0 and trunk clang
behave.
gcc does export typeinfo (_ZTI* symbols), while clang doesn't, gcc uses
.linkonce same_size in assembly, etc.
I've found an old attempt ( https://reviews.llvm.org/D1099 ) that actually
tested for proper typeinfo export, but trunk has diverged too much for me to
make any sense of this.
I've reduced a Qt link error to this bug, and boost fails to link apparently
for the same reason, which makes clang not very usable on mingw at the moment.
Attached dllexportimport.tar.gz
(809 bytes, application/x-gzip): test case
This was with clang 13.0.0 targeting windows-gnu
dllexportimport.tar.gz
(809 bytes, application/x-gzip)