| 1 |
// Copyright (C) 2001-2025 Free Software Foundation, Inc. |
| 2 |
// |
| 3 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 4 |
// software; you can redistribute it and/or modify it under the |
| 5 |
// terms of the GNU General Public License as published by the |
| 6 |
// Free Software Foundation; either version 3, or (at your option) |
| 7 |
// any later version. |
| 8 |
|
| 9 |
// This library is distributed in the hope that it will be useful, |
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
// GNU General Public License for more details. |
| 13 |
|
| 14 |
// Under Section 7 of GPL version 3, you are granted additional |
| 15 |
// permissions described in the GCC Runtime Library Exception, version |
| 16 |
// 3.1, as published by the Free Software Foundation. |
| 17 |
|
| 18 |
// You should have received a copy of the GNU General Public License and |
| 19 |
// a copy of the GCC Runtime Library Exception along with this program; |
| 20 |
// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see |
| 21 |
// <http://www.gnu.org/licenses/>. |
| 22 |
|
| 23 |
#include "bits/c++config.h" |
| 24 |
#include <fstream> |
| 25 |
#include <istream> |
| 26 |
#include <ostream> |
| 27 |
#include <ext/stdio_filebuf.h> |
| 28 |
#include <ext/stdio_sync_filebuf.h> |
| 29 |
|
| 30 |
// On AIX, and perhaps other systems, library initialization order is |
| 31 |
// not guaranteed. For example, the static initializers for the main |
| 32 |
// program might run before the static initializers for this library. |
| 33 |
// That means that we cannot rely on static initialization in the |
| 34 |
// library; there is no guarantee that things will get initialized in |
| 35 |
// time. This file contains definitions of all global variables that |
| 36 |
// require initialization as arrays of characters. |
| 37 |
|
| 38 |
// NB: asm directives can rename these non-exported, namespace |
| 39 |
// __gnu_cxx symbols into exported, namespace std symbols with the |
| 40 |
// appropriate symbol version name. |
| 41 |
// The rename syntax is |
| 42 |
// asm (".symver currentname,oldname@@GLIBCXX_3.2") |
| 43 |
// In macro form: |
| 44 |
// _GLIBCXX_ASM_SYMVER(currentname, oldname, GLIBCXX_3.2) |
| 45 |
|
| 46 |
namespace std _GLIBCXX_VISIBILITY(default) |
| 47 |
{ |
| 48 |
_GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 49 |
|
| 50 |
// Standard stream objects. |
| 51 |
// NB: Iff <iostream> is included, these definitions become wonky. |
| 52 |
typedef char fake_istream[sizeof(istream)] |
| 53 |
__attribute__ ((aligned(__alignof__(istream)))); |
| 54 |
typedef char fake_ostream[sizeof(ostream)] |
| 55 |
__attribute__ ((aligned(__alignof__(ostream)))); |
| 56 |
fake_istream cin; |
| 57 |
fake_ostream cout; |
| 58 |
fake_ostream cerr; |
| 59 |
fake_ostream clog; |
| 60 |
|
| 61 |
#ifdef _GLIBCXX_USE_WCHAR_T |
| 62 |
typedef char fake_wistream[sizeof(wistream)] |
| 63 |
__attribute__ ((aligned(__alignof__(wistream)))); |
| 64 |
typedef char fake_wostream[sizeof(wostream)] |
| 65 |
__attribute__ ((aligned(__alignof__(wostream)))); |
| 66 |
fake_wistream wcin; |
| 67 |
fake_wostream wcout; |
| 68 |
fake_wostream wcerr; |
| 69 |
fake_wostream wclog; |
| 70 |
#endif |
| 71 |
|
| 72 |
// If the target supports init priorities, set up a static object in the |
| 73 |
// compiled library to perform the <iostream> initialization once and |
| 74 |
// sufficiently early (so that it happens before any other global |
| 75 |
// constructor when statically linking with libstdc++.a), instead of |
| 76 |
// doing so in (each TU that includes) <iostream>. |
| 77 |
// This needs to be done in the same TU that defines the stream objects. |
| 78 |
#if _GLIBCXX_USE_INIT_PRIORITY_ATTRIBUTE |
| 79 |
#pragma GCC diagnostic ignored "-Wprio-ctor-dtor" |
| 80 |
static ios_base::Init __ioinit __attribute__((init_priority(90))); |
| 81 |
#endif |
| 82 |
|
| 83 |
_GLIBCXX_END_NAMESPACE_VERSION |
| 84 |
} // namespace |
| 85 |
|
| 86 |
namespace __gnu_internal _GLIBCXX_VISIBILITY(hidden) |
| 87 |
{ |
| 88 |
using namespace std; |
| 89 |
using namespace __gnu_cxx; |
| 90 |
|
| 91 |
// We use different stream buffer types depending on whether |
| 92 |
// ios_base::sync_with_stdio(false) has been called. |
| 93 |
typedef char fake_stdiobuf[sizeof(stdio_sync_filebuf<char>)] |
| 94 |
__attribute__ ((aligned(__alignof__(stdio_sync_filebuf<char>)))); |
| 95 |
fake_stdiobuf buf_cout_sync; |
| 96 |
fake_stdiobuf buf_cin_sync; |
| 97 |
fake_stdiobuf buf_cerr_sync; |
| 98 |
|
| 99 |
typedef char fake_filebuf[sizeof(stdio_filebuf<char>)] |
| 100 |
__attribute__ ((aligned(__alignof__(stdio_filebuf<char>)))); |
| 101 |
fake_filebuf buf_cout; |
| 102 |
fake_filebuf buf_cin; |
| 103 |
fake_filebuf buf_cerr; |
| 104 |
|
| 105 |
#ifdef _GLIBCXX_USE_WCHAR_T |
| 106 |
typedef char fake_wstdiobuf[sizeof(stdio_sync_filebuf<wchar_t>)] |
| 107 |
__attribute__ ((aligned(__alignof__(stdio_sync_filebuf<wchar_t>)))); |
| 108 |
fake_wstdiobuf buf_wcout_sync; |
| 109 |
fake_wstdiobuf buf_wcin_sync; |
| 110 |
fake_wstdiobuf buf_wcerr_sync; |
| 111 |
|
| 112 |
typedef char fake_wfilebuf[sizeof(stdio_filebuf<wchar_t>)] |
| 113 |
__attribute__ ((aligned(__alignof__(stdio_filebuf<wchar_t>)))); |
| 114 |
fake_wfilebuf buf_wcout; |
| 115 |
fake_wfilebuf buf_wcin; |
| 116 |
fake_wfilebuf buf_wcerr; |
| 117 |
#endif |
| 118 |
} // namespace __gnu_internal |