c++: New module mangling ABI
authorNathan Sidwell <nathan@acm.org>
Thu, 3 Mar 2022 00:13:43 +0000 (19:13 -0500)
committerNathan Sidwell <nathan@acm.org>
Fri, 4 Mar 2022 15:15:18 +0000 (10:15 -0500)
commit73baba1ae1b8f3618c2d3b674117b8a462e0ca76
tree6bef001d2cbd8c83d7487248c9e6436e2a46da0d
parentf1b3e3853329b58fb2e50c17487df2ecbc4a5608
c++: New module mangling ABI

This implements a new module mangling ABI as the original one has a
few issues:

a) it was not demangleable (oops)

b) implemented a weak ownership model.

This implements a strong ownership model, so that exported entities
from named modules are mangled to include their module attachment.
This gives more informative linker diagnostics and better module
isolation.  Weak ownership was hoped to allow backwards compatibility
with non-modular code, but in practice was very brittle, and C++20
added new semantics for linkage declarations that cover the needed
functionality.

FAOD Clang is also moving to this ABI and documentation will be added
to the Itanium ABI specification.

gcc/cp/
* cp-tree.h (mangle_identifier): Replace with ...
(mangle_module_component): ... this.
* mangle.cc (dump_substitution_candidates): Adjust.
(add_substitution): Likewise.
(find_substitution): Likewise.
(unmangled_name_p): Likewise.
(mangle_module_substitution): Reimplement.
(mangle_module_component): New.
(write_module, maybe_write_module): Adjust.
(write_name): Drop modules here.
(write_unqualified): Do them here instead.
(mangle_global_init): Adjust.
* module.cc (module_state::mangle): Adjust.
(mangle_module): Likewise.
(get_originating_module): Adjust.

gcc/testsuite/
* g++.dg/modules/fn-inline-1_b.C: Adjust.
* g++.dg/modules/fn-inline-1_c.C: Adjust.
* g++.dg/modules/imp-inline-1_a.C: Adjust.
* g++.dg/modules/imp-inline-1_b.C: Adjust.
* g++.dg/modules/init-2_a.C: Adjust.
* g++.dg/modules/init-2_b.C: Adjust.
* g++.dg/modules/init-2_c.C: Adjust.
* g++.dg/modules/member-def-2_d.C: Adjust.
* g++.dg/modules/mod-sym-1.C: Adjust.
* g++.dg/modules/mod-sym-2.C: Adjust.
* g++.dg/modules/mod-sym-3.C: Adjust.
* g++.dg/modules/sym-subst-1.C: Adjust.
* g++.dg/modules/sym-subst-2_b.C: Adjust.
* g++.dg/modules/sym-subst-3_a.C: Adjust.
* g++.dg/modules/sym-subst-3_b.C: Adjust.
* g++.dg/modules/sym-subst-4.C: Adjust.
* g++.dg/modules/sym-subst-5.C: Adjust.
* g++.dg/modules/sym-subst-6.C: Adjust.
* g++.dg/modules/tpl-spec-1_a.C: Adjust.
* g++.dg/modules/tpl-spec-2_b.C: Adjust.
* g++.dg/modules/tpl-spec-2_d.C: Adjust.
* g++.dg/modules/tpl-spec-3_a.C: Adjust.
* g++.dg/modules/virt-1_a.C: Adjust.
* g++.dg/modules/virt-2_a.C: Adjust.
* g++.dg/modules/virt-2_b.C: Adjust.
* g++.dg/modules/virt-2_c.C: Adjust.
* g++.dg/modules/vtt-1_a.C: Adjust.
* g++.dg/modules/vtt-1_b.C: Adjust.
31 files changed:
gcc/cp/cp-tree.h
gcc/cp/mangle.cc
gcc/cp/module.cc
gcc/testsuite/g++.dg/modules/fn-inline-1_b.C
gcc/testsuite/g++.dg/modules/fn-inline-1_c.C
gcc/testsuite/g++.dg/modules/imp-inline-1_a.C
gcc/testsuite/g++.dg/modules/imp-inline-1_b.C
gcc/testsuite/g++.dg/modules/init-2_a.C
gcc/testsuite/g++.dg/modules/init-2_b.C
gcc/testsuite/g++.dg/modules/init-2_c.C
gcc/testsuite/g++.dg/modules/member-def-2_d.C
gcc/testsuite/g++.dg/modules/mod-sym-1.C
gcc/testsuite/g++.dg/modules/mod-sym-2.C
gcc/testsuite/g++.dg/modules/mod-sym-3.C
gcc/testsuite/g++.dg/modules/sym-subst-1.C
gcc/testsuite/g++.dg/modules/sym-subst-2_b.C
gcc/testsuite/g++.dg/modules/sym-subst-3_a.C
gcc/testsuite/g++.dg/modules/sym-subst-3_b.C
gcc/testsuite/g++.dg/modules/sym-subst-4.C
gcc/testsuite/g++.dg/modules/sym-subst-5.C
gcc/testsuite/g++.dg/modules/sym-subst-6.C
gcc/testsuite/g++.dg/modules/tpl-spec-1_a.C
gcc/testsuite/g++.dg/modules/tpl-spec-2_b.C
gcc/testsuite/g++.dg/modules/tpl-spec-2_d.C
gcc/testsuite/g++.dg/modules/tpl-spec-3_a.C
gcc/testsuite/g++.dg/modules/virt-1_a.C
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/vtt-1_a.C
gcc/testsuite/g++.dg/modules/vtt-1_b.C