[RTEMS Project] #3012: Global C++ IO streams are broken (cout, cin, cerr)
RTEMS trac
trac at rtems.org
Tue May 9 08:57:53 UTC 2017
#3012: Global C++ IO streams are broken (cout, cin, cerr)
-----------------------------+-------------------------
Reporter: Sebastian Huber | Owner: Chris Johns
Type: defect | Status: assigned
Priority: normal | Milestone: Indefinite
Component: GCC | Version: 4.12
Severity: normal | Keywords:
-----------------------------+-------------------------
The global C++ IO stream objects are initialized here
https://gcc.gnu.org/viewcvs/gcc/trunk/libstdc%2B%2B-v3/src/c%2B%2B98/ios_init.cc?view=markup#l85
via a placement new. The "stdout" etc. is thread-local in Newlib
{{{
#define stdout (_REENT->_stdout)
}}}
Using this for a global object like std::cout is quite broken. Which FILE
object should be used instead? Potential fix:
{{{
diff --git a/libstdc++-v3/src/c++98/ios_init.cc
b/libstdc++-v3/src/c++98/ios_init.cc
index c5bcc83..7470c44 100644
--- a/libstdc++-v3/src/c++98/ios_init.cc
+++ b/libstdc++-v3/src/c++98/ios_init.cc
@@ -33,6 +33,15 @@
#include <ext/stdio_filebuf.h>
#include <ext/stdio_sync_filebuf.h>
+#ifdef __rtems__
+#undef stdout
+#undef stdin
+#undef stderr
+#define stdout (_GLOBAL_REENT->_stdout)
+#define stdin (_GLOBAL_REENT->_stdout)
+#define stderr (_GLOBAL_REENT->_stdout)
+#endif
+
namespace __gnu_internal _GLIBCXX_VISIBILITY(hidden)
{
using namespace __gnu_cxx;
}}}
{{{
diff --git a/newlib/libc/stdio/findfp.c b/newlib/libc/stdio/findfp.c
index 83d3dc5..7d50951 100644
--- a/newlib/libc/stdio/findfp.c
+++ b/newlib/libc/stdio/findfp.c
@@ -259,6 +259,12 @@ _DEFUN(__sinit, (s),
__sinit_lock_release ();
}
+static void __attribute__((__constructor__(0)))
+_global_reent_init(void)
+{
+ __sinit (_GLOBAL_REENT);
+}
+
#ifndef __SINGLE_THREAD__
__LOCK_INIT_RECURSIVE(static, __sfp_recursive_mutex);
}}}
--
Ticket URL: <http://devel.rtems.org/ticket/3012>
RTEMS Project <http://www.rtems.org/>
RTEMS Project
More information about the bugs
mailing list