[llvm] [Flang] explicitly link the pthread library when building shared flang-rt. (PR #129956)

Daniel Chen via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 5 15:35:31 PST 2025


https://github.com/DanielCChen created https://github.com/llvm/llvm-project/pull/129956

This patch is to explicitly link the pthread library when building shared flang-rt. 
On AIX, for example, it needs to link in `libpthread.a` explicitly in order to resolve the references to those `pthread_*` functions in `include/flang-rt/runtime/lock.h`

>From c9bab027c61e8efdaf4040789da5788a0ad07e48 Mon Sep 17 00:00:00 2001
From: Daniel Chen <cdchen at ca.ibm.com>
Date: Wed, 5 Mar 2025 18:31:22 -0500
Subject: [PATCH] [Flang] explicitly link the pthread library when building
 shared flang-rt.

---
 flang-rt/cmake/modules/AddFlangRT.cmake | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/flang-rt/cmake/modules/AddFlangRT.cmake b/flang-rt/cmake/modules/AddFlangRT.cmake
index a43f1c332187a..59c011b87b131 100644
--- a/flang-rt/cmake/modules/AddFlangRT.cmake
+++ b/flang-rt/cmake/modules/AddFlangRT.cmake
@@ -142,6 +142,8 @@ function (add_flangrt_library name)
   endif ()
   if (build_shared)
     add_library("${name_shared}" SHARED ${extra_args} ${ARG_ADDITIONAL_HEADERS} ${ARG_UNPARSED_ARGUMENTS})
+    find_package(Threads REQUIRED)
+    target_link_libraries(${name_shared} PUBLIC Threads::Threads)
   endif ()
 
   if (libtargets)



More information about the llvm-commits mailing list