libstdc++/16: ios initialization bug

Chad_Gibbons@bmc.com Chad_Gibbons@bmc.com
Mon Nov 22 10:57:00 GMT 1999


>Number:         16
>Category:       libstdc++
>Synopsis:       ios initialization bug
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Mon Nov 22 10:57:00 PST 1999
>Closed-Date:
>Last-Modified:
>Originator:     Chad_Gibbons@bmc.com
>Release:        2.90.6
>Organization:
>Environment:
sparc Solaris 7, gcc 2.95.0 / 2.95.2, gld 2.9
>Description:
While using v2.90.6 of libstdc++, I have run into a situation where the normal startup of the I/O stream library is run out of order. I believe this might be the result of an incorrect assumption in the library.

If <iostream> is included in any module, a static member is added from std_iostream.h:
    // For construction of filebuffers for cout, cin, cerr, clog et. al.
    static ios_base::Init __ioinit;

The constructor for this object creates the file buffers for the standard I/O stream objects and sets their references via rdbuf. If, however, the constructors for those standard I/O stream objects occurs after the first
call to ios_base::Init::Init(), then the pointers to these buffers are overridden and all stream operations via those objects are disabled.

In practice, I have only seen this in extremely large projects (on the order of 50,000 symbols). For whatever Reason, the compiler/linker selects several modules that are initialized before the libstdc++ modules. These modules
have no static data, no references to static objects, and are themselves not referenced statically -- they just happen to include <iostream>.

In any event, it seems the library is relying on the compiler to construct cout/cin/etc. before ios_base::Init is constructed, and that is something the language doesn't guarantee (I believe).

>How-To-Repeat:
I have not been able to cause the ctor list to be created in a way that exhibits this behavior unless a large project is built.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


More information about the Libstdc++-prs mailing list