https://bugs.llvm.org/show_bug.cgi?id=44035

            Bug ID: 44035
           Summary: dllexported dtor and virtual base lead to undefined
                    symbol in debug build
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: -New Bugs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected], [email protected],
                    [email protected], [email protected]

Created attachment 22829
  --> https://bugs.llvm.org/attachment.cgi?id=22829&action=edit
repro testcase

When compiling the same code with clang-cl (r375090) and MSVS 2019 (16.3.9),
the LLVM toolchain fails with a linker error, while the Microsoft one does not.

error : undefined symbol: __declspec(dllimport) public: void __thiscall
derived::`vbase dtor'(void)

Full repro below (also in the attachment)

=== lib.h ===
struct base {
    virtual LIBRARY_EXPORT ~base();
};
struct derived : public virtual base {
    virtual LIBRARY_EXPORT ~derived();
};

=== lib.cpp ===
#define LIBRARY_EXPORT __declspec(dllexport)
#include "lib.h"
LIBRARY_EXPORT base::~base() = default;
LIBRARY_EXPORT derived::~derived() = default;

=== main.cpp ===
#define LIBRARY_EXPORT __declspec(dllimport)
#include "lib.h"
int main() {
    derived{};
}

================
LLVM toolchain commands:

> clang-cl /c /Z7 /W3 /WX- /Od /D _WINDLL /D _MBCS /EHsc /MDd /GS /Gd /TP 
> lib.cpp
> lld-link /OUT:"library.dll" /IMPLIB:"library.lib" /DLL lib.obj
> clang-cl /c /Z7 /W3 /WX- /Od /D _MBCS /EHsc /MDd /GS /Gd /TP main.cpp
> lld-link /OUT:"executable.exe" library.lib main.obj

Output:

lld-link : error : undefined symbol: __declspec(dllimport) public: void
__thiscall derived::`vbase dtor'(void)
>>> referenced by D:\Mat\Projects\test\executable\main.cpp:5
>>>               Debug\main.obj:(_main)
>>> referenced by D:\Mat\Projects\test\library\lib.h:14
>>>               Debug\main.obj:(public: virtual void * __thiscall 
>>> derived::`scalar deleting dtor'(unsigned int))

The same commands with the Microsoft toolchain, giving no errors:

> cl /c /Z7 /W3 /WX- /Od /D _WINDLL /D _MBCS /EHsc /MDd /GS /Gd /TP lib.cpp
> link /OUT:"library.dll" /IMPLIB:"library.lib" /DLL lib.obj
> cl /c /Z7 /W3 /WX- /Od /D _MBCS /EHsc /MDd /GS /Gd /TP main.cpp
> link /OUT:"executable.exe" library.lib main.obj

I've also tried the release binaries of LLVM 8 and 9 and the same issue is
present.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to