-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc++] Fix initialization-order-fiasco with iostream.cpp constructors #126995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
baed235
c8f9626
f9fba09
295c292
08cb293
6a98752
155b9d5
0ca1b2a
8a7368c
aa819e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD | |
|
||
template <class StreamT, class BufferT> | ||
union stream_data { | ||
stream_data() {} | ||
~stream_data() {} | ||
constexpr stream_data() {} | ||
constexpr ~stream_data() {} | ||
struct { | ||
// The stream has to be the first element, since that's referenced by the stream declarations in <iostream> | ||
StreamT stream; | ||
|
@@ -38,13 +38,19 @@ union stream_data { | |
#define CHAR_MANGLING_wchar_t "_W" | ||
#define CHAR_MANGLING(CharT) CHAR_MANGLING_##CharT | ||
|
||
#ifdef _LIBCPP_COMPILER_CLANG_BASED | ||
# define STRING_DATA_CONSTINIT constinit | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can't figure out how to make GCC happy, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm. I'll try to figure something out tomorrow for this. Either a bug against one of the compilers or some code changes should happen here. I guess a CWG issue would also be possible. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we land this one in meantime? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fine with that. |
||
#else | ||
# define STRING_DATA_CONSTINIT | ||
#endif | ||
|
||
#ifdef _LIBCPP_ABI_MICROSOFT | ||
# define STREAM(StreamT, BufferT, CharT, var) \ | ||
stream_data<StreamT<CharT>, BufferT<CharT>> var __asm__( \ | ||
STRING_DATA_CONSTINIT stream_data<StreamT<CharT>, BufferT<CharT>> var __asm__( \ | ||
"?" #var "@" ABI_NAMESPACE_STR "@std@@3V?$" #StreamT \ | ||
"@" CHAR_MANGLING(CharT) "U?$char_traits@" CHAR_MANGLING(CharT) "@" ABI_NAMESPACE_STR "@std@@@12@A") | ||
#else | ||
# define STREAM(StreamT, BufferT, CharT, var) stream_data<StreamT<CharT>, BufferT<CharT>> var | ||
# define STREAM(StreamT, BufferT, CharT, var) STRING_DATA_CONSTINIT stream_data<StreamT<CharT>, BufferT<CharT>> var | ||
#endif | ||
|
||
// These definitions and the declarations in <iostream> technically cause ODR violations, since they have different | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include <iostream> | ||
|
||
// FIXME: Remove after issue https://github.com/llvm/llvm-project/issues/127348 resolved. | ||
extern "C" const char* __asan_default_options() { return "check_initialization_order=true:strict_init_order=true"; } | ||
vitalybuka marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Test that ios used from globals constructors doesn't trigger Asan initialization-order-fiasco. | ||
|
||
struct Global { | ||
Global() { std::cout << "Hello!"; } | ||
} global; | ||
|
||
int main(int, char**) { return 0; } |
Uh oh!
There was an error while loading. Please reload this page.