git: da15ed2e9821 - main - Merge commit 5300a6731e98 from llvm-project (by Jonathan Peyton):

From: Dimitry Andric <dim_at_FreeBSD.org>
Date: Wed, 08 May 2024 18:47:33 UTC
The branch main has been updated by dim:

URL: https://cgit.FreeBSD.org/src/commit/?id=da15ed2e982180198f77a0fa26628e6d414cb10e

commit da15ed2e982180198f77a0fa26628e6d414cb10e
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2024-05-08 16:55:08 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2024-05-08 18:45:44 +0000

    Merge commit 5300a6731e98 from llvm-project (by Jonathan Peyton):
    
      [OpenMP] Fix re-locking hang found in issue 86684 (#88539)
    
      This was initially reported here (including stacktraces):
      https://stackoverflow.com/questions/78183545/does-compiling-imagick-with-openmp-enabled-in-freebsd-13-2-cause-sched-yield
    
      If `__kmp_register_library_startup()` detects that another instance of
      the library is present, `__kmp_is_address_mapped()` is eventually
      called. which uses `kmpc_alloc()` to allocate memory. This function
      calls `__kmp_entry_thread()` to access the thread-local memory pool,
      which is a bad idea during initialization. This macro internally calls
      `__kmp_get_global_thread_id_reg()` which sets the bootstrap lock at the
      beginning (before calling `__kmp_register_library_startup()`).
    
      The fix is to use `KMP_INTERNAL_MALLOC()`/`KMP_INTERNAL_FREE()` instead
      of `kmpc_malloc()`/`kmpc_free()`. `KMP_INTERNAL_MALLOC` and
      `KMP_INTERNAL_FREE` do not use any bootstrap locks. They just translate
      to `malloc()`/`free()` and are meant to be used during library
      initialization before other library-specific allocators have been
      initialized.
    
      Fixes: #86684
    
    This should fix OpenMP processes sometimes getting locked with 100% CPU
    usage, endlessly calling sched_yield(2).
    
    PR:             278845
    Reported by:    Cassidy B. Larson <cbl@cbl.us>
    MFC after:      3 days
---
 contrib/llvm-project/openmp/runtime/src/z_Linux_util.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/contrib/llvm-project/openmp/runtime/src/z_Linux_util.cpp b/contrib/llvm-project/openmp/runtime/src/z_Linux_util.cpp
index b9ff96873702..97ddb8a608b7 100644
--- a/contrib/llvm-project/openmp/runtime/src/z_Linux_util.cpp
+++ b/contrib/llvm-project/openmp/runtime/src/z_Linux_util.cpp
@@ -2129,10 +2129,10 @@ int __kmp_is_address_mapped(void *addr) {
   // We pass from number of vm entry's semantic
   // to size of whole entry map list.
   lstsz = lstsz * 4 / 3;
-  buf = reinterpret_cast<char *>(kmpc_malloc(lstsz));
+  buf = reinterpret_cast<char *>(KMP_INTERNAL_MALLOC(lstsz));
   rc = sysctl(mib, 4, buf, &lstsz, NULL, 0);
   if (rc < 0) {
-    kmpc_free(buf);
+    KMP_INTERNAL_FREE(buf);
     return 0;
   }
 
@@ -2156,7 +2156,7 @@ int __kmp_is_address_mapped(void *addr) {
     }
     lw += cursz;
   }
-  kmpc_free(buf);
+  KMP_INTERNAL_FREE(buf);
 
 #elif KMP_OS_DARWIN