[libcxx-commits] [libcxx] [libc++] Fix initialization-order-fiasco with iostream.cpp constructors (PR #126995)
via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Feb 12 17:45:22 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libcxx
Author: Vitaly Buka (vitalybuka)
<details>
<summary>Changes</summary>
Asan reports it after #<!-- -->124103.
It's know case of false positive for Asan.
https://github.com/google/sanitizers/wiki/AddressSanitizerInitializationOrderFiasco#false-positives
In general order global constructors in different
modules is undefined. If global constructor uses
external global, they can be not constructed yet.
However, implementation may contain workaround for
that, or the state of non-constructed global can
be still valid.
Asan will still falsely report such cases, as it
has no machinery to detect correctness of such
cases.
We need to fix/workaround the issue in libc++, as
it will affect many libc++ with Asan users.
---
Full diff: https://github.com/llvm/llvm-project/pull/126995.diff
1 Files Affected:
- (added) libcxx/test/std/input.output/iostreams.base/ios.base/ios.types/ios_Init/ios_Init.global.pass.cpp (+27)
``````````diff
diff --git a/libcxx/test/std/input.output/iostreams.base/ios.base/ios.types/ios_Init/ios_Init.global.pass.cpp b/libcxx/test/std/input.output/iostreams.base/ios.base/ios.types/ios_Init/ios_Init.global.pass.cpp
new file mode 100644
index 0000000000000..b1ea8517850f4
--- /dev/null
+++ b/libcxx/test/std/input.output/iostreams.base/ios.base/ios.types/ios_Init/ios_Init.global.pass.cpp
@@ -0,0 +1,27 @@
+//===----------------------------------------------------------------------===//
+//
+// 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>
+
+extern "C" const char *__asan_default_options() {
+ return "check_initialization_order=true:strict_init_order=true";
+}
+
+// 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;
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/126995
More information about the libcxx-commits
mailing list