-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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
[C++20] [Modules] Clang didn't generate the virtual table to the unit containing the key function #70585
Comments
@llvm/issue-subscribers-clang-modules Author: Chuanqi Xu (ChuanqiXu9)
Reproducer:
Compiler layer2.cppm with:
Then we can't see anything about the definition of virtual table. This violates the itanium ABI 5.2.3: > The virtual table for a class is emitted in the same object containing the definition of its key function, i.e. the first non-pure virtual function that is not inline at the point of class definition. |
I seem to recall we fixed a key function issue not too long ago - is this problem present on earlier branches? |
No, I tested on trunk. The problem we fixed were about we generate the vtables in too many units to produce duplicated symbols. But the problem is about we didn't generate the vtable in the targeted unit so that we met undefined symbol. I am trying to look at it. Probably an oversight. |
I took a simple look at the problem and the cause may be a mismatch. Currently, (maybe there are other paths), when we're generating the constructor of the record decl, we will try to emit the vtable for the record decl if the record decl is a dynamic class. However, in this example, the constructor won't be generated when we compile One solution may be, checking if the current emitting function is a key function and if yes, try to generate the vtable. |
FYI, when I create a similar thing in the old style, with just % nm layer1_b.o | llvm-cxxfilt | grep vtable
00000000000000a0 S vtable for Fruit
U vtable for Banana
U vtable for __cxxabiv1::__class_type_info
% nm layer2_b.o | llvm-cxxfilt | grep vtable
0000000000000d68 S vtable for Banana
U vtable for __cxxabiv1::__class_type_info
U vtable for __cxxabiv1::__si_class_type_info It's seems it's emitting the vtables in one |
Is the concept of a key function necessary with modules? Would anything bad happen if the virtual table were emitted in the object file for the module that defines the class? |
Otherwise we're violating the Itanium ABI, which seems not good. |
But modules are a new space for the ABI - we could change/specify the ABI to home any type defined in a module to that modules object file, right? I think that would be a good ABI feature/change/direction for modules - at least at a glance. Perhaps on discussion there might be complications/issues with doing that. |
(I'd want to do/have done similar things with debug info for Clang Header Modules, |
I filed itanium-cxx-abi/cxx-abi#170. Let's discuss the ABI related issue there. |
Sent #75912 |
of dynamic classes Close llvm#70585 and reflect itanium-cxx-abi/cxx-abi#170. The significant change of the patch is: for dynamic classes attached to module units, we generate the vtable to the attached module units directly and the key functions for such classes is meaningless.
of dynamic classes Close llvm#70585 and reflect itanium-cxx-abi/cxx-abi#170. The significant change of the patch is: for dynamic classes attached to module units, we generate the vtable to the attached module units directly and the key functions for such classes is meaningless.
of dynamic classes Close llvm#70585 and reflect itanium-cxx-abi/cxx-abi#170. The significant change of the patch is: for dynamic classes attached to module units, we generate the vtable to the attached module units directly and the key functions for such classes is meaningless.
of dynamic classes Close llvm#70585 and reflect itanium-cxx-abi/cxx-abi#170. The significant change of the patch is: for dynamic classes attached to module units, we generate the vtable to the attached module units directly and the key functions for such classes is meaningless.
of dynamic classes Close llvm#70585 and reflect itanium-cxx-abi/cxx-abi#170. The significant change of the patch is: for dynamic classes attached to module units, we generate the vtable to the attached module units directly and the key functions for such classes is meaningless.
of dynamic classes Close llvm#70585 and reflect itanium-cxx-abi/cxx-abi#170. The significant change of the patch is: for dynamic classes attached to module units, we generate the vtable to the attached module units directly and the key functions for such classes is meaningless.
…t of dynamic classes (#75912) Close #70585 and reflect itanium-cxx-abi/cxx-abi#170. The significant change of the patch is: for dynamic classes attached to module units, we generate the vtable to the attached module units directly and the key functions for such classes is meaningless.
Reopen due to we reverted #75912 |
I add this to the document to provide a method to workaround: https://clang.llvm.org/docs/StandardCPlusPlusModules.html#missing-vtables-for-classes-attached-to-modules Hope this helps. |
Due to llvm#75912 is reverted and llvm#70585 is reopened. It looks riskful to fix the issue correctly before 19. So we provide a workaround here to help people in this trouble as much as possible.
Yeah, the current blocking issue is that we're waiting the response from MSVC's devs. |
I got the response from MSVC dev: it looks like MSVC will always generate the virtual table on need in the COMDAT section no matter if modules are involved or not. |
…ule unit of dynamic classes (llvm#75912) Close llvm#70585 and reflect itanium-cxx-abi/cxx-abi#170. The significant change of the patch is: for dynamic classes attached to module units, we generate the vtable to the attached module units directly and the key functions for such classes is meaningless.
Close since #102287 is landed. |
Reproducer:
Compiler layer2.cppm with:
Then we can't see anything about the definition of virtual table. This violates the itanium ABI 5.2.3:
The text was updated successfully, but these errors were encountered: