[libcxx-commits] [libcxx] [libc++] Fix initialization-order-fiasco with iostream.cpp constructors (PR #126995)
Vitaly Buka via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Feb 12 17:44:50 PST 2025
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/126995
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.
>From baed235d9dac075571ef4f4703b7eabd5326d943 Mon Sep 17 00:00:00 2001
From: Vitaly Buka <vitalybuka at google.com>
Date: Wed, 12 Feb 2025 17:44:36 -0800
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.4
---
.../ios_Init/ios_Init.global.pass.cpp | 27 +++++++++++++++++++
1 file changed, 27 insertions(+)
create mode 100644 libcxx/test/std/input.output/iostreams.base/ios.base/ios.types/ios_Init/ios_Init.global.pass.cpp
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;
+}
More information about the libcxx-commits
mailing list