[llvm-bugs] [Bug 44205] New: [Microsoft ABI] dllexport not sufficient to emit complete destructor

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Dec 2 13:06:45 PST 2019


            Bug ID: 44205
           Summary: [Microsoft ABI] dllexport not sufficient to emit
                    complete destructor
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: LLVM Codegen
          Assignee: unassignedclangbugs at nondot.org
          Reporter: CFSworks at gmail.com
                CC: llvm-bugs at lists.llvm.org, neeilans at live.com,
                    richard-llvm at metafoo.co.uk

In the Microsoft ABI, non-base destructors are treated as if they were inline
methods, being emitted only as-needed. The exception to "only as-needed" is if
there's a dllexport, which forces all inlines to be emitted so that they're
available to a dllimport, as the latter altogether suppresses emitting
definitions in favor of importing them from a DLL containing the dllexport

Clang views complete destructors as a tier below inline methods: their
definitions aren't just elided, they aren't even brought into existence unless
needed somewhere in the TU. Perfectly okay, but if the class is dllexport, then
the complete destructor must be considered "needed" (must be realized) so it
can be emitted.

For the benefit of those searching for this bug, the missing vbase dtor will
cause an error that looks like:
lld-link : error : undefined symbol: "__declspec(dllimport) public: void
__cdecl SomeClass::`vbase dtor'(void)" (__imp_??_DSomeClass@@QEAAXXZ)

One suitable workaround is to put a never-called function in the dllexport TU
that somehow references the complete destructor. Another is to enable the
inline optimization in the dllimport TU; that should cause Clang to inline the
complete destructor instead of importing it.

Distinct from, but perhaps related to, #44035, which is caused by the complete
destructor using the dllimport/dllexport declaration from the base destructor
instead of from the class declaration.


$ cat dllexport.cpp 
struct Base { ~Base() { } };
struct __declspec(dllexport) Exported : virtual public Base { };

$ cl /nologo /c dllexport.cpp && dumpbin /symbols dllexport.obj | grep vbase
01D 00000000 SECTA  notype ()    External     | ??_DExported@@QEAAXXZ (public:
void __cdecl Exported::`vbase destructor'(void))

$ clang-cl /nologo /c dllexport.cpp && dumpbin /symbols dllexport.obj | grep


You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191202/22760de1/attachment.html>

More information about the llvm-bugs mailing list