From nobody Sun Dec 14 06:16:17 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34D7BC04A95 for ; Thu, 29 Sep 2022 02:16:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234548AbiI2CQs (ORCPT ); Wed, 28 Sep 2022 22:16:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232599AbiI2CQp (ORCPT ); Wed, 28 Sep 2022 22:16:45 -0400 X-Greylist: delayed 489 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 28 Sep 2022 19:16:44 PDT Received: from ozlabs.ru (ozlabs.ru [107.174.27.60]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0BCA710AB0E for ; Wed, 28 Sep 2022 19:16:43 -0700 (PDT) Received: from ole.1.ozlabs.ru (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 8D471831F4; Wed, 28 Sep 2022 22:08:30 -0400 (EDT) From: Alexey Kardashevskiy To: linux-kernel@vger.kernel.org Cc: Alexey Kardashevskiy , Nick Terrell , Nick Desaulniers , Nathan Chancellor , Nicholas Piggin , Masahiro Yamada , kernel test robot Subject: [PATCH kernel v3] zstd: Fixing mixed module-builtin objects Date: Thu, 29 Sep 2022 12:08:23 +1000 Message-Id: <20220929020823.1373722-1-aik@ozlabs.ru> X-Mailer: git-send-email 2.37.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" With CONFIG_ZSTD_COMPRESS=3Dm and CONFIG_ZSTD_DECOMPRESS=3Dy we end up in a situation when files from lib/zstd/common/ are compiled once to be linked later for ZSTD_DECOMPRESS (build-in) and ZSTD_COMPRESS (module) even though CFLAGS are different for builtins and modules. So far somehow this was not a problem but enabling LLVM LTO exposes the problem as: ld.lld: error: linking module flags 'Code Model': IDs have conflicting valu= es in 'lib/built-in.a(zstd_common.o at 5868)' and 'ld-temp.o' This particular conflict is caused by KBUILD_CFLAGS=3D-mcmodel=3Dmedium vs. KBUILD_CFLAGS_MODULE=3D-mcmodel=3Dlarge , modules use the large model on POWERPC as explained at https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arc= h/powerpc/Makefile?h=3Dv5.18-rc4#n127 but the current use of common files is wrong anyway. This works around the issue by introducing a zstd_common module with shared code. Cc: Masahiro Yamada Signed-off-by: Alexey Kardashevskiy [robot found a problem in v2] Reported-by: kernel test robot --- Changes: v3: * added EXPORT_SYMBOL_GPL to compile with: CONFIG_ZSTD_COMMON=3Dm CONFIG_ZSTD_COMPRESS=3Dm CONFIG_ZSTD_DECOMPRESS=3Dm Vast majority of cases have CONFIG_ZSTD_COMMON=3Dy so this went unnoticed --- lib/zstd/Makefile | 18 ++++++++---------- lib/zstd/common/entropy_common.c | 5 ++++- lib/zstd/common/zstd_common.c | 10 ++++++++++ lib/Kconfig | 8 ++++++-- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/lib/zstd/Makefile b/lib/zstd/Makefile index fc45339fc3a3..440bd0007ae2 100644 --- a/lib/zstd/Makefile +++ b/lib/zstd/Makefile @@ -10,14 +10,10 @@ # ################################################################ obj-$(CONFIG_ZSTD_COMPRESS) +=3D zstd_compress.o obj-$(CONFIG_ZSTD_DECOMPRESS) +=3D zstd_decompress.o +obj-$(CONFIG_ZSTD_COMMON) +=3D zstd_common.o =20 zstd_compress-y :=3D \ zstd_compress_module.o \ - common/debug.o \ - common/entropy_common.o \ - common/error_private.o \ - common/fse_decompress.o \ - common/zstd_common.o \ compress/fse_compress.o \ compress/hist.o \ compress/huf_compress.o \ @@ -33,12 +29,14 @@ zstd_compress-y :=3D \ =20 zstd_decompress-y :=3D \ zstd_decompress_module.o \ - common/debug.o \ - common/entropy_common.o \ - common/error_private.o \ - common/fse_decompress.o \ - common/zstd_common.o \ decompress/huf_decompress.o \ decompress/zstd_ddict.o \ decompress/zstd_decompress.o \ decompress/zstd_decompress_block.o \ + +zstd_common-y :=3D \ + common/debug.o \ + common/entropy_common.o \ + common/error_private.o \ + common/fse_decompress.o \ + common/zstd_common.o \ diff --git a/lib/zstd/common/entropy_common.c b/lib/zstd/common/entropy_com= mon.c index 53b47a2b52ff..a311808c0d56 100644 --- a/lib/zstd/common/entropy_common.c +++ b/lib/zstd/common/entropy_common.c @@ -15,6 +15,7 @@ /* ************************************* * Dependencies ***************************************/ +#include #include "mem.h" #include "error_private.h" /* ERR_*, ERROR */ #define FSE_STATIC_LINKING_ONLY /* FSE_MIN_TABLELOG */ @@ -239,7 +240,7 @@ size_t FSE_readNCount( { return FSE_readNCount_bmi2(normalizedCounter, maxSVPtr, tableLogPtr, h= eaderBuffer, hbSize, /* bmi2 */ 0); } - +EXPORT_SYMBOL_GPL(FSE_readNCount); =20 /*! HUF_readStats() : Read compact Huffman tree, saved by HUF_writeCTable(). @@ -255,6 +256,7 @@ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U= 32* rankStats, U32 wksp[HUF_READ_STATS_WORKSPACE_SIZE_U32]; return HUF_readStats_wksp(huffWeight, hwSize, rankStats, nbSymbolsPtr,= tableLogPtr, src, srcSize, wksp, sizeof(wksp), /* bmi2 */ 0); } +EXPORT_SYMBOL_GPL(HUF_readStats); =20 FORCE_INLINE_TEMPLATE size_t HUF_readStats_body(BYTE* huffWeight, size_t hwSize, U32* rankStats, @@ -355,3 +357,4 @@ size_t HUF_readStats_wksp(BYTE* huffWeight, size_t hwSi= ze, U32* rankStats, (void)bmi2; return HUF_readStats_body_default(huffWeight, hwSize, rankStats, nbSym= bolsPtr, tableLogPtr, src, srcSize, workSpace, wkspSize); } +EXPORT_SYMBOL_GPL(HUF_readStats_wksp); diff --git a/lib/zstd/common/zstd_common.c b/lib/zstd/common/zstd_common.c index 3d7e35b309b5..0f1f63be25d9 100644 --- a/lib/zstd/common/zstd_common.c +++ b/lib/zstd/common/zstd_common.c @@ -13,6 +13,7 @@ /*-************************************* * Dependencies ***************************************/ +#include #define ZSTD_DEPS_NEED_MALLOC #include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_mems= et */ #include "error_private.h" @@ -35,14 +36,17 @@ const char* ZSTD_versionString(void) { return ZSTD_VERS= ION_STRING; } * tells if a return value is an error code * symbol is required for external callers */ unsigned ZSTD_isError(size_t code) { return ERR_isError(code); } +EXPORT_SYMBOL_GPL(ZSTD_isError); =20 /*! ZSTD_getErrorName() : * provides error code string from function result (useful for debugging)= */ const char* ZSTD_getErrorName(size_t code) { return ERR_getErrorName(code)= ; } +EXPORT_SYMBOL_GPL(ZSTD_getErrorName); =20 /*! ZSTD_getError() : * convert a `size_t` function result into a proper ZSTD_errorCode enum */ ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(co= de); } +EXPORT_SYMBOL_GPL(ZSTD_getErrorCode); =20 /*! ZSTD_getErrorString() : * provides error code string from enum */ @@ -59,6 +63,7 @@ void* ZSTD_customMalloc(size_t size, ZSTD_customMem custo= mMem) return customMem.customAlloc(customMem.opaque, size); return ZSTD_malloc(size); } +EXPORT_SYMBOL_GPL(ZSTD_customMalloc); =20 void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem) { @@ -71,6 +76,7 @@ void* ZSTD_customCalloc(size_t size, ZSTD_customMem custo= mMem) } return ZSTD_calloc(1, size); } +EXPORT_SYMBOL_GPL(ZSTD_customCalloc); =20 void ZSTD_customFree(void* ptr, ZSTD_customMem customMem) { @@ -81,3 +87,7 @@ void ZSTD_customFree(void* ptr, ZSTD_customMem customMem) ZSTD_free(ptr); } } +EXPORT_SYMBOL_GPL(ZSTD_customFree); + +MODULE_LICENSE("Dual BSD/GPL"); +MODULE_DESCRIPTION("Zstd Common"); diff --git a/lib/Kconfig b/lib/Kconfig index dc1ab2ed1dc6..3ea8941ab18d 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -343,12 +343,16 @@ config LZ4HC_COMPRESS config LZ4_DECOMPRESS tristate =20 +config ZSTD_COMMON + select XXHASH + tristate + config ZSTD_COMPRESS - select XXHASH + select ZSTD_COMMON tristate =20 config ZSTD_DECOMPRESS - select XXHASH + select ZSTD_COMMON tristate =20 source "lib/xz/Kconfig" --=20 2.37.3