c++: Implement modules ABI for vtable emissions
commitad30265ccfb211fca35789df2d1404cc12302219
authorNathaniel Shead <nathanieloshead@gmail.com>
Tue, 16 Apr 2024 12:50:26 +0000 (16 22:50 +1000)
committerNathaniel Shead <nathanieloshead@gmail.com>
Thu, 2 May 2024 01:38:54 +0000 (2 11:38 +1000)
tree7b9f0096bfa03b5075a1f5dc8adbec5591f24867
parentfd48e674fd72e9de9eaa47b12a22750512070e64
c++: Implement modules ABI for vtable emissions

This patch implements the changes described in
https://github.com/itanium-cxx-abi/cxx-abi/pull/171.

One restriction that is lifted in the ABI that hasn't been updated here
is that the ABI no longer requires unique vtables to be emitted with
vague linkage.  I haven't changed this behaviour for this patch, but in
the future we could look into changing the relevant target hook
('class_data_always_comdat') to default to 'false'.  But the current
behaviour is more forgiving to changes in key function identification.

Since the ABI for vtables attached to named modules no longer depends on
key methods, this also resolves the issue described in PR c++/105224.

PR c++/105224

gcc/cp/ChangeLog:

* class.cc (finish_struct_1): Also push classes attached to a
module into the 'keyed_classes' list.
* decl.cc (record_key_method_defined): Don't push classes
attached to a named module into the 'keyed_classes' list.
* module.cc (trees_in::read_class_def): Likewise.
* decl2.cc (import_export_class): Uniquely emit vtables for
non-template classes attached to a named module.
(vtables_uniquely_emitted): New function.
(import_export_decl): Update comments. Update with knowledge
about new kinds of uniquely emitted vtables.

gcc/testsuite/ChangeLog:

* g++.dg/modules/virt-2_a.C: Update linkage requirements.
* g++.dg/modules/virt-2_b.C: Likewise.
* g++.dg/modules/virt-2_c.C: Likewise.
* g++.dg/modules/virt-4_a.C: New test.
* g++.dg/modules/virt-4_b.C: New test.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/class.cc
gcc/cp/decl.cc
gcc/cp/decl2.cc
gcc/cp/module.cc
gcc/testsuite/g++.dg/modules/virt-2_a.C
gcc/testsuite/g++.dg/modules/virt-2_b.C
gcc/testsuite/g++.dg/modules/virt-2_c.C
gcc/testsuite/g++.dg/modules/virt-4_a.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/virt-4_b.C [new file with mode: 0644]