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 AD2193959E73 for ; Wed, 16 Nov 2022 12:40:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AD2193959E73 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=1668602421; 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=Xqa6Sf+2+DCuFHen1L5dIO1/Us4ZTgd/7kPUUfavimo=; b=S/SHT2zzLhmK3QYbZQjQxv/roF9+g4mQ8h87s3eaeb+qNB0TNGyuzIbyggzoXvxnCJNd/X zP+s5DebpDQ/Ovboze664KBW6py57AUhB3S05Cf4ciEmd5nMZ5KZpJkNMV42/yTmCJkKb5 ba8s5qX8v7glR5+30Ev+DmCytEWsfa0= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-520-wf-EqqiwNUqkLmxWcNpWjg-1; Wed, 16 Nov 2022 07:40:20 -0500 X-MC-Unique: wf-EqqiwNUqkLmxWcNpWjg-1 Received: by mail-ed1-f70.google.com with SMTP id z9-20020a05640235c900b0046358415c4fso12160764edc.9 for ; Wed, 16 Nov 2022 04:40:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=Xqa6Sf+2+DCuFHen1L5dIO1/Us4ZTgd/7kPUUfavimo=; b=kg5fSLXba0sfjovtYovTjBoOYCqjuggtGUHVU3A+wUUkcDt1V+qVo243+5eMgu+6tt SF2+OW9l/sjP50tzbI4KxUsd1fCJqRHHdnYXmtyn/A1R5r4VMksXcH1Vd1mPu2yOHTOg gJkKVtdMU1kaMRblLnUr3a/aQypRnxawJ3A2UxGGbu0uLuWxGVpha1jV4nK7IZoKOTPf EqmVLRDKQ2YEveKv6yZFwGwV/GLGREtuC7NCF8vTtHOCyZkCelu0PzopSmQ5ik94qUac 1xN9LJMR54qbpb7DqCdHpYON+CHyqqqFMy1fE7KB5M4A2x7KTUid0ycPt69qCtI8s1LC STZg== X-Gm-Message-State: ANoB5plT1H6CZSnzDgN5zkT9RGbikbfOfOUyvpIZ3D1BlXzqNfz6XFgg 41zTKHzeznNw4fah0M+qk9acfo/v+IZOBdnsuvWJwConv051/mLRNfE/dN4cyTDQ4LAXmN9jUc0 08RQg0L1uL28cpHuNePSxmDDrujElBq8= X-Received: by 2002:a17:906:1c85:b0:7ae:ca2f:171d with SMTP id g5-20020a1709061c8500b007aeca2f171dmr16560091ejh.353.1668602419002; Wed, 16 Nov 2022 04:40:19 -0800 (PST) X-Google-Smtp-Source: AA0mqf4nhBq2jdVn10+o7Grcpyd3TuuQaqsCBggT3RDyll3e4jsVO5KR9qr2HA7Kb+B1Q/efYvDJiDMc13Ss0sDc3W4= X-Received: by 2002:a17:906:1c85:b0:7ae:ca2f:171d with SMTP id g5-20020a1709061c8500b007aeca2f171dmr16560082ejh.353.1668602418750; Wed, 16 Nov 2022 04:40:18 -0800 (PST) MIME-Version: 1.0 References: <20221116024619.1465996-1-ppalka@redhat.com> In-Reply-To: From: Jonathan Wakely Date: Wed, 16 Nov 2022 12:40:07 +0000 Message-ID: Subject: Re: [PATCH] libstdc++: Fix stream initialization with static library [PR107701] 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=-12.3 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=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 Wed, 16 Nov 2022 at 10:55, Jonathan Wakely wrote: > > On Wed, 16 Nov 2022 at 02:46, Patrick Palka via Libstdc++ > wrote: > > > > When linking with a static library, the linker seems to exclude a > > constituent .o object (including its global initializers) if nothing > > from it is referenced by the program (unless e.g. --whole-archive is > > used). This behavior breaks iostream when linking with static libstdc++.a > > (on systems that support init priorities) because we're defining the > > global initializer for the standard stream objects in a separate TU > > (ios_init.cc) from the stream objects definitions (globals_io.cc). > > > > Thus in order to ensure that the global initializer for the standard > > stream objects doesn't get wrongly dropped when statically linking, > > we need to perform the initialization from the same TU that actually > > defines the stream objects. > > > > Tested on x86_64-pc-linux-gnu, does this look OK for trunk? > > OK, thanks. Oops, I missed the v2. That's definitely better with the improve comments. OK for v2. > > I'm a little nervous that future improvements to --gc-sections or LTO > could cause the same problem, but I think we're OK for now. > > > > > > PR libstdc++/107701 > > > > libstdc++-v3/ChangeLog: > > > > * src/c++98/globals_io.cc: Include "io_base_init.h" here > > instead of ... > > * src/c++98/ios_init.cc: ... here. > > * testsuite/17_intro/static.cc: Run the test as well. > > --- > > libstdc++-v3/src/c++98/globals_io.cc | 2 ++ > > libstdc++-v3/src/c++98/ios_init.cc | 2 -- > > libstdc++-v3/testsuite/17_intro/static.cc | 2 +- > > 3 files changed, 3 insertions(+), 3 deletions(-) > > > > diff --git a/libstdc++-v3/src/c++98/globals_io.cc b/libstdc++-v3/src/c++98/globals_io.cc > > index 04fecb22aeb..bfd808b5bbd 100644 > > --- a/libstdc++-v3/src/c++98/globals_io.cc > > +++ b/libstdc++-v3/src/c++98/globals_io.cc > > @@ -69,6 +69,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > > fake_wostream wclog; > > #endif > > > > +#include "ios_base_init.h" > > + > > _GLIBCXX_END_NAMESPACE_VERSION > > } // namespace > > > > diff --git a/libstdc++-v3/src/c++98/ios_init.cc b/libstdc++-v3/src/c++98/ios_init.cc > > index 4016fcab785..1b5132f1c2d 100644 > > --- a/libstdc++-v3/src/c++98/ios_init.cc > > +++ b/libstdc++-v3/src/c++98/ios_init.cc > > @@ -75,8 +75,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > > extern wostream wclog; > > #endif > > > > -#include "ios_base_init.h" > > - > > ios_base::Init::Init() > > { > > if (__gnu_cxx::__exchange_and_add_dispatch(&_S_refcount, 1) == 0) > > diff --git a/libstdc++-v3/testsuite/17_intro/static.cc b/libstdc++-v3/testsuite/17_intro/static.cc > > index ffa7ecb7077..a0d6ed081f8 100644 > > --- a/libstdc++-v3/testsuite/17_intro/static.cc > > +++ b/libstdc++-v3/testsuite/17_intro/static.cc > > @@ -1,4 +1,4 @@ > > -// { dg-do link { target c++11 } } > > +// { dg-do run { target c++11 } } > > // { dg-require-static-libstdcxx } > > // { dg-options "-static-libstdc++" } > > > > -- > > 2.38.1.436.geea7033409 > >