From 5f6c8eb030928063f57a060ea6663af81d9280ec Mon Sep 17 00:00:00 2001 From: Khem Raj Date: Wed, 5 Aug 2026 23:29:51 -0700 Subject: [PATCH] apitrace: Fix link failure with BMI2 capable tunes thirdparty/zstd.cmake compiles the bundled zstd's huf_decompress.c but not the assembly file it pairs with, zstd/lib/decompress/huf_decompress_amd64.S. zstd selects the assembly fast loops in portability_macros.h whenever !defined(ZSTD_DISABLE_ASM) && ZSTD_ASM_SUPPORTED && defined(__x86_64__) && (DYNAMIC_BMI2 || defined(__BMI2__)) so the DYNAMIC_BMI2=0 that apitrace already sets is not enough: any x86-64 tune whose -march implies BMI2, such as x86-64-v3, still takes that path and fails to link: | ld.lld: error: undefined hidden symbol: HUF_decompress4X2_usingDTable_internal_fast_asm_loop | >>> referenced by huf_decompress.c:1739 | >>> thirdparty/apitrace.lto.libzstd_bundled.a(huf_decompress.c.o) | ld.lld: error: undefined hidden symbol: HUF_decompress4X1_usingDTable_internal_fast_asm_loop | >>> referenced by huf_decompress.c:917 Plain -march=x86-64 does not define __BMI2__, which is why only the more specific tunes are affected. Define ZSTD_DISABLE_ASM so the C fast loops are used consistently, which is already what every non-BMI2 build gets. Not fixed upstream: master carries the same zstd.cmake, no commit since tag 14.0 touches it, and none of the 19 open pull requests or any issue covers this. Verified on x86-64 for qemux86-64 (x86-64-v3 tune): do_compile fails before the change while linking gltrim and apitrace, and do_compile, do_install and do_package succeed after. Signed-off-by: Khem Raj --- ...-the-x86-64-BMI2-assembly-fast-loops.patch | 54 +++++++++++++++++++ .../apitrace/apitrace_14.0.bb | 4 +- 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 meta-oe/recipes-devtools/apitrace/apitrace/0001-zstd-disable-the-x86-64-BMI2-assembly-fast-loops.patch diff --git a/meta-oe/recipes-devtools/apitrace/apitrace/0001-zstd-disable-the-x86-64-BMI2-assembly-fast-loops.patch b/meta-oe/recipes-devtools/apitrace/apitrace/0001-zstd-disable-the-x86-64-BMI2-assembly-fast-loops.patch new file mode 100644 index 0000000000..7cdd09a319 --- /dev/null +++ b/meta-oe/recipes-devtools/apitrace/apitrace/0001-zstd-disable-the-x86-64-BMI2-assembly-fast-loops.patch @@ -0,0 +1,54 @@ +From 6109e8fc11f396d91c7fea8bf2dbf4aaf40af5af Mon Sep 17 00:00:00 2001 +From: Khem Raj +Date: Thu, 6 Aug 2026 05:34:55 +0000 +Subject: [PATCH] zstd: disable the x86-64 BMI2 assembly fast loops + +thirdparty/zstd.cmake compiles huf_decompress.c but not the assembly +file it pairs with, zstd/lib/decompress/huf_decompress_amd64.S. zstd +selects the assembly fast loops in portability_macros.h whenever + + !defined(ZSTD_DISABLE_ASM) && ZSTD_ASM_SUPPORTED && + defined(__x86_64__) && (DYNAMIC_BMI2 || defined(__BMI2__)) + +so setting DYNAMIC_BMI2=0 is not enough: any x86-64 build whose -march +implies BMI2, such as -march=x86-64-v3, still takes that path and then +fails to link: + +| ld.lld: error: undefined hidden symbol: HUF_decompress4X2_usingDTable_internal_fast_asm_loop +| >>> referenced by huf_decompress.c:1739 +| >>> thirdparty/apitrace.lto.libzstd_bundled.a(huf_decompress.c.o) +| ld.lld: error: undefined hidden symbol: HUF_decompress4X1_usingDTable_internal_fast_asm_loop +| >>> referenced by huf_decompress.c:917 + +Plain -march=x86-64 does not define __BMI2__, which is why this only +shows up on the more specific tunes. + +Define ZSTD_DISABLE_ASM so the C fast loops are used consistently. The +alternative would be to add huf_decompress_amd64.S to the target and +enable the ASM language, guarded to x86-64, but the C loops are already +what every non-BMI2 build gets today. +Upstream-Status: Pending +Signed-off-by: Khem Raj +--- + thirdparty/zstd.cmake | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/thirdparty/zstd.cmake b/thirdparty/zstd.cmake +index cb1e5851..84642916 100644 +--- a/thirdparty/zstd.cmake ++++ b/thirdparty/zstd.cmake +@@ -40,6 +40,11 @@ target_compile_definitions(zstd_bundled PRIVATE + + # Would be better to copy their logic for enabling this asm support. + DYNAMIC_BMI2=0 ++ ++ # huf_decompress_amd64.S is not built above, but zstd still selects the ++ # assembly fast loops whenever the compiler targets BMI2 (for example ++ # -march=x86-64-v3), which then fails to link. Keep the C fast loops. ++ ZSTD_DISABLE_ASM + ) + + target_optimize(zstd_bundled) +-- +2.43.0 + diff --git a/meta-oe/recipes-devtools/apitrace/apitrace_14.0.bb b/meta-oe/recipes-devtools/apitrace/apitrace_14.0.bb index b4b1d710d1..cb5ee92e04 100644 --- a/meta-oe/recipes-devtools/apitrace/apitrace_14.0.bb +++ b/meta-oe/recipes-devtools/apitrace/apitrace_14.0.bb @@ -6,7 +6,9 @@ LIC_FILES_CHKSUM = "file://LICENSE;md5=aeb969185a143c3c25130bc2c3ef9a50 \ file://thirdparty/snappy/COPYING;md5=f62f3080324a97b3159a7a7e61812d0c" SRCREV = "18cfd388ac47a9e00978b34d6c20341f3e2cdb56" -SRC_URI = "gitsm://github.com/${BPN}/${BPN}.git;branch=master;protocol=https;tag=${PV}" +SRC_URI = "gitsm://github.com/${BPN}/${BPN}.git;branch=master;protocol=https;tag=${PV} \ + file://0001-zstd-disable-the-x86-64-BMI2-assembly-fast-loops.patch \ + " DEPENDS += "zlib libpng python3-native"