diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2023-06-30 11:07:35 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2023-06-30 15:35:02 +0100 |
commit | fe2651affa8c15624188bfd062fb894648743431 (patch) | |
tree | 5330912c016c8d8549df4358652f84d4ab01c556 /libstdc++-v3/configure | |
parent | d083c8c808cae2c7acb46117374bb047b4c3afce (diff) | |
download | gcc-fe2651affa8c15624188bfd062fb894648743431.zip gcc-fe2651affa8c15624188bfd062fb894648743431.tar.gz gcc-fe2651affa8c15624188bfd062fb894648743431.tar.bz2 |
libstdc++: Fix iostream init for Clang on darwin [PR110432]
The __has_attribute(init_priority) check in <iostream> is true for Clang
on darwin, which means that user code including <iostream> thinks the
library will initialize the global streams. However, when libstdc++ is
built by GCC on darwin, the __has_attribute(init_priority) check is
false, which means that the library thinks that user code will do the
initialization when <iostream> is included. This means that the
initialization is never done.
Add an autoconf check so that the header and the library both make their
decision based on the static properties of GCC at build time, with a
consistent outcome.
As a belt and braces check, also do the initialization in <iostream> if
the compiler including that header doesn't support the attribute (even
if the library also containers the initialization). This might result in
redundant initialization done in <iostream>, but ensures the
initialization happens somewhere if there's any doubt about the
attribute working correctly due to missing linker support.
libstdc++-v3/ChangeLog:
PR libstdc++/110432
* acinclude.m4 (GLIBCXX_CHECK_INIT_PRIORITY): New.
* config.h.in: Regenerate.
* configure: Regenerate.
* configure.ac: Use GLIBCXX_CHECK_INIT_PRIORITY.
* include/std/iostream: Use new autoconf macro as well as
__has_attribute.
* src/c++98/ios_base_init.h: Use new autoconf macro instead of
__has_attribute.
Reviewed-by: Patrick Palka <ppalka@redhat.com>
Diffstat (limited to 'libstdc++-v3/configure')
-rwxr-xr-x | libstdc++-v3/configure | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/libstdc++-v3/configure b/libstdc++-v3/configure index 98568ae..c8d5508 100755 --- a/libstdc++-v3/configure +++ b/libstdc++-v3/configure @@ -73496,6 +73496,57 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu +# For using init_priority in ios_init.cc + + + ac_ext=cpp +ac_cpp='$CXXCPP $CPPFLAGS' +ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_cxx_compiler_gnu + + + { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether init_priority attribute is supported" >&5 +$as_echo_n "checking whether init_priority attribute is supported... " >&6; } + cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + +int +main () +{ + + #if ! __has_attribute(init_priority) + #error init_priority not supported + #endif + + ; + return 0; +} +_ACEOF +if ac_fn_cxx_try_compile "$LINENO"; then : + ac_init_priority=yes +else + ac_init_priority=no +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext + if test "$ac_init_priority" = yes; then + +cat >>confdefs.h <<_ACEOF +#define _GLIBCXX_USE_INIT_PRIORITY_ATTRIBUTE 1 +_ACEOF + + fi + { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_init_priority" >&5 +$as_echo "$ac_init_priority" >&6; } + + ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + + + # Define documentation rules conditionally. # See if makeinfo has been installed and is modern enough |