Skip to content

[MS ABI] Clang doesn't generate local vftables with dllimport #23923

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
majnemer mannequin opened this issue May 17, 2015 · 3 comments
Open

[MS ABI] Clang doesn't generate local vftables with dllimport #23923

majnemer mannequin opened this issue May 17, 2015 · 3 comments
Labels
bugzilla Issues migrated from bugzilla c++ clang:to-be-triaged Should not be used for new issues extension:microsoft

Comments

@majnemer
Copy link
Mannequin

majnemer mannequin commented May 17, 2015

Bugzilla Link 23549
Version unspecified
OS All
Blocks #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

@majnemer
Copy link
Mannequin Author

majnemer mannequin commented May 17, 2015

Array new creates another symbol, the "local vftable constructor closure". I don't believe we will need this though.

@jyu2-git
Copy link
Contributor

jyu2-git commented Feb 2, 2018

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.

@jyu2-git
Copy link
Contributor

jyu2-git commented Apr 23, 2018

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]$

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@Endilll Endilll changed the title [MS ABI] Clang doesn't generate local vftables with dllimport [MS ABI] Clang doesn't generate local vftables with dllimport Jul 25, 2024
@Endilll Endilll added the clang:to-be-triaged Should not be used for new issues label Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++ clang:to-be-triaged Should not be used for new issues extension:microsoft
Projects
None yet
Development

No branches or pull requests

2 participants