[llvm] [BOLT] Link pthread in Profile and Target libs to fix undefined pthre… (PR #215748)
Kito Cheng via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 12 00:44:21 PDT 2026
https://github.com/kito-cheng created https://github.com/llvm/llvm-project/pull/215748
…ad_rwlock_* symbols
MCPlusBuilder.h uses llvm::sys::RWMutex, which aliases std::shared_mutex on non-Apple platforms. Its inline lock/unlock calls pthread_rwlock_* directly, so any shared library that instantiates these inline functions must link pthread explicitly under -Wl,-z,defs.
This only shows up when building with -DBUILD_SHARED_LIBS=ON. With static libs, the missing symbols get resolved elsewhere on the final link line, so the problem stays hidden.
LLVMBOLTCore, LLVMBOLTRewrite, LLVMBOLTPasses, and LLVMBOLTUtils already link ${LLVM_PTHREAD_LIB}; LLVMBOLTProfile and the LLVMBOLTTarget{X86, AArch64,RISCV} libs were missing it, causing link failures.
>From 4238423d64e2facf181a4746b3ec15b33bf19482 Mon Sep 17 00:00:00 2001
From: Kito Cheng <kito.cheng at sifive.com>
Date: Wed, 12 Aug 2026 00:12:33 -0700
Subject: [PATCH] [BOLT] Link pthread in Profile and Target libs to fix
undefined pthread_rwlock_* symbols
MCPlusBuilder.h uses llvm::sys::RWMutex, which aliases std::shared_mutex
on non-Apple platforms. Its inline lock/unlock calls pthread_rwlock_*
directly, so any shared library that instantiates these inline
functions must link pthread explicitly under -Wl,-z,defs.
This only shows up when building with -DBUILD_SHARED_LIBS=ON. With
static libs, the missing symbols get resolved elsewhere on the final
link line, so the problem stays hidden.
LLVMBOLTCore, LLVMBOLTRewrite, LLVMBOLTPasses, and LLVMBOLTUtils already
link ${LLVM_PTHREAD_LIB}; LLVMBOLTProfile and the LLVMBOLTTarget{X86,
AArch64,RISCV} libs were missing it, causing link failures.
---
bolt/lib/Profile/CMakeLists.txt | 3 +++
bolt/lib/Target/AArch64/CMakeLists.txt | 3 +++
bolt/lib/Target/RISCV/CMakeLists.txt | 3 +++
bolt/lib/Target/X86/CMakeLists.txt | 3 +++
4 files changed, 12 insertions(+)
diff --git a/bolt/lib/Profile/CMakeLists.txt b/bolt/lib/Profile/CMakeLists.txt
index a6686510f91a7..c4c6403be3a55 100644
--- a/bolt/lib/Profile/CMakeLists.txt
+++ b/bolt/lib/Profile/CMakeLists.txt
@@ -10,6 +10,9 @@ add_llvm_library(LLVMBOLTProfile
NO_EXPORT
DISABLE_LLVM_LINK_LLVM_DYLIB
+ LINK_LIBS
+ ${LLVM_PTHREAD_LIB}
+
LINK_COMPONENTS
BinaryFormat
Demangle
diff --git a/bolt/lib/Target/AArch64/CMakeLists.txt b/bolt/lib/Target/AArch64/CMakeLists.txt
index 1e171748aece6..715efc1e8c5a4 100644
--- a/bolt/lib/Target/AArch64/CMakeLists.txt
+++ b/bolt/lib/Target/AArch64/CMakeLists.txt
@@ -25,6 +25,9 @@ add_llvm_library(LLVMBOLTTargetAArch64
NO_EXPORT
DISABLE_LLVM_LINK_LLVM_DYLIB
+ LINK_LIBS
+ ${LLVM_PTHREAD_LIB}
+
DEPENDS
AArch64CommonTableGen
)
diff --git a/bolt/lib/Target/RISCV/CMakeLists.txt b/bolt/lib/Target/RISCV/CMakeLists.txt
index 6c3a196f8a1fe..45645a98d132f 100644
--- a/bolt/lib/Target/RISCV/CMakeLists.txt
+++ b/bolt/lib/Target/RISCV/CMakeLists.txt
@@ -23,6 +23,9 @@ add_llvm_library(LLVMBOLTTargetRISCV
NO_EXPORT
DISABLE_LLVM_LINK_LLVM_DYLIB
+ LINK_LIBS
+ ${LLVM_PTHREAD_LIB}
+
DEPENDS
RISCVCommonTableGen
)
diff --git a/bolt/lib/Target/X86/CMakeLists.txt b/bolt/lib/Target/X86/CMakeLists.txt
index 6d1accb5e8159..0da4713b191aa 100644
--- a/bolt/lib/Target/X86/CMakeLists.txt
+++ b/bolt/lib/Target/X86/CMakeLists.txt
@@ -24,6 +24,9 @@ add_llvm_library(LLVMBOLTTargetX86
NO_EXPORT
DISABLE_LLVM_LINK_LLVM_DYLIB
+ LINK_LIBS
+ ${LLVM_PTHREAD_LIB}
+
DEPENDS
X86CommonTableGen
)
More information about the llvm-commits
mailing list