public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/107701] New: [13 Regression] static linking broken when using iostream
@ 2022-11-15 16:01 hp at gcc dot gnu.org
  2022-11-15 16:22 ` [Bug libstdc++/107701] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: hp at gcc dot gnu.org @ 2022-11-15 16:01 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107701

            Bug ID: 107701
           Summary: [13 Regression] static linking broken when using
                    iostream
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hp at gcc dot gnu.org
                CC: ppalka at gcc dot gnu.org
  Target Milestone: ---

Since r13-3707-g4e4e3ffd10f53e, static linking with iostreams has been broken.

This affects most "embedded" targets (the "*-elf" and "*-eabi" ones; the "vast
majority" that don't do dynamic linking) but also plain -static.

For a repeater, run "make check-gcc-c++
'RUNTESTFLAGS=--target_board=unix/-static old-deja.exp=15071.C'" a trivial
test-case which just does cout << "hi" << endl;.
This works before r13-3707-g4e4e3ffd10f53e but SEGV's afterwards, in my case
"Debian 11" x86_64, but expected to manifest on any native build.

(BTW, looks like we miss a specific test-case exercising static linking at
least with iostreams.)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/107701] [13 Regression] static linking broken when using iostream
  2022-11-15 16:01 [Bug libstdc++/107701] New: [13 Regression] static linking broken when using iostream hp at gcc dot gnu.org
@ 2022-11-15 16:22 ` pinskia at gcc dot gnu.org
  2022-11-15 17:43 ` ppalka at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-15 16:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107701

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |13.0
           Keywords|                            |wrong-code

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/107701] [13 Regression] static linking broken when using iostream
  2022-11-15 16:01 [Bug libstdc++/107701] New: [13 Regression] static linking broken when using iostream hp at gcc dot gnu.org
  2022-11-15 16:22 ` [Bug libstdc++/107701] " pinskia at gcc dot gnu.org
@ 2022-11-15 17:43 ` ppalka at gcc dot gnu.org
  2022-11-16  2:05 ` ppalka at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-11-15 17:43 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107701

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2022-11-15

--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
D'oh, not sure how I missed this.  For some reason, the ios_base::Init __ioinit
initializer disappears when statically linking.

$ nm libstdc++.a | grep _GLOBAL__sub
0000000000000000 t _GLOBAL__sub_I_eh_alloc.cc
0000000000000000 t _GLOBAL__sub_I_bitmap_allocator.cc
0000000000000000 t _GLOBAL__sub_I.00090_ios_init.cc
0000000000000000 t _GLOBAL__sub_I_parallel_settings.cc
0000000000000000 t _GLOBAL__sub_I_cxx11_locale_inst.cc
0000000000000000 t _GLOBAL__sub_I_cxx11_wlocale_inst.cc
0000000000000000 t _GLOBAL__sub_I_future.cc
0000000000000000 t _GLOBAL__sub_I_ios_errcat.cc
0000000000000000 t _GLOBAL__sub_I_locale_inst.cc
0000000000000000 t _GLOBAL__sub_I_system_error.cc
0000000000000000 t _GLOBAL__sub_I_wlocale_inst.cc
0000000000000000 t _GLOBAL__sub_I_memory_resource.cc
$ ./a.out # g++ -static gcc/testsuite/g++.old-deja/g++.benjamin/15071.C
Segmentation fault
$ nm a.out | grep _GLOBAL__sub
0000000000403c00 t _GLOBAL__sub_I_cxx11_locale_inst.cc
0000000000403c80 t _GLOBAL__sub_I_cxx11_wlocale_inst.cc
0000000000403a10 t _GLOBAL__sub_I_eh_alloc.cc
0000000000403d00 t _GLOBAL__sub_I_ios_errcat.cc
0000000000403890 t _GLOBAL__sub_I_locale_inst.cc
0000000000403d20 t _GLOBAL__sub_I_system_error.cc
0000000000403950 t _GLOBAL__sub_I_wlocale_inst.cc

I'm not sure why some global initializers (notably
_GLOBAL__sub_I.00090_ios_init.cc) are missing in the statically linked
executable vs libstdc++.a?

If we define the __ioinit object in e.g. c++11/ios_errcat.cc instead of
c++98/ios_init.cc then the ios_base::Init initializer runs and static linking
works, not sure why that is.

diff --git a/libstdc++-v3/src/c++11/ios_errcat.cc
b/libstdc++-v3/src/c++11/ios_errcat.cc
index 12192447b8b..aa778810009 100644
--- a/libstdc++-v3/src/c++11/ios_errcat.cc
+++ b/libstdc++-v3/src/c++11/ios_errcat.cc
@@ -76,6 +76,8 @@ namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION

+#include "../c++98/ios_base_init.h"
+
   const error_category&
   iostream_category() noexcept
   { return io_category_instance.cat; }
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)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/107701] [13 Regression] static linking broken when using iostream
  2022-11-15 16:01 [Bug libstdc++/107701] New: [13 Regression] static linking broken when using iostream hp at gcc dot gnu.org
  2022-11-15 16:22 ` [Bug libstdc++/107701] " pinskia at gcc dot gnu.org
  2022-11-15 17:43 ` ppalka at gcc dot gnu.org
@ 2022-11-16  2:05 ` ppalka at gcc dot gnu.org
  2022-11-16 13:54 ` cvs-commit at gcc dot gnu.org
  2022-11-16 14:29 ` rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: ppalka at gcc dot gnu.org @ 2022-11-16  2:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107701

Patrick Palka <ppalka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |ppalka at gcc dot gnu.org

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/107701] [13 Regression] static linking broken when using iostream
  2022-11-15 16:01 [Bug libstdc++/107701] New: [13 Regression] static linking broken when using iostream hp at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2022-11-16  2:05 ` ppalka at gcc dot gnu.org
@ 2022-11-16 13:54 ` cvs-commit at gcc dot gnu.org
  2022-11-16 14:29 ` rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-11-16 13:54 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107701

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Patrick Palka <ppalka@gcc.gnu.org>:

https://gcc.gnu.org/g:ec59848074ba8c4310cbadb603822bfaeff03a32

commit r13-4098-gec59848074ba8c4310cbadb603822bfaeff03a32
Author: Patrick Palka <ppalka@redhat.com>
Date:   Wed Nov 16 08:53:51 2022 -0500

    libstdc++: Fix stream initialization with static library [PR107701]

    When linking with a static library, the linker seems to discard a
    constituent .o object (including its global initializers) if nothing
    defined in the object is referenced by the program (unless e.g.
    --whole-archive is used).  This behavior breaks iostream with static
    libstdc++.a (on systems that support init priorities) because we define
    the global initializer for the standard stream objects in a separate TU
    (ios_init.cc) from the stream object definitions (globals_io.cc).

    This patch fixes this by moving the stream initialization object into
    the same TU that defines the stream objects, so that any use of the
    streams prevents the linker from discarding this global initializer.

            PR libstdc++/107701

    libstdc++-v3/ChangeLog:

            * include/std/iostream (__ioinit): Adjust comment.
            * src/c++98/globals_io.cc: Include "io_base_init.h" here
            instead of ...
            * src/c++98/ios_init.cc: ... here.
            * src/c++98/ios_base_init.h (__ioinit): More comments.
            * testsuite/17_intro/static.cc: dg-do run instead of just link.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/107701] [13 Regression] static linking broken when using iostream
  2022-11-15 16:01 [Bug libstdc++/107701] New: [13 Regression] static linking broken when using iostream hp at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2022-11-16 13:54 ` cvs-commit at gcc dot gnu.org
@ 2022-11-16 14:29 ` rguenth at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-11-16 14:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107701

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-11-16 14:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-15 16:01 [Bug libstdc++/107701] New: [13 Regression] static linking broken when using iostream hp at gcc dot gnu.org
2022-11-15 16:22 ` [Bug libstdc++/107701] " pinskia at gcc dot gnu.org
2022-11-15 17:43 ` ppalka at gcc dot gnu.org
2022-11-16  2:05 ` ppalka at gcc dot gnu.org
2022-11-16 13:54 ` cvs-commit at gcc dot gnu.org
2022-11-16 14:29 ` rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).