Skip to content

Commit 576efff

Browse files
wlejonclaude
andcommitted
cmake: build the backend static libs position-independent
Consumers that link libbrotensor_cpu.a into a shared object (a Python extension, a plugin .so) hit a link failure on Linux: the CPU thread pool's thread-local t_active emits a local-exec TLS relocation (R_X86_64_TPOFF32) that ld rejects inside a shared object -- "recompile with -fPIC". Setting CMAKE_POSITION_INDEPENDENT_CODE ON makes every backend archive PIC so it can land in either an executable or a shared object. Scoped to this directory's targets; it does not leak into a parent that add_subdirectory()s brotensor. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 98b1a3c commit 576efff

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ set(CMAKE_CXX_STANDARD 20)
1010
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1111
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1212

13+
# Build every backend static lib position-independent. Consumers vendor this
14+
# repo and sometimes link the archives into a shared object (e.g. a Python
15+
# extension module or a plugin .so); without PIC the CPU pool's thread-local
16+
# `t_active` emits a local-exec TLS relocation (R_X86_64_TPOFF32) that the
17+
# linker rejects when the archive lands in a shared object. Scoped to this
18+
# directory's targets — it does not leak to a parent that add_subdirectory()s us.
19+
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
20+
1321
set(THREADS_PREFER_PTHREAD_FLAG ON)
1422
find_package(Threads REQUIRED)
1523

0 commit comments

Comments
 (0)