Skip to content

Commit 78631ac

Browse files
authored
[Flang] explicitly link the pthread library when building shared flang-rt. (#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`
1 parent 4bc3592 commit 78631ac

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

flang-rt/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ check_cxx_compiler_flag("-UTESTFLAG" FLANG_RT_SUPPORTS_UNDEFINE_FLAG)
245245
# Check whether -fno-lto is supported.
246246
check_cxx_compiler_flag(-fno-lto FLANG_RT_HAS_FNO_LTO_FLAG)
247247

248+
# Different platform may have different name for the POSIX thread library.
249+
# For example, libpthread.a on AIX. Search for it as it is needed when
250+
# building the shared flang_rt.runtime.so.
251+
find_package(Threads)
248252

249253
# function checks
250254
find_package(Backtrace)

flang-rt/cmake/modules/AddFlangRT.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ function (add_flangrt_library name)
142142
endif ()
143143
if (build_shared)
144144
add_library("${name_shared}" SHARED ${extra_args} ${ARG_ADDITIONAL_HEADERS} ${ARG_UNPARSED_ARGUMENTS})
145+
if (Threads_FOUND)
146+
target_link_libraries(${name_shared} PUBLIC Threads::Threads)
147+
endif ()
145148
endif ()
146149

147150
if (libtargets)

0 commit comments

Comments
 (0)