[Bug libstdc++/107701] [13 Regression] static linking broken when using iostream

cvs-commit at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Wed Nov 16 13:54:00 GMT 2022


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.


More information about the Gcc-bugs mailing list