[MS ABI] Clang doesn't generate local vftables with `dllimport`
| Bugzilla Link | 23549 |
| Version | unspecified |
| OS | All |
| Blocks | llvm/llvm-project#12849 |
| CC | @DougGregor,@jyu2-git,@zahiraam |
Extended Description
consider:
struct _declspec(dllimport) A {
A()
virtual ~A();
};
A *f() { return new A();}
MSVC generates:
This calls operator new and the imported A constructor. However, it also overwrites the VFPtr with a so-called "local vftable". I suspect this is to support overriding the global operator new and delete.
More information is available here: https://groups.google.com/d/msg/microsoft.public.vc.language/atSh_2VSc2w/EgJ3r_7OzVUJ
I am sorry. I was past wrong result for x_cl.sh:
[0 llvm-23549]$ sh x_cl.sh
x_a.cpp
Creating library x_a.lib and object x_a.exp
x.cpp
In EXE's ::operator new
Drawbot()
~Drawbot()
In EXE's ::operator delete
PASSED
while x_clang_cl.sh give:
[0 llvm-23549]$ sh x_clang_cl.sh
[0 llvm-23549]$ ./x.exe
In EXE's ::operator new
Drawbot()
~Drawbot()
In DLL's ::operator delete
FAILED
[116 llvm-23549]$
small test case I attach a small test case, that fails with clang-cl but pass with MS cl
sh x_clang_cl.sh In EXE's ::operator new Drawbot() ~Drawbot() In DLL's ::operator delete FAILED sh x_cl.sh In EXE's ::operator new Drawbot() ~Drawbot() In DLL's ::operator delete FAILED
The test is to demonstrate a potential heap problem. Where pragma is define both operator new/delete in two different TU. The operator new is called from one TU, but operator delete is call from other TU (dll).
I think local vatble is still needed.
Array new creates another symbol, the "local vftable constructor closure". I don't believe we will need this though.