From 04ce33eee4b0d82a5dbf58414e2b7d8880f65a37 Mon Sep 17 00:00:00 2001 From: Khem Raj Date: Wed, 21 Oct 2026 21:51:45 -0700 Subject: [PATCH] x265: Link with libatomic when 64-bit atomics need it The encoder uses atomic operations on 64-bit counters. On riscv32 these become __atomic_*_8 libcalls, and libx265 is not linked with libatomic, so linking the x265 CLI fails: ld.lld: error: undefined reference: __atomic_fetch_or_8 >>> referenced by libx265.so.217 (disallowed by --no-allow-shlib-undefined) Add a patch that checks in CMake whether 64-bit atomics need libatomic and adds it to the platform libraries only in that case. AI-Generated: Uses Claude Code Signed-off-by: Khem Raj --- ...libatomic-when-64-bit-atomics-need-i.patch | 55 +++++++++++++++++++ .../recipes-multimedia/x265/x265_4.3.bb | 1 + 2 files changed, 56 insertions(+) create mode 100644 meta-multimedia/recipes-multimedia/x265/x265/0004-cmake-Link-with-libatomic-when-64-bit-atomics-need-i.patch diff --git a/meta-multimedia/recipes-multimedia/x265/x265/0004-cmake-Link-with-libatomic-when-64-bit-atomics-need-i.patch b/meta-multimedia/recipes-multimedia/x265/x265/0004-cmake-Link-with-libatomic-when-64-bit-atomics-need-i.patch new file mode 100644 index 0000000000..648bfe2255 --- /dev/null +++ b/meta-multimedia/recipes-multimedia/x265/x265/0004-cmake-Link-with-libatomic-when-64-bit-atomics-need-i.patch @@ -0,0 +1,55 @@ +From: Khem Raj +Date: Wed, 21 Oct 2026 15:00:00 -0700 +Subject: [PATCH] cmake: Link with libatomic when 64-bit atomics need it + +The encoder uses the ATOMIC_* macros, i.e. the __sync builtins, on +64-bit counters, e.g. the threaded ME sequence number and timing +totals. On 32-bit targets without 64-bit atomic instructions, such as +riscv32, the compiler lowers these to __atomic_*_8 libcalls. libx265 is +not linked with libatomic, so linking the x265 CLI against it fails: + + ld.lld: error: undefined reference: __atomic_fetch_or_8 + >>> referenced by libx265.so.217 (disallowed by --no-allow-shlib-undefined) + +Check whether 64-bit atomics link on their own, and if not, whether they +link with libatomic, and add it to PLATFORM_LIBS only in that case, so +libx265, the CLI and the Libs.private of x265.pc all get it. The test +variable is global so the compiler cannot optimize the atomic +operations away. + +Upstream-Status: Pending +Signed-off-by: Khem Raj +--- + source/CMakeLists.txt | 21 +++++++++++++++++++++ + 1 file changed, 21 insertions(+) + +--- a/source/CMakeLists.txt ++++ b/source/CMakeLists.txt +@@ -191,6 +191,27 @@ + if(NO_ATOMICS) + add_definitions(-DNO_ATOMICS=1) + endif(NO_ATOMICS) ++ if(NOT NO_ATOMICS) ++ # The atomics on 64-bit counters need libatomic on 32-bit targets ++ # without 64-bit atomic instructions, e.g. riscv32. The variable is ++ # global so the compiler cannot optimize the atomic operations away. ++ set(ATOMIC64_TEST " ++#include ++uint64_t v; ++int main(void) { ++ __sync_fetch_and_add(&v, 1); ++ return (int)__sync_fetch_and_or(&v, 0); ++}") ++ check_c_source_compiles("${ATOMIC64_TEST}" HAVE_ATOMIC64) ++ if(NOT HAVE_ATOMIC64) ++ set(CMAKE_REQUIRED_LIBRARIES atomic) ++ check_c_source_compiles("${ATOMIC64_TEST}" HAVE_ATOMIC64_WITH_LIBATOMIC) ++ unset(CMAKE_REQUIRED_LIBRARIES) ++ if(HAVE_ATOMIC64_WITH_LIBATOMIC) ++ list(APPEND PLATFORM_LIBS atomic) ++ endif() ++ endif() ++ endif() + find_library(VMAF vmaf) + option(ENABLE_LIBVMAF "Enable VMAF" OFF) + if(ENABLE_LIBVMAF) diff --git a/meta-multimedia/recipes-multimedia/x265/x265_4.3.bb b/meta-multimedia/recipes-multimedia/x265/x265_4.3.bb index c657421783..31b28c3295 100644 --- a/meta-multimedia/recipes-multimedia/x265/x265_4.3.bb +++ b/meta-multimedia/recipes-multimedia/x265/x265_4.3.bb @@ -13,6 +13,7 @@ SRC_URI = " \ file://0001-fix-dynamicHDR10-undefined-uint8_t.patch;patchdir=.. \ file://0002-x265-fix-build-with-cmake-4.patch;patchdir=.. \ file://0003-riscv64-Fix-case-of-STRIDE_SHIFT-macro-invocation.patch;patchdir=.. \ + file://0004-cmake-Link-with-libatomic-when-64-bit-atomics-need-i.patch;patchdir=.. \ " SRCREV = "e9b88125dc21393b3fd8d68e98083bdfb89778a8" S = "${UNPACKDIR}/x265-${PV}/source"