[PATCH] D147413: [sanitizer][win] Fix `Atexit()` on MinGW asan_dynamic runtime
Alvin Wong via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 3 03:35:07 PDT 2023
alvinhochun updated this revision to Diff 510443.
alvinhochun added a comment.
Reformat
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D147413/new/
https://reviews.llvm.org/D147413
Files:
compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
compiler-rt/test/asan/TestCases/Windows/coverage-basic.cpp
compiler-rt/test/asan/TestCases/atexit_stats.cpp
Index: compiler-rt/test/asan/TestCases/atexit_stats.cpp
===================================================================
--- compiler-rt/test/asan/TestCases/atexit_stats.cpp
+++ compiler-rt/test/asan/TestCases/atexit_stats.cpp
@@ -6,9 +6,6 @@
// https://code.google.com/p/address-sanitizer/issues/detail?id=263
// UNSUPPORTED: android
-// FIXME: Investigate failure on MinGW.
-// XFAIL: target={{.*-windows-gnu}}
-
#include <stdlib.h>
#if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__NetBSD__)
#include <malloc.h>
Index: compiler-rt/test/asan/TestCases/Windows/coverage-basic.cpp
===================================================================
--- compiler-rt/test/asan/TestCases/Windows/coverage-basic.cpp
+++ compiler-rt/test/asan/TestCases/Windows/coverage-basic.cpp
@@ -5,9 +5,6 @@
//
// RUN: %sancov print *.sancov | FileCheck %s
-// FIXME: Investigate failure on MinGW.
-// XFAIL: target={{.*-windows-gnu}}
-
#include <stdio.h>
void foo() { fputs("FOO", stderr); }
Index: compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
+++ compiler-rt/lib/sanitizer_common/sanitizer_win.cpp
@@ -718,13 +718,24 @@
// atexit() as soon as it is ready for use (i.e. after .CRT$XIC initializers).
InternalMmapVectorNoCtor<void (*)(void)> atexit_functions;
-int Atexit(void (*function)(void)) {
+static int queueAtexit(void (*function)(void)) {
atexit_functions.push_back(function);
return 0;
}
+// If Atexit() is being called after RunAtexit() has already been run, it needs
+// to be able to call atexit() directly. Here we use a function ponter to
+// switch out its behaviour.
+// An example of where this is needed is the asan_dynamic runtime on MinGW-w64.
+// On this environment, __asan_init is called during global constructor phase,
+// way after calling the .CRT$XID initializer.
+static int (*volatile queueOrCallAtExit)(void (*)(void)) = &queueAtexit;
+
+int Atexit(void (*function)(void)) { return queueOrCallAtExit(function); }
+
static int RunAtexit() {
TraceLoggingUnregister(g_asan_provider);
+ queueOrCallAtExit = &atexit;
int ret = 0;
for (uptr i = 0; i < atexit_functions.size(); ++i) {
ret |= atexit(atexit_functions[i]);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147413.510443.patch
Type: text/x-patch
Size: 2318 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230403/5288ac03/attachment.bin>
More information about the llvm-commits
mailing list