From: Jonathan Wakely Date: Tue, 15 Dec 2020 11:40:06 +0000 (+0000) Subject: libstdc++: Use init_priority attribute for Init object [PR 98108] X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=cf4ed3b41594b6935a337fe0aaf8149eadf88751;p=gcc.git libstdc++: Use init_priority attribute for Init object [PR 98108] This causes the global objects that run the initialization code to be constructed earlier, which avoids some bugs in user code due to incorrectly relying on static initialization order. libstdc++-v3/ChangeLog: PR libstdc++/98108 * include/std/iostream (__ioinit): Add init_priority attribute. --- diff --git a/libstdc++-v3/include/std/iostream b/libstdc++-v3/include/std/iostream index f988342b90a..6b2f964f688 100644 --- a/libstdc++-v3/include/std/iostream +++ b/libstdc++-v3/include/std/iostream @@ -70,8 +70,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #endif //@} +#if __has_attribute(__init_priority__) +# define _GLIBCXX_INIT_PRIO(N) __attribute__((__init_priority__(N))) +#else +# define _GLIBCXX_INIT_PRIO(N) +#endif + // For construction of filebuffers for cout, cin, cerr, clog et. al. - static ios_base::Init __ioinit; + static ios_base::Init __ioinit _GLIBCXX_INIT_PRIO(90); + +#undef _GLIBCXX_INIT_PRIO _GLIBCXX_END_NAMESPACE_VERSION } // namespace