c++: cross-module __cxa_atexit use [PR 98531]

Nathan Sidwell nathan@acm.org
Wed Feb 3 12:59:00 GMT 2021


[Dropping Richard, as I don't think his input is necessary further]

Hi Rainer,
here are two patches, to be applied in sequence (replacing earlier 
versions of the patch).

The first is merely a testsuite correction of the earlier patch to 
inhibit the cxa_atexit-specific tests where it matters.  (I don't think 
it matters in the ABI ones, if the library does not provide them, we 
won't hit a declaration that could differ)

The second fixes the atexit issue (and array entity with cxa_atexit) you 
encountered on solaris 11.3.

With these two patches I could build the xtreme-header-2_a.ii you 
provided on an i386-solaris2.11 xcompiler (I can only compile there, not 
got a complete runtime to run the tests).

Please let me know how these behave, thanks.

patch 3a:
     c++: cross-module __cxa_atexit use [PR 98531]

The compiler's use of lazily-declared library functions must insert
said functions into a symbol table, so that they can be correctly
merged across TUs at the module-level.  We have too many different
ways of declaring such library functions.  This fixes __cxa_atexit (or
its system-specific variations), pushing (or merging) the decl into
the appropriate namespace.  Because we're pushing a lazy builtin,
check_redeclaration_exception_specification needed a tweak to allow a
such a builtin's eh spec to differ from what the user may have already
declared. (I suspect no all headers declare atexit as noexcept.)

We can't test the -fno-use-cxa-atexit path with modules, as that
requires a followup patch to a closely related piece (which also
affects cxa_atexit targets in other circumstances).

             PR c++/98531
             gcc/cp/
             * cp-tree.h (push_abi_namespace, pop_abi_namespace): Declare.
             * decl.c (push_abi_namespace, pop_abi_namespace): Moved
             from rtti.c, add default namespace arg.
             (check_redeclaration_exception_specification): Allow a lazy
             builtin's eh spec to differ from an lready-declared user
             declaration.
             (declare_global_var): Use push/pop_abi_namespace.
             (get_atexit_node): Push the fndecl into a namespace.
             * rtti.c (push_abi_namespace, pop_abi_namespace): Moved to
             decl.c.
             gcc/testsuite/
             * g++.dg/modules/pr98531-1.h: New.
             * g++.dg/modules/pr98531-1_a.H: New.
             * g++.dg/modules/pr98531-1_b.C: New.
             * g++.dg/abi/pr98531-1.C: New.
             * g++.dg/abi/pr98531-2.C: New.
             * g++.dg/abi/pr98531-3.C: New.
             * g++.dg/abi/pr98531-4.C: New.


patch 3b:
c++: cleanup function name [PR 98531]

The next piece of 98531 is that in some cases we need to create a
cleanup function to do the work (when the object is an array, or we're
using regular atexit).  We were not pushing that function's decl
anywhere (not giving it a context) so streaming it failed.

This is a partial fix.  You'll notice we're naming these from a per-TU
counter.  I've captured that in PR98893.

             gcc/cp/
             * decl.c (start_cleanup_fn): Push function into
             namespace.
             gcc/testsuite/
             * g++.dg/modules/pr98531-2.h: New.
             * g++.dg/modules/pr98531-2_a.H: New.
             * g++.dg/modules/pr98531-2_b.C: New.
             * g++.dg/modules/pr98531-3.h: New.
             * g++.dg/modules/pr98531-3_a.H: New.
             * g++.dg/modules/pr98531-3_b.C: New.

-- 
Nathan Sidwell
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr98531-3a.diff
Type: text/x-patch
Size: 10071 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20210203/5e381b49/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pr98531-3b.diff
Type: text/x-patch
Size: 3922 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-patches/attachments/20210203/5e381b49/attachment-0001.bin>


More information about the Gcc-patches mailing list