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.129.124]) by sourceware.org (Postfix) with ESMTPS id DEF3F3858428 for ; Fri, 4 Nov 2022 15:05:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DEF3F3858428 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=1667574334; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rmgUs23lKPlZ1uNaHMio3kywczEnXxr8ui/LdLG6yJE=; b=CmCtWubMLnJbXoHNbMCgLwqYLTf55QLzmTPBiWeNo3jIHaHjwAzWOLkyatXon5MhTDWCag XylPpYifIulTXzBYRs5t1whJHhIAlBWuf37Yv3oIhQacWM3SNuqdfmwAQXeANuFO4xjEhS IQi8W7qOryIDCNT6rpVi0LXHxPGUFZo= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-399-1CA3fFnwM7SqRzsXe9c3IQ-1; Fri, 04 Nov 2022 11:05:33 -0400 X-MC-Unique: 1CA3fFnwM7SqRzsXe9c3IQ-1 Received: by mail-qk1-f200.google.com with SMTP id j13-20020a05620a288d00b006be7b2a758fso4594654qkp.1 for ; Fri, 04 Nov 2022 08:05:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rmgUs23lKPlZ1uNaHMio3kywczEnXxr8ui/LdLG6yJE=; b=fhdGh8FC7WFQfMvgb/uz7ZYvFipwgTHy9T6te30ZJruLiy17Ig59RN2yHREMOM6zDa C8ZOXF8/BFDYl16g4mcbcV5hRrUpUTLdjiS97zMrvFGj009C1v4H5ppLxC8qT+6kQQG+ aJicHBoTT2HNL1OcLrMmSzPz9/bd7vxum6bJftYb6M+t3GKQO6E7C0b5vtecwiKX7ymf I6DqnQnkCeuwz8arZ66EJaxJLr5AX9nSlyJqRuFB5Eg0QhMusYF2zPX0BX2EuLNt+FrE FZ1XN7qq3jd907VgAlJlIvd/QfpxoysKM3arR3s22J0XeUDOQaomQfz/ZziC7oPiax9+ uugA== X-Gm-Message-State: ACrzQf15IxOFOcqbp2yqZqX/q9M2vD+RSvFDEpWK0z4873en2ZMb8vac GJgobUWjWtPO/IOROdkI4/WhTI/ixM6iPUj8qk792O1F6Z1F+z6sayz7DPauhTqOMW1xp+IgUWg dRLAFrxM4u/xEox4= X-Received: by 2002:a05:620a:f03:b0:6cf:c0a1:20bc with SMTP id v3-20020a05620a0f0300b006cfc0a120bcmr26069037qkl.663.1667574331561; Fri, 04 Nov 2022 08:05:31 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7zxDCKInO6R8o6BvkAxYVvPvy9QjiXiQWRe0e5vuH0tCMv1rPkvO8L5rfNfjdMWOS2gMBNrg== X-Received: by 2002:a05:620a:f03:b0:6cf:c0a1:20bc with SMTP id v3-20020a05620a0f0300b006cfc0a120bcmr26069020qkl.663.1667574331312; Fri, 04 Nov 2022 08:05:31 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id cx26-20020a05620a51da00b006fa12a74c53sm3018498qkb.61.2022.11.04.08.05.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 08:05:30 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, jason@redhat.com, Patrick Palka Subject: [PATCH 2/2] libstdc++: Move stream initialization into compiled library [PR44952] Date: Fri, 4 Nov 2022 11:05:25 -0400 Message-Id: <20221104150525.2968778-2-ppalka@redhat.com> X-Mailer: git-send-email 2.38.1.385.g3b08839926 In-Reply-To: <20221104150525.2968778-1-ppalka@redhat.com> References: <20221104150525.2968778-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-14.9 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_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This patch moves the global object for constructing the standard streams out from and into the compiled library on targets that support the init_priority attribute. This means that no longer introduces a separate global constructor in each TU that includes it. We can do this only if the init_priority attribute is supported because we need to force that the stream initialization runs first before any user-defined global initializer in programs that that use a static libstdc++.a. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look right? Unfortunately I don't have access to a system that truly doesn't support init priorities, so I instead tested that situation by artificially disabling the init_priority attribute on x86_64. PR libstdc++/44952 PR libstdc++/98108 libstdc++-v3/ChangeLog: * include/bits/c++config (_GLIBCXX_HAS_ATTRIBUTE): Define. (_GLIBCXX_HAVE_ATTRIBUTE_INIT_PRIORITY): Define. * include/std/iostream (__ioinit): Define only if init_priority attribute isn't usable. * src/c++98/ios_init.cc (__ioinit): Define here instead if the init_priority is usable. * src/c++98/ios_base_init.h: New file. --- libstdc++-v3/include/bits/c++config | 12 ++++++++++++ libstdc++-v3/include/std/iostream | 4 ++++ libstdc++-v3/src/c++98/ios_base_init.h | 9 +++++++++ libstdc++-v3/src/c++98/ios_init.cc | 4 ++++ 4 files changed, 29 insertions(+) create mode 100644 libstdc++-v3/src/c++98/ios_base_init.h diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config index 50406066afe..f93076191d9 100644 --- a/libstdc++-v3/include/bits/c++config +++ b/libstdc++-v3/include/bits/c++config @@ -837,6 +837,18 @@ namespace __gnu_cxx #undef _GLIBCXX_HAS_BUILTIN +#ifdef __has_attribute +# define _GLIBCXX_HAS_ATTRIBUTE(B) __has_attribute(B) +#else +# define _GLIBCXX_HAS_ATTRIBUTE(B) 0 +#endif + +#if _GLIBCXX_HAS_ATTRIBUTE(init_priority) +# define _GLIBCXX_HAVE_ATTRIBUTE_INIT_PRIORITY 1 +#endif + +#undef _GLIBCXX_HAS_ATTRIBUTE + // Mark code that should be ignored by the compiler, but seen by Doxygen. #define _GLIBCXX_DOXYGEN_ONLY(X) diff --git a/libstdc++-v3/include/std/iostream b/libstdc++-v3/include/std/iostream index 70318a45891..5eaa9755d9a 100644 --- a/libstdc++-v3/include/std/iostream +++ b/libstdc++-v3/include/std/iostream @@ -73,7 +73,11 @@ _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 (see src/c++98/ios_init.cc). +#if !_GLIBCXX_HAVE_ATTRIBUTE_INIT_PRIORITY static ios_base::Init __ioinit; +#endif _GLIBCXX_END_NAMESPACE_VERSION } // namespace diff --git a/libstdc++-v3/src/c++98/ios_base_init.h b/libstdc++-v3/src/c++98/ios_base_init.h new file mode 100644 index 00000000000..f3087d1da3c --- /dev/null +++ b/libstdc++-v3/src/c++98/ios_base_init.h @@ -0,0 +1,9 @@ +// This is only in a header so we can use the system_header pragma, +// to suppress the warning caused by using a reserved init_priority. +#pragma GCC system_header + +#if !_GLIBCXX_HAVE_ATTRIBUTE_INIT_PRIORITY +# error "This file should not be included for this build" +#endif + +static ios_base::Init __ioinit __attribute__((init_priority(90))); diff --git a/libstdc++-v3/src/c++98/ios_init.cc b/libstdc++-v3/src/c++98/ios_init.cc index 1b5132f1c2d..954fa9f29cf 100644 --- a/libstdc++-v3/src/c++98/ios_init.cc +++ b/libstdc++-v3/src/c++98/ios_init.cc @@ -75,6 +75,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION extern wostream wclog; #endif +#if _GLIBCXX_HAVE_ATTRIBUTE_INIT_PRIORITY +# include "ios_base_init.h" +#endif + ios_base::Init::Init() { if (__gnu_cxx::__exchange_and_add_dispatch(&_S_refcount, 1) == 0) -- 2.38.1.385.g3b08839926