From 77038ab61a23ac53dc8d3b3a08abb576d9971503 Mon Sep 17 00:00:00 2001 From: Brad Smith Date: Thu, 5 Nov 2026 12:14:07 -0500 Subject: [PATCH] build: only build huf_decompress_amd64.S on x86_64 The Make and Meson builds add the x86_64 Huffman decoder assembly source to every build, whatever the target CPU. Match the CMake build and only build it when targeting x86_64, otherwise explicitly disable assembly. For Make, ask the compiler whether it targets x86_64, rather than using uname, so cross-compiling and -m32 builds are handled. For Meson, check the host machine's CPU family. --- build/meson/lib/meson.build | 3 ++- lib/libzstd.mk | 12 ++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/build/meson/lib/meson.build b/build/meson/lib/meson.build index 81fc313f954..ae16d655426 100644 --- a/build/meson/lib/meson.build +++ b/build/meson/lib/meson.build @@ -46,10 +46,11 @@ libzstd_sources = [join_paths(zstd_rootdir, 'lib/common/entropy_common.c'), join_paths(zstd_rootdir, 'lib/dictBuilder/divsufsort.c'), join_paths(zstd_rootdir, 'lib/dictBuilder/zdict.c')] +# The assembly source only has an x86_64 implementation, so only build it there. # really we need anything that defines __GNUC__ as that is what ZSTD_ASM_SUPPORTED is gated on # but these are the two compilers that are supported in tree and actually handle this correctly # Otherwise, explicitly disable assembly. -if [compiler_gcc, compiler_clang].contains(cc_id) +if host_machine.cpu_family() == 'x86_64' and [compiler_gcc, compiler_clang].contains(cc_id) libzstd_sources += join_paths(zstd_rootdir, 'lib/decompress/huf_decompress_amd64.S') else add_project_arguments('-DZSTD_DISABLE_ASM', language: 'c') diff --git a/lib/libzstd.mk b/lib/libzstd.mk index 60928b0ee95..9055da61fed 100644 --- a/lib/libzstd.mk +++ b/lib/libzstd.mk @@ -49,9 +49,6 @@ else ZSTD_STRIP_ERROR_STRINGS ?= 0 endif -# Assembly support -ZSTD_NO_ASM ?= 0 - ZSTD_LIB_EXCLUDE_COMPRESSORS_DFAST_AND_UP ?= 0 ZSTD_LIB_EXCLUDE_COMPRESSORS_GREEDY_AND_UP ?= 0 @@ -151,11 +148,14 @@ ZSTD_LEGACY_FILES := ZSTD_DECOMPRESS_AMD64_ASM_FILES := $(sort $(wildcard $(LIB_SRCDIR)/decompress/*_amd64.S)) -ifneq ($(ZSTD_NO_ASM), 0) +# The assembly sources only have an x86_64 implementation, so only build +# them when the compiler targets x86_64. Ask the compiler instead of using +# uname so that cross-compiling and -m32 builds do the right thing. +ZSTD_ASM_X86_64 := $(shell echo | $(CC) $(CPPFLAGS) $(CFLAGS) -dM -E - 2>$(VOID) | $(GREP) -c '__x86_64__') + +ifeq ($(ZSTD_ASM_X86_64), 0) CPPFLAGS += -DZSTD_DISABLE_ASM else - # Unconditionally add the ASM files they are disabled by - # macros in the .S file. ZSTD_DECOMPRESS_FILES += $(ZSTD_DECOMPRESS_AMD64_ASM_FILES) endif