[Openmp-commits] [openmp] a6d40b4 - [libomp] Fix hang when a fatal error is raised before library registration (#215988)

via Openmp-commits openmp-commits at lists.llvm.org
Mon Aug 17 00:22:53 PDT 2026


Author: Robert Imschweiler
Date: 2026-08-17T09:22:49+02:00
New Revision: a6d40b40c42d95963f915234851855f456a55b53

URL: https://github.com/llvm/llvm-project/commit/a6d40b40c42d95963f915234851855f456a55b53
DIFF: https://github.com/llvm/llvm-project/commit/a6d40b40c42d95963f915234851855f456a55b53.diff

LOG: [libomp] Fix hang when a fatal error is raised before library registration (#215988)

Uncovered by debug-build testing, not triggered for non-debug builds due
to absence of KMP_DEBUG_ASSERT.

Claude assisted with this patch.

Added: 
    

Modified: 
    openmp/runtime/src/kmp_runtime.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/runtime/src/kmp_runtime.cpp b/openmp/runtime/src/kmp_runtime.cpp
index 234a211bcfba3..f16bcf5e2cbbb 100644
--- a/openmp/runtime/src/kmp_runtime.cpp
+++ b/openmp/runtime/src/kmp_runtime.cpp
@@ -459,6 +459,15 @@ void __kmp_warn(char const *format, ...) {
 }
 
 void __kmp_abort_process() {
+  // A failed assertion or fatal error raised from inside the abort path itself
+  // re-enters this function on the same thread. __kmp_exit_lock is not
+  // recursive, so re-acquiring it below would hang the process instead of
+  // terminating it. Terminate directly on re-entry.
+  static KMP_THREAD_LOCAL bool aborting = false;
+  if (aborting)
+    abort();
+  aborting = true;
+
   // Later threads may stall here, but that's ok because abort() will kill them.
   __kmp_acquire_bootstrap_lock(&__kmp_exit_lock);
 
@@ -6918,6 +6927,13 @@ void __kmp_register_library_startup(void) {
 
 void __kmp_unregister_library(void) {
 
+  // The library can be torn down before it ever registered itself, e.g. when
+  // __kmp_abort_process() runs for a fatal error raised during environment
+  // parsing. There is nothing to unregister then, and __kmp_registration_str
+  // is still NULL, so the strcmp() below would dereference it.
+  if (__kmp_registration_flag == 0)
+    return;
+
   char *name = __kmp_reg_status_name();
   char *value = NULL;
 


        


More information about the Openmp-commits mailing list