zstd: Fixing mixed module-builtin objects
Subsystems (2)
PATCH v2 1/1 zstd: Fixing mixed module-builtin objects
With CONFIG_ZSTD_COMPRESS=m and CONFIG_ZSTD_DECOMPRESS=y 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 values in 'lib/built-in.a(zstd_common.o at 5868)' and 'ld-temp.o'
This particular conflict is caused by KBUILD_CFLAGS=-mcmodel=medium vs. KBUILD_CFLAGS_MODULE=-mcmodel=large , modules use the large model on POWERPC as explained at
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/powerpc/Makefile?h=v5.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.
---
Changes:
v2:
* add a new module instead of inlining common bits
--- lib/zstd/Makefile | 18 ++++++++---------- lib/zstd/common/entropy_common.c | 4 +++- lib/zstd/common/zstd_common.c | 7 +++++++ lib/Kconfig | 8 ++++++-- 4 files changed, 24 insertions(+), 13 deletions(-)
lib/zstd/Makefile +8 -10
@@ -10,14 +10,10 @@ # ################################################################ obj-$(CONFIG_ZSTD_COMPRESS) += zstd_compress.o obj-$(CONFIG_ZSTD_DECOMPRESS) += zstd_decompress.o +obj-$(CONFIG_ZSTD_COMMON) += zstd_common.o zstd_compress-y := \ 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 := \ zstd_decompress-y := \ 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 := \ + common/debug.o \ + common/entropy_common.o \ + common/error_private.o \ + common/fse_decompress.o \ + common/zstd_common.o \
lib/zstd/common/entropy_common.c +3 -1
@@ -15,6 +15,7 @@/* ************************************* * Dependencies ***************************************/ +#include <linux/module.h> #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, headerBuffer, hbSize,/* bmi2 */ 0 ); } - +EXPORT_SYMBOL_GPL (FSE_readNCount);/*! HUF_readStats() : Read compact Huffman tree, saved by HUF_writeCTable().
@@ -255,6 +256,7 @@ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* 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); FORCE_INLINE_TEMPLATE size_t HUF_readStats_body(BYTE* huffWeight, size_t hwSize, U32* rankStats,
lib/zstd/common/zstd_common.c +7 -0
@@ -13,6 +13,7 @@/*-************************************* * Dependencies ***************************************/ +#include <linux/module.h> #define ZSTD_DEPS_NEED_MALLOC #include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */ #include "error_private.h"
@@ -59,6 +60,7 @@ void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)return customMem.customAlloc (customMem.opaque, size);return ZSTD_malloc (size); } +EXPORT_SYMBOL_GPL (ZSTD_customMalloc);void *ZSTD_customCalloc (size_t size,ZSTD_customMem customMem) {
@@ -71,6 +73,7 @@ void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem) }return ZSTD_calloc (1 , size); } +EXPORT_SYMBOL_GPL (ZSTD_customCalloc);void ZSTD_customFree (void * ptr,ZSTD_customMem customMem) {
@@ -81,3 +84,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" );
lib/Kconfig +6 -2
@@ -333,12 +333,16 @@ config LZ4HC_COMPRESS config LZ4_DECOMPRESS tristate +config ZSTD_COMMON + select XXHASH + tristate + config ZSTD_COMPRESS - select XXHASH + select ZSTD_COMMON tristate config ZSTD_DECOMPRESS - select XXHASH + select ZSTD_COMMON tristate source "lib/xz/Kconfig"
Signature · 1 line
2.30.2
Quoted 15 lines · Alexey Kardashevskiy
With
CONFIG_ZSTD_COMPRESS=mandCONFIG_ZSTD_DECOMPRESS=ywe end up in a situation when files fromlib/zstd/common/are compiled once to be linked later forZSTD_DECOMPRESS(build-in) andZSTD_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 values in 'lib/built-in.a(zstd_common.o at 5868)' and 'ld-temp.o'
This particular conflict is caused by KBUILD_CFLAGS=-mcmodel=medium vs. KBUILD_CFLAGS_MODULE=-mcmodel=large , modules use the large model on POWERPC as explained at
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/powerpc/Makefile?h=v5.18-rc4#n127
but the current use of common files is wrong anyway.
Quoted 5 lines
This works around the issue by introducing a
zstd_commonmodule with shared code.Cc Masahiro Yamada <[email protected]>Signed-off-by Alexey Kardashevskiy <[email protected]>
Ping? Thanks,
Quoted 140 lines
---
Changes:
v2:
* add a new module instead of inlining common bits--- lib/zstd/Makefile | 18 ++++++++---------- lib/zstd/common/entropy_common.c | 4 +++- lib/zstd/common/zstd_common.c | 7 +++++++ lib/Kconfig | 8 ++++++-- 4 files changed, 24 insertions(+), 13 deletions(-)lib/zstd/Makefile +8
-10@@ -10,14 +10,10 @@ # ################################################################ obj-$(CONFIG_ZSTD_COMPRESS) += zstd_compress.o obj-$(CONFIG_ZSTD_DECOMPRESS) += zstd_decompress.o +obj-$(CONFIG_ZSTD_COMMON) += zstd_common.o zstd_compress-y := \ 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 := \ zstd_decompress-y := \ 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 := \ + common/debug.o \ + common/entropy_common.o \ + common/error_private.o \ + common/fse_decompress.o \ + common/zstd_common.o \lib/zstd/common/entropy_common.c +3
-1@@ -15,6 +15,7 @@/* ************************************* * Dependencies ***************************************/ +#include <linux/module.h> #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, headerBuffer, hbSize,/* bmi2 */ 0 ); } - +EXPORT_SYMBOL_GPL (FSE_readNCount);/*! HUF_readStats() : Read compact Huffman tree, saved by HUF_writeCTable(). @@ -255,6 +256,7 @@ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* 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); FORCE_INLINE_TEMPLATE size_t HUF_readStats_body(BYTE* huffWeight, size_t hwSize, U32* rankStats,lib/zstd/common/zstd_common.c +7
-0@@ -13,6 +13,7 @@/*-************************************* * Dependencies ***************************************/ +#include <linux/module.h> #define ZSTD_DEPS_NEED_MALLOC #include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */ #include "error_private.h" @@ -59,6 +60,7 @@ void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)return customMem.customAlloc (customMem.opaque, size);return ZSTD_malloc (size); } +EXPORT_SYMBOL_GPL (ZSTD_customMalloc);void *ZSTD_customCalloc (size_t size,ZSTD_customMem customMem) {@@ -71,6 +73,7 @@ void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem) }return ZSTD_calloc (1 , size); } +EXPORT_SYMBOL_GPL (ZSTD_customCalloc);void ZSTD_customFree (void * ptr,ZSTD_customMem customMem) {@@ -81,3 +84,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" );lib/Kconfig +6
-2@@ -333,12 +333,16 @@ config LZ4HC_COMPRESS config LZ4_DECOMPRESS tristate +config ZSTD_COMMON + select XXHASH + tristate + config ZSTD_COMPRESS - select XXHASH + select ZSTD_COMMON tristate config ZSTD_DECOMPRESS - select XXHASH + select ZSTD_COMMON tristate source "lib/xz/Kconfig"
Masahiro Yamada
Reviewed-byQuoted 19 lines · Alexey Kardashevskiy
Quoted 15 lines · Alexey Kardashevskiy
With
CONFIG_ZSTD_COMPRESS=mandCONFIG_ZSTD_DECOMPRESS=ywe end up in a situation when files fromlib/zstd/common/are compiled once to be linked later forZSTD_DECOMPRESS(build-in) andZSTD_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 values in 'lib/built-in.a(zstd_common.o at 5868)' and 'ld-temp.o'
This particular conflict is caused by KBUILD_CFLAGS=-mcmodel=medium vs. KBUILD_CFLAGS_MODULE=-mcmodel=large , modules use the large model on POWERPC as explained at
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/powerpc/Makefile?h=v5.18-rc4#n127
but the current use of common files is wrong anyway.
Quoted 8 lines
Quoted 5 lines
This works around the issue by introducing a
zstd_commonmodule with shared code.Cc Masahiro Yamada <[email protected]>Signed-off-by Alexey Kardashevskiy <[email protected]>Ping? Thanks,
Signature · 2 lines
Best Regards Masahiro Yamada
Hi Nick,
Did you have any thoughts on this patch? It is necessary for enabling LTO with PowerPC:
https://lore.kernel.org/[email protected]/
If you don't have anything to send to Linus for the next cycle, perhaps this patch could be carried by the PowerPC folks with your ack?
Cheers,
Nathan
Quoted 164 lines · Alexey Kardashevskiy
With
CONFIG_ZSTD_COMPRESS=mandCONFIG_ZSTD_DECOMPRESS=ywe end up in a situation when files fromlib/zstd/common/are compiled once to be linked later forZSTD_DECOMPRESS(build-in) andZSTD_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 values in 'lib/built-in.a(zstd_common.o at 5868)' and 'ld-temp.o'
This particular conflict is caused by KBUILD_CFLAGS=-mcmodel=medium vs. KBUILD_CFLAGS_MODULE=-mcmodel=large , modules use the large model on POWERPC as explained at
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/powerpc/Makefile?h=v5.18-rc4#n127
but the current use of common files is wrong anyway.This works around the issue by introducing a
zstd_commonmodule with shared code.Cc Masahiro Yamada <[email protected]>Signed-off-by Alexey Kardashevskiy <[email protected]>---
Changes:
v2:
* add a new module instead of inlining common bits--- lib/zstd/Makefile | 18 ++++++++---------- lib/zstd/common/entropy_common.c | 4 +++- lib/zstd/common/zstd_common.c | 7 +++++++ lib/Kconfig | 8 ++++++-- 4 files changed, 24 insertions(+), 13 deletions(-)lib/zstd/Makefile +8
-10@@ -10,14 +10,10 @@ # ################################################################ obj-$(CONFIG_ZSTD_COMPRESS) += zstd_compress.o obj-$(CONFIG_ZSTD_DECOMPRESS) += zstd_decompress.o +obj-$(CONFIG_ZSTD_COMMON) += zstd_common.o zstd_compress-y := \ 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 := \ zstd_decompress-y := \ 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 := \ + common/debug.o \ + common/entropy_common.o \ + common/error_private.o \ + common/fse_decompress.o \ + common/zstd_common.o \lib/zstd/common/entropy_common.c +3
-1@@ -15,6 +15,7 @@/* ************************************* * Dependencies ***************************************/ +#include <linux/module.h> #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, headerBuffer, hbSize,/* bmi2 */ 0 ); } - +EXPORT_SYMBOL_GPL (FSE_readNCount);/*! HUF_readStats() : Read compact Huffman tree, saved by HUF_writeCTable(). @@ -255,6 +256,7 @@ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* 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); FORCE_INLINE_TEMPLATE size_t HUF_readStats_body(BYTE* huffWeight, size_t hwSize, U32* rankStats,lib/zstd/common/zstd_common.c +7
-0@@ -13,6 +13,7 @@/*-************************************* * Dependencies ***************************************/ +#include <linux/module.h> #define ZSTD_DEPS_NEED_MALLOC #include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */ #include "error_private.h" @@ -59,6 +60,7 @@ void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)return customMem.customAlloc (customMem.opaque, size);return ZSTD_malloc (size); } +EXPORT_SYMBOL_GPL (ZSTD_customMalloc);void *ZSTD_customCalloc (size_t size,ZSTD_customMem customMem) {@@ -71,6 +73,7 @@ void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem) }return ZSTD_calloc (1 , size); } +EXPORT_SYMBOL_GPL (ZSTD_customCalloc);void ZSTD_customFree (void * ptr,ZSTD_customMem customMem) {@@ -81,3 +84,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" );lib/Kconfig +6
-2@@ -333,12 +333,16 @@ config LZ4HC_COMPRESS config LZ4_DECOMPRESS tristate +config ZSTD_COMMON + select XXHASH + tristate + config ZSTD_COMPRESS - select XXHASH + select ZSTD_COMMON tristate config ZSTD_DECOMPRESS - select XXHASH + select ZSTD_COMMON tristate source "lib/xz/Kconfig"Signature · 1 line
2.30.2
Ping?
Quoted 178 lines · Nathan Chancellor
Hi Nick,
Did you have any thoughts on this patch? It is necessary for enabling LTO with PowerPC:
https://lore.kernel.org/[email protected]/
If you don't have anything to send to Linus for the next cycle, perhaps this patch could be carried by the PowerPC folks with your ack?
Cheers,
NathanQuoted 164 lines · Alexey Kardashevskiy
With
CONFIG_ZSTD_COMPRESS=mandCONFIG_ZSTD_DECOMPRESS=ywe end up in a situation when files fromlib/zstd/common/are compiled once to be linked later forZSTD_DECOMPRESS(build-in) andZSTD_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 values in 'lib/built-in.a(zstd_common.o at 5868)' and 'ld-temp.o'
This particular conflict is caused by KBUILD_CFLAGS=-mcmodel=medium vs. KBUILD_CFLAGS_MODULE=-mcmodel=large , modules use the large model on POWERPC as explained at
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/powerpc/Makefile?h=v5.18-rc4#n127
but the current use of common files is wrong anyway.This works around the issue by introducing a
zstd_commonmodule with shared code.Cc Masahiro Yamada <[email protected]>Signed-off-by Alexey Kardashevskiy <[email protected]>---
Changes:
v2:
* add a new module instead of inlining common bits--- lib/zstd/Makefile | 18 ++++++++---------- lib/zstd/common/entropy_common.c | 4 +++- lib/zstd/common/zstd_common.c | 7 +++++++ lib/Kconfig | 8 ++++++-- 4 files changed, 24 insertions(+), 13 deletions(-)lib/zstd/Makefile +8
-10@@ -10,14 +10,10 @@ # ################################################################ obj-$(CONFIG_ZSTD_COMPRESS) += zstd_compress.o obj-$(CONFIG_ZSTD_DECOMPRESS) += zstd_decompress.o +obj-$(CONFIG_ZSTD_COMMON) += zstd_common.o zstd_compress-y := \ 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 := \ zstd_decompress-y := \ 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 := \ + common/debug.o \ + common/entropy_common.o \ + common/error_private.o \ + common/fse_decompress.o \ + common/zstd_common.o \lib/zstd/common/entropy_common.c +3
-1@@ -15,6 +15,7 @@/* ************************************* * Dependencies ***************************************/ +#include <linux/module.h> #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, headerBuffer, hbSize,/* bmi2 */ 0 ); } - +EXPORT_SYMBOL_GPL (FSE_readNCount);/*! HUF_readStats() : Read compact Huffman tree, saved by HUF_writeCTable(). @@ -255,6 +256,7 @@ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* 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); FORCE_INLINE_TEMPLATE size_t HUF_readStats_body(BYTE* huffWeight, size_t hwSize, U32* rankStats,lib/zstd/common/zstd_common.c +7
-0@@ -13,6 +13,7 @@/*-************************************* * Dependencies ***************************************/ +#include <linux/module.h> #define ZSTD_DEPS_NEED_MALLOC #include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */ #include "error_private.h" @@ -59,6 +60,7 @@ void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)return customMem.customAlloc (customMem.opaque, size);return ZSTD_malloc (size); } +EXPORT_SYMBOL_GPL (ZSTD_customMalloc);void *ZSTD_customCalloc (size_t size,ZSTD_customMem customMem) {@@ -71,6 +73,7 @@ void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem) }return ZSTD_calloc (1 , size); } +EXPORT_SYMBOL_GPL (ZSTD_customCalloc);void ZSTD_customFree (void * ptr,ZSTD_customMem customMem) {@@ -81,3 +84,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" );lib/Kconfig +6
-2@@ -333,12 +333,16 @@ config LZ4HC_COMPRESS config LZ4_DECOMPRESS tristate +config ZSTD_COMMON + select XXHASH + tristate + config ZSTD_COMPRESS - select XXHASH + select ZSTD_COMMON tristate config ZSTD_DECOMPRESS - select XXHASH + select ZSTD_COMMON tristate source "lib/xz/Kconfig"Signature · 1 line
2.30.2
Signature · 1 line
Alexey
Ping? It's about 2 months now :)
Quoted 178 lines · Alexey Kardashevskiy
Ping?
Quoted 173 lines · Nathan Chancellor
Hi Nick,
Did you have any thoughts on this patch? It is necessary for enabling LTO with PowerPC:
https://lore.kernel.org/[email protected]/
If you don't have anything to send to Linus for the next cycle, perhaps this patch could be carried by the PowerPC folks with your ack?
Cheers,
NathanQuoted 159 lines · Alexey Kardashevskiy
With
CONFIG_ZSTD_COMPRESS=mandCONFIG_ZSTD_DECOMPRESS=ywe end up in a situation when files fromlib/zstd/common/are compiled once to be linked later forZSTD_DECOMPRESS(build-in) andZSTD_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 values in 'lib/built-in.a(zstd_common.o at 5868)' and 'ld-temp.o'
This particular conflict is caused by KBUILD_CFLAGS=-mcmodel=medium vs. KBUILD_CFLAGS_MODULE=-mcmodel=large , modules use the large model on POWERPC as explained at
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/powerpc/Makefile?h=v5.18-rc4#n127
but the current use of common files is wrong anyway.This works around the issue by introducing a
zstd_commonmodule with shared code.Cc Masahiro Yamada <[email protected]>Signed-off-by Alexey Kardashevskiy <[email protected]>---
Changes:
v2:
* add a new module instead of inlining common bits---
lib/zstd/Makefile | 18 ++++++++----------lib/zstd/common/entropy_common.c| 4 +++- lib/zstd/common/zstd_common.c | 7 +++++++ lib/Kconfig | 8 ++++++--4 files changed, 24 insertions(+), 13 deletions(-)lib/zstd/Makefile +0
-0@@ -10,14 +10,10 @@ # ################################################################obj-$(CONFIG_ZSTD_COMPRESS) += zstd_compress.o obj-$(CONFIG_ZSTD_DECOMPRESS) += zstd_decompress.o +obj-$(CONFIG_ZSTD_COMMON) += zstd_common.o zstd_compress-y := \
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\lib/zstd/Makefile +7
-5@@ -33,12 +29,14 @@ zstd_compress-y := \ zstd_decompress-y := \ 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 := \ + common/debug.o \ + common/entropy_common.o \ + common/error_private.o \ + common/fse_decompress.o \ + common/zstd_common.o \lib/zstd/common/entropy_common.c +2
-1@@ -15,6 +15,7 @@ /* ************************************** Dependencies ***************************************/ +#include <linux/module.h> #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, headerBuffer, hbSize, /* bmi2 */ 0); } - +EXPORT_SYMBOL_GPL (FSE_readNCount); /*! HUF_readStats() :Read compact Huffman tree, saved by
HUF_writeCTable().lib/zstd/common/entropy_common.c +1
-0@@ -255,6 +256,7 @@ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize,U32 * 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);
FORCE_INLINE_TEMPLATEsize_t
HUF_readStats_body(BYTE* huffWeight,size_thwSize, U32* rankStats,lib/zstd/common/zstd_common.c +3
-0@@ -13,6 +13,7 @@ /*-************************************** Dependencies ***************************************/ +#include <linux/module.h> #define ZSTD_DEPS_NEED_MALLOC #include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */ #include "error_private.h"@@ -59,6 +60,7 @@ void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem) return customMem.customAlloc(customMem.opaque, size); return ZSTD_malloc(size); } +EXPORT_SYMBOL_GPL (ZSTD_customMalloc); void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem) {@@ -71,6 +73,7 @@ void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem) } return ZSTD_calloc(1, size); } +EXPORT_SYMBOL_GPL (ZSTD_customCalloc); void ZSTD_customFree(void* ptr, ZSTD_customMem customMem) {@@ -81,3 +84,7 @@ void ZSTD_customFree(void* ptr, ZSTD_customMem customMem) ZSTD_free(ptr); }}
lib/zstd/common/zstd_common.c +4
-0+EXPORT_SYMBOL_GPL (ZSTD_customFree); + +MODULE_LICENSE ("Dual BSD/GPL" ); +MODULE_DESCRIPTION ("Zstd Common" );lib/Kconfig +0
-0@@ -333,12 +333,16 @@ config LZ4HC_COMPRESSconfig
LZ4_DECOMPRESS
tristatelib/Kconfig +4
-0+config ZSTD_COMMON + select XXHASH + tristate +config
ZSTD_COMPRESS
- select XXHASH
+ selectZSTD_COMMON
tristate
configZSTD_DECOMPRESS
- select XXHASH
+ selectZSTD_COMMON
tristate
source "lib/xz/Kconfig"Signature · 1 line
2.30.2
Signature · 1 line
Alexey
Quoted 8 lines · Alexey Kardashevskiy
Ping? It's about 2 months now :)
Quoted 3 lines · Alexey Kardashevskiy
Ping?
Applied to linux-kbuild.
Thanks.
Quoted 186 lines
Quoted 174 lines · Nathan Chancellor
Quoted 173 lines
Hi Nick,
Did you have any thoughts on this patch? It is necessary for enabling LTO with PowerPC:
https://lore.kernel.org/[email protected]/
If you don't have anything to send to Linus for the next cycle, perhaps this patch could be carried by the PowerPC folks with your ack?
Cheers,
NathanQuoted 159 lines · Alexey Kardashevskiy
With
CONFIG_ZSTD_COMPRESS=mandCONFIG_ZSTD_DECOMPRESS=ywe end up in a situation when files fromlib/zstd/common/are compiled once to be linked later forZSTD_DECOMPRESS(build-in) andZSTD_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 values in 'lib/built-in.a(zstd_common.o at 5868)' and 'ld-temp.o'
This particular conflict is caused by KBUILD_CFLAGS=-mcmodel=medium vs. KBUILD_CFLAGS_MODULE=-mcmodel=large , modules use the large model on POWERPC as explained at
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/powerpc/Makefile?h=v5.18-rc4#n127
but the current use of common files is wrong anyway.This works around the issue by introducing a
zstd_commonmodule with shared code.Cc Masahiro Yamada <[email protected]>Signed-off-by Alexey Kardashevskiy <[email protected]>---
Changes:
v2:
* add a new module instead of inlining common bits--- lib/zstd/Makefile | 18 ++++++++---------- lib/zstd/common/entropy_common.c | 4 +++- lib/zstd/common/zstd_common.c | 7 +++++++ lib/Kconfig | 8 ++++++-- 4 files changed, 24 insertions(+), 13 deletions(-)lib/zstd/Makefile +8
-10@@ -10,14 +10,10 @@ # ################################################################ obj-$(CONFIG_ZSTD_COMPRESS) += zstd_compress.o obj-$(CONFIG_ZSTD_DECOMPRESS) += zstd_decompress.o +obj-$(CONFIG_ZSTD_COMMON) += zstd_common.o zstd_compress-y := \ 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 := \ zstd_decompress-y := \ 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 := \ + common/debug.o \ + common/entropy_common.o \ + common/error_private.o \ + common/fse_decompress.o \ + common/zstd_common.o \lib/zstd/common/entropy_common.c +2
-1@@ -15,6 +15,7 @@/* ************************************* * Dependencies ***************************************/ +#include <linux/module.h> #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, headerBuffer, hbSize,/* bmi2 */ 0 ); } - +EXPORT_SYMBOL_GPL (FSE_readNCount);/*! HUF_readStats() : Read compact Huffman tree, saved by HUF_writeCTable(). @@ -255,6 +256,7 @@ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize,U32 * 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);
}lib/zstd/common/entropy_common.c +1
-0+EXPORT_SYMBOL_GPL (HUF_readStats); FORCE_INLINE_TEMPLATE size_t HUF_readStats_body(BYTE* huffWeight, size_t hwSize, U32* rankStats,lib/zstd/common/zstd_common.c +1
-0@@ -13,6 +13,7 @@/*-************************************* * Dependencies ***************************************/ +#include <linux/module.h> #define ZSTD_DEPS_NEED_MALLOC #include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free,
ZSTD_memset*/
#include "error_private.h"lib/zstd/common/zstd_common.c +6
-0@@ -59,6 +60,7 @@ void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)return customMem.customAlloc (customMem.opaque, size);return ZSTD_malloc (size); } +EXPORT_SYMBOL_GPL (ZSTD_customMalloc);void *ZSTD_customCalloc (size_t size,ZSTD_customMem customMem) {@@ -71,6 +73,7 @@ void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem) }return ZSTD_calloc (1 , size); } +EXPORT_SYMBOL_GPL (ZSTD_customCalloc);void ZSTD_customFree (void * ptr,ZSTD_customMem customMem) {@@ -81,3 +84,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" );lib/Kconfig +5
-1@@ -333,12 +333,16 @@ config LZ4HC_COMPRESS config LZ4_DECOMPRESS tristate +config ZSTD_COMMON + select XXHASH + tristate + config ZSTD_COMPRESS - select XXHASH + select ZSTD_COMMON tristate config ZSTD_DECOMPRESSQuoted 9 lines
Quoted 8 lines
Quoted 8 lines
lib/Kconfig +1
-2- select XXHASH + select ZSTD_COMMON tristate source "lib/xz/Kconfig" --2.30.2
--
Alexey
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 14 lines · Masahiro Yamada
Quoted 8 lines · Alexey Kardashevskiy
Ping? It's about 2 months now :)
Quoted 3 lines · Alexey Kardashevskiy
Ping?
Quoted 2 lines
Applied to linux-kbuild.
Thanks.
I dropped the patch from my tree because
I confirmed that the mainline + this patch
breaks the build.
Please check the 0day report:
https://lore.kernel.org/lkml/[email protected]/
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 19 lines · Masahiro Yamada
Quoted 14 lines · Masahiro Yamada
Quoted 8 lines · Alexey Kardashevskiy
Ping? It's about 2 months now :)
Quoted 3 lines · Alexey Kardashevskiy
Ping?
Quoted 2 lines
Applied to linux-kbuild.
Thanks.
Quoted 7 lines
I dropped the patch from my tree because
I confirmed that the mainline + this patch
breaks the build.Please check the 0day report:
Ouch, missed few exports, sorry. I've reproduced this with x86 config and posted v3. Thanks,
Quoted 4 lines
Signature · 1 line
Alexey