From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 895F73855583 for ; Fri, 30 Jun 2023 14:38:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 895F73855583 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688135890; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=kJPO4YUeDNNgiB3CmqREP7ONtE9h1nLxZz9U2L3e8fI=; b=LQ0pLI4UGbWmOPHx+nIS+A4qki7VAisndUltI3y4WkBgm20XI8+cI/okGVKJEpkzHTnkyJ UvEGA1omhT+ipg9YUQqPB/Q5D+jfRty9Zp1wTkQaIiayyW7vXS9TuuklHMl7mOgljtq/4D vkR4HEq5jhsz1QsJdQ23CtQosAQTiuY= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-632-ChEFUyaBMGSOySphT19CRw-1; Fri, 30 Jun 2023 10:38:09 -0400 X-MC-Unique: ChEFUyaBMGSOySphT19CRw-1 Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-2b6ae3cb20cso19623731fa.3 for ; Fri, 30 Jun 2023 07:38:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688135887; x=1690727887; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kJPO4YUeDNNgiB3CmqREP7ONtE9h1nLxZz9U2L3e8fI=; b=NGzMbPdsv6hzeA+VUX7cK0I8wttZu2wU3EOZYGPTgG5bEqYZZsN52zB5w6ABdXDXik ZTdSwUFvjpT52qqaQE45aAstZrz1LROZptqY12AmTPzPV1nXdqNJLSmA9pQmBkTjYvY5 JeIXXpXhOiHLtfuZPUbE5g5WT2oedozMs9WPPT3WSNhG5Tt5abgntVI+5J0ti3+wwh/+ Ks4/iXMvQPI8XERYA1v+VIodpkqE6e3/gzF2WelGh0vLBRrvMB/XkjRJNL0aM6B60/2R 6wAgv44OkWaMx33H5k7qT653C/19xlT7SWe409CPZqpC/ogFFodLshHoBJVEUT/VV8Oy 1GuA== X-Gm-Message-State: ABy/qLb3YNPwoH5tSsj3EbxGkPOVy3a6NDwzNJMpDn0ZDVECm9Q+MEUQ WC7LiWgVio77orsyb411mX5wu5d6AV0VI6RxWsrUbaXFAYWhr8fVWJTuua+AWXEhuA7JAjCHTlY ZhOYfJJjTFlL+pwm8gGr+UmJ2xErXMgw= X-Received: by 2002:a2e:700e:0:b0:2b6:a2dc:7681 with SMTP id l14-20020a2e700e000000b002b6a2dc7681mr2559126ljc.6.1688135887521; Fri, 30 Jun 2023 07:38:07 -0700 (PDT) X-Google-Smtp-Source: APBJJlFLgigidkptdyT6QNXfvti8bRuZaU1zxjTXvuJV/06SVhjSmj/a6woaM9UcGiUDcF7grnIi0+bWhv/5PTqsWKU= X-Received: by 2002:a2e:700e:0:b0:2b6:a2dc:7681 with SMTP id l14-20020a2e700e000000b002b6a2dc7681mr2559113ljc.6.1688135887221; Fri, 30 Jun 2023 07:38:07 -0700 (PDT) MIME-Version: 1.0 References: <20230630141131.716948-1-jwakely@redhat.com> In-Reply-To: From: Jonathan Wakely Date: Fri, 30 Jun 2023 15:37:55 +0100 Message-ID: Subject: Re: [PATCH] libstdc++: Fix iostream init for Clang on darwin [PR110432] To: Patrick Palka Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Fri, 30 Jun 2023 at 15:29, Patrick Palka wrote: > > On Fri, 30 Jun 2023, Jonathan Wakely wrote: > > > Tested x86_64-linux. Patrick, PTAL. > > > > -- >8 -- > > > > The __has_attribute(init_priority) check in is true for Clang > > on darwin, which means that user code including 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 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 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 , 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: > > Missing ChangeLog entry? > > > * src/c++98/ios_base_init.h: Use new autoconf macro instead of > > __has_attribute. > > --- > > libstdc++-v3/acinclude.m4 | 27 ++++++++++++++ > > libstdc++-v3/config.h.in | 3 ++ > > libstdc++-v3/configure | 51 ++++++++++++++++++++++++++ > > libstdc++-v3/configure.ac | 3 ++ > > libstdc++-v3/include/std/iostream | 2 +- > > libstdc++-v3/src/c++98/ios_base_init.h | 2 +- > > 6 files changed, 86 insertions(+), 2 deletions(-) > > > > diff --git a/libstdc++-v3/acinclude.m4 b/libstdc++-v3/acinclude.m4 > > index 277ae10e031..823832f97d4 100644 > > --- a/libstdc++-v3/acinclude.m4 > > +++ b/libstdc++-v3/acinclude.m4 > > @@ -5680,6 +5680,33 @@ AC_DEFUN([GLIBCXX_CHECK_ALIGNAS_CACHELINE], [ > > AC_LANG_RESTORE > > ]) > > > > +dnl > > +dnl Check whether iostream initialization should be done in the library, > > +dnl using the init_priority attribute. > > +dnl > > +dnl Defines: > > +dnl _GLIBCXX_USE_INIT_PRIORITY_ATTRIBUTE if GCC supports the init_priority > > +dnl attribute for the target. > > +dnl > > +AC_DEFUN([GLIBCXX_CHECK_INIT_PRIORITY], [ > > +AC_LANG_SAVE > > + AC_LANG_CPLUSPLUS > > + > > + AC_MSG_CHECKING([whether init_priority attribute is supported]) > > + AC_TRY_COMPILE(, [ > > + #if ! __has_attribute(init_priority) > > + #error init_priority not supported > > + #endif > > + ], [ac_init_priority=yes], [ac_init_priority=no]) > > + if test "$ac_init_priority" = yes; then > > + AC_DEFINE_UNQUOTED(_GLIBCXX_USE_INIT_PRIORITY_ATTRIBUTE, 1, > > + [Define if init_priority should be used for iostream initialization.]) > > + fi > > + AC_MSG_RESULT($ac_init_priority) > > + > > + AC_LANG_RESTORE > > +]) > > + > > # Macros from the top-level gcc directory. > > m4_include([../config/gc++filt.m4]) > > m4_include([../config/tls.m4]) > > diff --git a/libstdc++-v3/configure.ac b/libstdc++-v3/configure.ac > > index 9770c178767..fc0f2522027 100644 > > --- a/libstdc++-v3/configure.ac > > +++ b/libstdc++-v3/configure.ac > > @@ -550,6 +550,9 @@ GLIBCXX_ZONEINFO_DIR > > # For src/c++11/shared_ptr.cc alignment. > > GLIBCXX_CHECK_ALIGNAS_CACHELINE > > > > +# For using init_priority in ios_init.cc > > +GLIBCXX_CHECK_INIT_PRIORITY > > + > > # Define documentation rules conditionally. > > > > # See if makeinfo has been installed and is modern enough > > diff --git a/libstdc++-v3/include/std/iostream b/libstdc++-v3/include/std/iostream > > index cfd124dcf43..ec337cf89dd 100644 > > --- a/libstdc++-v3/include/std/iostream > > +++ b/libstdc++-v3/include/std/iostream > > @@ -75,7 +75,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > > // For construction of filebuffers for cout, cin, cerr, clog et. al. > > // When the init_priority attribute is usable, we do this initialization > > // in the compiled library instead (src/c++98/globals_io.cc). > > -#if !__has_attribute(__init_priority__) > > +#if !(_GLIBCXX_USE_INIT_PRIORITY_ATTRIBUTE && __has_attribute(init_priority)) > > This should check __init_priority__ since init_priority is a non-reserved > name I think? LGTM otherwise. Thanks, fixed and pushed to trunk. Backport to gcc-13 to follow.