Skip to content

Commit 637a642

Browse files
aikmasahir0y
authored andcommitted
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. Signed-off-by: Alexey Kardashevskiy <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent d32b55f commit 637a642

File tree

4 files changed

+27
-12
lines changed

4 files changed

+27
-12
lines changed

lib/Kconfig

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,16 @@ config LZ4HC_COMPRESS
343343
config LZ4_DECOMPRESS
344344
tristate
345345

346-
config ZSTD_COMPRESS
346+
config ZSTD_COMMON
347347
select XXHASH
348348
tristate
349349

350+
config ZSTD_COMPRESS
351+
select ZSTD_COMMON
352+
tristate
353+
350354
config ZSTD_DECOMPRESS
351-
select XXHASH
355+
select ZSTD_COMMON
352356
tristate
353357

354358
source "lib/xz/Kconfig"

lib/zstd/Makefile

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,10 @@
1010
# ################################################################
1111
obj-$(CONFIG_ZSTD_COMPRESS) += zstd_compress.o
1212
obj-$(CONFIG_ZSTD_DECOMPRESS) += zstd_decompress.o
13+
obj-$(CONFIG_ZSTD_COMMON) += zstd_common.o
1314

1415
zstd_compress-y := \
1516
zstd_compress_module.o \
16-
common/debug.o \
17-
common/entropy_common.o \
18-
common/error_private.o \
19-
common/fse_decompress.o \
20-
common/zstd_common.o \
2117
compress/fse_compress.o \
2218
compress/hist.o \
2319
compress/huf_compress.o \
@@ -33,12 +29,14 @@ zstd_compress-y := \
3329

3430
zstd_decompress-y := \
3531
zstd_decompress_module.o \
32+
decompress/huf_decompress.o \
33+
decompress/zstd_ddict.o \
34+
decompress/zstd_decompress.o \
35+
decompress/zstd_decompress_block.o \
36+
37+
zstd_common-y := \
3638
common/debug.o \
3739
common/entropy_common.o \
3840
common/error_private.o \
3941
common/fse_decompress.o \
4042
common/zstd_common.o \
41-
decompress/huf_decompress.o \
42-
decompress/zstd_ddict.o \
43-
decompress/zstd_decompress.o \
44-
decompress/zstd_decompress_block.o \

lib/zstd/common/entropy_common.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
/* *************************************
1616
* Dependencies
1717
***************************************/
18+
#include <linux/module.h>
1819
#include "mem.h"
1920
#include "error_private.h" /* ERR_*, ERROR */
2021
#define FSE_STATIC_LINKING_ONLY /* FSE_MIN_TABLELOG */
@@ -239,7 +240,7 @@ size_t FSE_readNCount(
239240
{
240241
return FSE_readNCount_bmi2(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize, /* bmi2 */ 0);
241242
}
242-
243+
EXPORT_SYMBOL_GPL(FSE_readNCount);
243244

244245
/*! HUF_readStats() :
245246
Read compact Huffman tree, saved by HUF_writeCTable().
@@ -255,6 +256,7 @@ size_t HUF_readStats(BYTE* huffWeight, size_t hwSize, U32* rankStats,
255256
U32 wksp[HUF_READ_STATS_WORKSPACE_SIZE_U32];
256257
return HUF_readStats_wksp(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, wksp, sizeof(wksp), /* bmi2 */ 0);
257258
}
259+
EXPORT_SYMBOL_GPL(HUF_readStats);
258260

259261
FORCE_INLINE_TEMPLATE size_t
260262
HUF_readStats_body(BYTE* huffWeight, size_t hwSize, U32* rankStats,
@@ -355,3 +357,4 @@ size_t HUF_readStats_wksp(BYTE* huffWeight, size_t hwSize, U32* rankStats,
355357
(void)bmi2;
356358
return HUF_readStats_body_default(huffWeight, hwSize, rankStats, nbSymbolsPtr, tableLogPtr, src, srcSize, workSpace, wkspSize);
357359
}
360+
EXPORT_SYMBOL_GPL(HUF_readStats_wksp);

lib/zstd/common/zstd_common.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
/*-*************************************
1414
* Dependencies
1515
***************************************/
16+
#include <linux/module.h>
1617
#define ZSTD_DEPS_NEED_MALLOC
1718
#include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */
1819
#include "error_private.h"
@@ -35,14 +36,17 @@ const char* ZSTD_versionString(void) { return ZSTD_VERSION_STRING; }
3536
* tells if a return value is an error code
3637
* symbol is required for external callers */
3738
unsigned ZSTD_isError(size_t code) { return ERR_isError(code); }
39+
EXPORT_SYMBOL_GPL(ZSTD_isError);
3840

3941
/*! ZSTD_getErrorName() :
4042
* provides error code string from function result (useful for debugging) */
4143
const char* ZSTD_getErrorName(size_t code) { return ERR_getErrorName(code); }
44+
EXPORT_SYMBOL_GPL(ZSTD_getErrorName);
4245

4346
/*! ZSTD_getError() :
4447
* convert a `size_t` function result into a proper ZSTD_errorCode enum */
4548
ZSTD_ErrorCode ZSTD_getErrorCode(size_t code) { return ERR_getErrorCode(code); }
49+
EXPORT_SYMBOL_GPL(ZSTD_getErrorCode);
4650

4751
/*! ZSTD_getErrorString() :
4852
* provides error code string from enum */
@@ -59,6 +63,7 @@ void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
5963
return customMem.customAlloc(customMem.opaque, size);
6064
return ZSTD_malloc(size);
6165
}
66+
EXPORT_SYMBOL_GPL(ZSTD_customMalloc);
6267

6368
void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
6469
{
@@ -71,6 +76,7 @@ void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
7176
}
7277
return ZSTD_calloc(1, size);
7378
}
79+
EXPORT_SYMBOL_GPL(ZSTD_customCalloc);
7480

7581
void ZSTD_customFree(void* ptr, ZSTD_customMem customMem)
7682
{
@@ -81,3 +87,7 @@ void ZSTD_customFree(void* ptr, ZSTD_customMem customMem)
8187
ZSTD_free(ptr);
8288
}
8389
}
90+
EXPORT_SYMBOL_GPL(ZSTD_customFree);
91+
92+
MODULE_LICENSE("Dual BSD/GPL");
93+
MODULE_DESCRIPTION("Zstd Common");

0 commit comments

Comments
 (0)