From 0aa5aebd0ace94cfb6b975b16024fe90a6139acf Mon Sep 17 00:00:00 2001 From: Jonathan Peyton Date: Mon, 12 Dec 2022 11:33:52 -0600 Subject: [PATCH] [OpenMP][libomp] Fix macOS 12 library destruction When building the library with icc and using it on macOS 12, the library destruction process is skipped which has many OMPT tests failing for macOS 12. This change registers the __kmp_internal_end_library() call for atexit() which will be a harmless, redundant call for macOS 11 and below and the only destructor called for macOS 12+. Differential Revision: https://reviews.llvm.org/D139857 --- openmp/runtime/src/kmp_runtime.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/openmp/runtime/src/kmp_runtime.cpp b/openmp/runtime/src/kmp_runtime.cpp index e70393a..6022dca 100644 --- a/openmp/runtime/src/kmp_runtime.cpp +++ b/openmp/runtime/src/kmp_runtime.cpp @@ -7242,10 +7242,12 @@ static void __kmp_do_serial_initialize(void) { __kmp_register_atfork(); #endif -#if !KMP_DYNAMIC_LIB +#if !KMP_DYNAMIC_LIB || \ + ((KMP_COMPILER_ICC || KMP_COMPILER_ICX) && KMP_OS_DARWIN) { /* Invoke the exit handler when the program finishes, only for static - library. For dynamic library, we already have _fini and DllMain. */ + library and macOS* dynamic. For other dynamic libraries, we already + have _fini and DllMain. */ int rc = atexit(__kmp_internal_end_atexit); if (rc != 0) { __kmp_fatal(KMP_MSG(FunctionError, "atexit()"), KMP_ERR(rc), -- 2.7.4