Tested x86_64-pc-linux-gnu. Thoughts? Can someone else test it on a !DEFAULT_USE_CXA_ATEXIT target?
-- 8< -- The weak declaration of __cxa_finalize was causing some shared libraries linked with -Wl,--as-needed to omit -lc as a dependency, since a library only used to satisfy a weak reference is considered to be unneeded under that flag. As a result the reference doesn't have the appropriate symbol version information. Since r10-6069[1] we control the call to __cxa_finalize with DEFAULT_USE_CXA_ATEXIT, so there's no need to also declare it as a weak reference; if the target has __cxa_atexit, it must also have __cxa_finalize. Also since that commit, -fuse-cxa-atexit has been broken, since the destructors don't get run if the default is off; this patch similarly breaks -fno-use-cxa-atexit, since crtstuff will still demand __cxa_finalize. It seems reasonable to ask people to use the configure flag instead, and this patch changes the compiler flag to be ignored with a warning. Alternatively, we could replace -lc with --push-state --no-as-needed -lc --pop-state which is less likely to break obscure uses, but could result in libc dependencies that are actually unneeded. And some of the obscure uses have been broken since GCC 10. [1] https://gcc.gnu.org/pipermail/gcc-patches/2019-December/536384.html libgcc/ChangeLog: * crtstuff.c (__cxa_finalize): Not weak. Only declare when DEFAULT_USE_CXA_ATEXIT. gcc/ChangeLog: * doc/invoke.texi: Remove -fuse-cxa-atexit. gcc/c-family/ChangeLog: * c.opt (-fuse-cxa-atexit): Now Undocumented. * c-opts.cc (c_common_post_options): Warn about it. * c.opt.urls: Regenerate. gcc/testsuite/ChangeLog: * g++.dg/abi/pr98531-3.C: Remove -fno-use-cxa-atexit. * g++.dg/abi/pr98531-4.C: Likewise. * g++.dg/init/static-cdtor1.C: Likewise. * g++.dg/pr61324.C: Likewise. * g++.dg/warn/Wunused-3.C: Likewise. * g++.dg/modules/pr98531-2.h: Removed. * g++.dg/modules/pr98531-2_b.C: Removed. * g++.dg/modules/pr98531-2_a.H: Removed. --- gcc/doc/invoke.texi | 10 +--------- gcc/c-family/c.opt | 2 +- gcc/testsuite/g++.dg/modules/pr98531-2.h | 13 ------------- gcc/c-family/c-opts.cc | 11 +++++++++++ gcc/testsuite/g++.dg/abi/pr98531-3.C | 2 +- gcc/testsuite/g++.dg/abi/pr98531-4.C | 2 +- gcc/testsuite/g++.dg/init/static-cdtor1.C | 12 ++++++------ gcc/testsuite/g++.dg/modules/pr98531-2_b.C | 4 ---- gcc/testsuite/g++.dg/pr61324.C | 2 +- gcc/testsuite/g++.dg/warn/Wunused-3.C | 2 +- libgcc/crtstuff.c | 10 ++++------ gcc/c-family/c.opt.urls | 3 --- gcc/testsuite/g++.dg/modules/pr98531-2_a.H | 5 ----- 13 files changed, 27 insertions(+), 51 deletions(-) delete mode 100644 gcc/testsuite/g++.dg/modules/pr98531-2.h delete mode 100644 gcc/testsuite/g++.dg/modules/pr98531-2_b.C delete mode 100644 gcc/testsuite/g++.dg/modules/pr98531-2_a.H diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index b83818337c5..70ae1a7d800 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -237,7 +237,7 @@ in the following sections. -fstrong-eval-order@r{[}=@var{kind}@r{]} -ftemplate-backtrace-limit=@var{n} -ftemplate-depth=@var{n} --fno-threadsafe-statics -fuse-cxa-atexit +-fno-threadsafe-statics -fno-weak -nostdinc++ -fvisibility-inlines-hidden -fvisibility-ms-compat @@ -3670,14 +3670,6 @@ ABI for thread-safe initialization of local statics. You can use this option to reduce code size slightly in code that doesn't need to be thread-safe. -@opindex fuse-cxa-atexit -@item -fuse-cxa-atexit -Register destructors for objects with static storage duration with the -@code{__cxa_atexit} function rather than the @code{atexit} function. -This option is required for fully standards-compliant handling of static -destructors, but only works if your C library supports -@code{__cxa_atexit}. - @opindex fno-use-cxa-get-exception-ptr @opindex fuse-cxa-get-exception-ptr @item -fno-use-cxa-get-exception-ptr diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 8af466d1ed1..69961d4bf9f 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -2418,7 +2418,7 @@ C ObjC C++ ObjC++ LTO Var(flag_signed_char, 0) Make \"char\" unsigned by default. fuse-cxa-atexit -C++ ObjC++ Var(flag_use_cxa_atexit) Init(DEFAULT_USE_CXA_ATEXIT) +C++ ObjC++ Var(flag_use_cxa_atexit) Init(DEFAULT_USE_CXA_ATEXIT) Undocumented Use __cxa_atexit to register destructors. fuse-cxa-get-exception-ptr diff --git a/gcc/testsuite/g++.dg/modules/pr98531-2.h b/gcc/testsuite/g++.dg/modules/pr98531-2.h deleted file mode 100644 index 62d4c1d1f90..00000000000 --- a/gcc/testsuite/g++.dg/modules/pr98531-2.h +++ /dev/null @@ -1,13 +0,0 @@ - -struct __waiters -{ - __waiters() noexcept; - ~__waiters () noexcept; - - static __waiters &_S_for() - { - static __waiters w; - - return w; - } -}; diff --git a/gcc/c-family/c-opts.cc b/gcc/c-family/c-opts.cc index 3ee9444cbef..290c21824b3 100644 --- a/gcc/c-family/c-opts.cc +++ b/gcc/c-family/c-opts.cc @@ -965,6 +965,17 @@ c_common_post_options (const char **pfilename) if (warn_packed_bitfield_compat == -1) warn_packed_bitfield_compat = 1; + if (!flag_use_cxa_atexit != !DEFAULT_USE_CXA_ATEXIT) + { + const char *opt, *copt; + if (flag_use_cxa_atexit) + opt = "-fuse-cxa-atexit", copt = "--enable-__cxa_atexit"; + else + opt = "-fno-use-cxa-atexit", copt = "--disable-__cxa_atexit"; + warning (0, "ignoring %s, configure gcc with %s instead", opt, copt); + flag_use_cxa_atexit = DEFAULT_USE_CXA_ATEXIT; + } + /* Special format checking options don't work without -Wformat; warn if they are used. */ if (!warn_format) diff --git a/gcc/testsuite/g++.dg/abi/pr98531-3.C b/gcc/testsuite/g++.dg/abi/pr98531-3.C index de6129dc808..02a6fd5f7bd 100644 --- a/gcc/testsuite/g++.dg/abi/pr98531-3.C +++ b/gcc/testsuite/g++.dg/abi/pr98531-3.C @@ -1,5 +1,5 @@ // { dg-do compile { target c++11 } } -// { dg-additional-options -fno-use-cxa-atexit } + // PR 98531 Making __cxa_atexit (or atexit) more visible means it // must be consistent with the std library's declarations diff --git a/gcc/testsuite/g++.dg/abi/pr98531-4.C b/gcc/testsuite/g++.dg/abi/pr98531-4.C index ec64ee07a17..b64b69bbac6 100644 --- a/gcc/testsuite/g++.dg/abi/pr98531-4.C +++ b/gcc/testsuite/g++.dg/abi/pr98531-4.C @@ -1,5 +1,5 @@ // { dg-do compile { target c++11 } } -// { dg-additional-options -fno-use-cxa-atexit } + // PR 98531 Making __cxa_atexit (or atexit) more visible means it // must be consistent with the std library's declarations diff --git a/gcc/testsuite/g++.dg/init/static-cdtor1.C b/gcc/testsuite/g++.dg/init/static-cdtor1.C index d4d85f99c43..77a3d8b6942 100644 --- a/gcc/testsuite/g++.dg/init/static-cdtor1.C +++ b/gcc/testsuite/g++.dg/init/static-cdtor1.C @@ -1,13 +1,13 @@ // { dg-do compile { target { lp64 && { i?86-*-linux* x86_64-*-linux* } } } } -// { dg-additional-options -fno-use-cxa-atexit } + // Make sure we emit initializers in the correct order. // ctors -// { dg-final { scan-assembler {_Z41__static_initialization_and_destruction_0v:.*movl \$var1[^\n]*\n[^\n]*_ZN5LeelaC1Ev[^\n]*\n[^\n]*movl \$var2[^\n]*\n[^\n]*_ZN5LeelaC1Ev[^\n]*\n[^\n]*movl \$var3[^\n]*\n[^\n]*_ZN5LeelaC1Ev} { target nonpic } } } -// { dg-final { scan-assembler {_Z41__static_initialization_and_destruction_0v:.*leaq var1[^\n]*\n[^\n]*(?:|movq[^\n]*\n[^\n]*)_ZN5LeelaC1Ev[^\n]*\n[^\n]*leaq var2[^\n]*\n[^\n]*(?:|movq[^\n]*\n[^\n]*)_ZN5LeelaC1Ev[^\n]*\n[^\n]*leaq var3[^\n]*\n[^\n]*(?:|movq[^\n]*\n[^\n]*)_ZN5LeelaC1Ev} { target { ! nonpic } } } } -// dtors -// { dg-final { scan-assembler {_Z41__static_initialization_and_destruction_1v:.*movl \$var3[^\n]*\n[^\n]*_ZN5LeelaD1Ev[^\n]*\n[^\n]*movl \$var2[^\n]*\n[^\n]*_ZN5LeelaD1Ev[^\n]*\n[^\n]*movl \$var1[^\n]*\n[^\n]*_ZN5LeelaD1Ev} { target nonpic } } } -// { dg-final { scan-assembler {_Z41__static_initialization_and_destruction_1v:.*leaq var3[^\n]*\n[^\n]*(?:|movq[^\n]*\n[^\n]*)_ZN5LeelaD1Ev[^\n]*\n[^\n]*leaq var2[^\n]*\n[^\n]*(?:|movq[^\n]*\n[^\n]*)_ZN5LeelaD1Ev[^\n]*\n[^\n]*leaq var1[^\n]*\n[^\n]*(?:|movq[^\n]*\n[^\n]*)_ZN5LeelaD1Ev} { target { ! nonpic } } } } +// { dg-final { scan-assembler {_Z41__static_initialization_and_destruction_0v:.*movl \$var1[^\n]*\n[^\n]*_ZN5LeelaC1Ev.*movl \$var2[^\n]*\n[^\n]*_ZN5LeelaC1Ev.*movl \$var3[^\n]*\n[^\n]*_ZN5LeelaC1Ev} { target nonpic } } } +// { dg-final { scan-assembler {_Z41__static_initialization_and_destruction_0v:.*leaq var1[^\n]*\n[^\n]*(?:|movq[^\n]*\n[^\n]*)_ZN5LeelaC1Ev.*leaq var2[^\n]*\n[^\n]*(?:|movq[^\n]*\n[^\n]*)_ZN5LeelaC1Ev.*leaq var3[^\n]*\n[^\n]*(?:|movq[^\n]*\n[^\n]*)_ZN5LeelaC1Ev} { target { ! nonpic } } } } +// dtors (on non-__cxa_atexit target) +// { dg-final { scan-assembler {_Z41__static_initialization_and_destruction_1v:.*movl \$var3[^\n]*\n[^\n]*_ZN5LeelaD1Ev[^\n]*\n[^\n]*movl \$var2[^\n]*\n[^\n]*_ZN5LeelaD1Ev[^\n]*\n[^\n]*movl \$var1[^\n]*\n[^\n]*_ZN5LeelaD1Ev} { target { nonpic && { ! cxa_atexit } } } } } +// { dg-final { scan-assembler {_Z41__static_initialization_and_destruction_1v:.*leaq var3[^\n]*\n[^\n]*(?:|movq[^\n]*\n[^\n]*)_ZN5LeelaD1Ev[^\n]*\n[^\n]*leaq var2[^\n]*\n[^\n]*(?:|movq[^\n]*\n[^\n]*)_ZN5LeelaD1Ev[^\n]*\n[^\n]*leaq var1[^\n]*\n[^\n]*(?:|movq[^\n]*\n[^\n]*)_ZN5LeelaD1Ev} { target { { ! nonpic } && { ! cxa_atexit } } } } } struct Leela { Leela (); diff --git a/gcc/testsuite/g++.dg/modules/pr98531-2_b.C b/gcc/testsuite/g++.dg/modules/pr98531-2_b.C deleted file mode 100644 index b5fa4492e8a..00000000000 --- a/gcc/testsuite/g++.dg/modules/pr98531-2_b.C +++ /dev/null @@ -1,4 +0,0 @@ -// { dg-additional-options "-fmodules-ts -fno-module-lazy -fno-use-cxa-atexit" } - -#include "pr98531-2.h" -import "pr98531-2_a.H"; diff --git a/gcc/testsuite/g++.dg/pr61324.C b/gcc/testsuite/g++.dg/pr61324.C index 610257436b3..d63b100f981 100644 --- a/gcc/testsuite/g++.dg/pr61324.C +++ b/gcc/testsuite/g++.dg/pr61324.C @@ -1,5 +1,5 @@ // { dg-do compile } -// { dg-options "-O -fkeep-inline-functions -fno-use-cxa-atexit" } +// { dg-options "-O -fkeep-inline-functions" } void foo (); struct S diff --git a/gcc/testsuite/g++.dg/warn/Wunused-3.C b/gcc/testsuite/g++.dg/warn/Wunused-3.C index 2d00dda3faa..31009094352 100644 --- a/gcc/testsuite/g++.dg/warn/Wunused-3.C +++ b/gcc/testsuite/g++.dg/warn/Wunused-3.C @@ -1,5 +1,5 @@ // { dg-do compile } -// { dg-options "-Wunused -O -fno-use-cxa-atexit" } +// { dg-options "-Wunused -O" } void do_cleanups(); diff --git a/libgcc/crtstuff.c b/libgcc/crtstuff.c index b9767cd1eee..ffb600d9fbf 100644 --- a/libgcc/crtstuff.c +++ b/libgcc/crtstuff.c @@ -346,11 +346,10 @@ void *__dso_handle = &__dso_handle; #else void *__dso_handle = 0; #endif -#endif /* DEFAULT_USE_CXA_ATEXIT */ -/* The __cxa_finalize function may not be available so we use only a - weak declaration. */ -extern void __cxa_finalize (void *) TARGET_ATTRIBUTE_WEAK; +extern void __cxa_finalize (void *); + +#endif /* DEFAULT_USE_CXA_ATEXIT */ /* Run all the global destructors on exit from the program. */ @@ -385,8 +384,7 @@ __do_global_dtors_aux (void) #if DEFAULT_USE_CXA_ATEXIT #ifdef CRTSTUFFS_O - if (__cxa_finalize) - __cxa_finalize (__dso_handle); + __cxa_finalize (__dso_handle); #endif #endif diff --git a/gcc/c-family/c.opt.urls b/gcc/c-family/c.opt.urls index 65d1221c4ad..7394b2b2029 100644 --- a/gcc/c-family/c.opt.urls +++ b/gcc/c-family/c.opt.urls @@ -1388,9 +1388,6 @@ UrlSuffix(gcc/C_002b_002b-Dialect-Options.html#index-fno-threadsafe-statics) ; duplicate: 'gcc/C-Dialect-Options.html#index-funsigned-char' ; duplicate: 'gcc/Characters-implementation.html#index-funsigned-char-1' -fuse-cxa-atexit -UrlSuffix(gcc/C_002b_002b-Dialect-Options.html#index-fuse-cxa-atexit) - fuse-cxa-get-exception-ptr UrlSuffix(gcc/C_002b_002b-Dialect-Options.html#index-fno-use-cxa-get-exception-ptr) diff --git a/gcc/testsuite/g++.dg/modules/pr98531-2_a.H b/gcc/testsuite/g++.dg/modules/pr98531-2_a.H deleted file mode 100644 index 757d68af297..00000000000 --- a/gcc/testsuite/g++.dg/modules/pr98531-2_a.H +++ /dev/null @@ -1,5 +0,0 @@ -// { dg-additional-options "-fmodule-header -fno-use-cxa-atexit" } -// PR c++ 98531 no-context __cxa_atexit -// { dg-module-cmi {} } - -#include "pr98531-2.h" base-commit: 61f07bcb509cca051e39b698a1bd9a5907f26cf4 -- 2.49.0