Re: [PATCH] lib: zstd: build common files separately for compress and decompress

From: Masahiro Yamada
Date: Mon Sep 19 2022 - 08:53:07 EST


On Mon, Sep 19, 2022 at 9:04 PM Nicholas Piggin <npiggin@xxxxxxxxx> wrote:
>
> It is possible for compress to be built as a module and decompress to
> be built in, and kernel and module C flags can be different. This can
> cause module built code to be linked into the kernel or vice versa.
>
> Use symbolic links from the common code to compression and decompression
> module directories to avoid this problem.
>
> Signed-off-by: Nicholas Piggin <npiggin@xxxxxxxxx>
> ---
> I'm not sure if this is the preferred way to fix it. I hadn't
> thought about this problem before but now I notice it in zstd
> it seems like it could be a pitfall in other parts of the kernel
> as well.


I will apply the following instead.

https://lore.kernel.org/all/20220429053329.2278740-1-aik@xxxxxxxxx/



> Is there a better way to solve it? Or some way to
> automatically detect the conflict and fail the build rather than
> silently succeed?


There is a way to detect this, but let me check if there are more
instances that do similar things like zstd.
If I remember correctly, there are some more.








> Thanks,
> Nick
>
> lib/zstd/Makefile | 20 ++++++++++----------
> lib/zstd/compress/common/bitstream.h | 1 +
> lib/zstd/compress/common/compiler.h | 1 +
> lib/zstd/compress/common/cpu.h | 1 +
> lib/zstd/compress/common/debug.c | 1 +
> lib/zstd/compress/common/debug.h | 1 +
> lib/zstd/compress/common/entropy_common.c | 1 +
> lib/zstd/compress/common/error_private.c | 1 +
> lib/zstd/compress/common/error_private.h | 1 +
> lib/zstd/compress/common/fse.h | 1 +
> lib/zstd/compress/common/fse_decompress.c | 1 +
> lib/zstd/compress/common/huf.h | 1 +
> lib/zstd/compress/common/mem.h | 1 +
> lib/zstd/compress/common/zstd_common.c | 1 +
> lib/zstd/compress/common/zstd_deps.h | 1 +
> lib/zstd/compress/common/zstd_internal.h | 1 +
> lib/zstd/decompress/common/bitstream.h | 1 +
> lib/zstd/decompress/common/compiler.h | 1 +
> lib/zstd/decompress/common/cpu.h | 1 +
> lib/zstd/decompress/common/debug.c | 1 +
> lib/zstd/decompress/common/debug.h | 1 +
> lib/zstd/decompress/common/entropy_common.c | 1 +
> lib/zstd/decompress/common/error_private.c | 1 +
> lib/zstd/decompress/common/error_private.h | 1 +
> lib/zstd/decompress/common/fse.h | 1 +
> lib/zstd/decompress/common/fse_decompress.c | 1 +
> lib/zstd/decompress/common/huf.h | 1 +
> lib/zstd/decompress/common/mem.h | 1 +
> lib/zstd/decompress/common/zstd_common.c | 1 +
> lib/zstd/decompress/common/zstd_deps.h | 1 +
> lib/zstd/decompress/common/zstd_internal.h | 1 +
> 31 files changed, 40 insertions(+), 10 deletions(-)
> create mode 120000 lib/zstd/compress/common/bitstream.h
> create mode 120000 lib/zstd/compress/common/compiler.h
> create mode 120000 lib/zstd/compress/common/cpu.h
> create mode 120000 lib/zstd/compress/common/debug.c
> create mode 120000 lib/zstd/compress/common/debug.h
> create mode 120000 lib/zstd/compress/common/entropy_common.c
> create mode 120000 lib/zstd/compress/common/error_private.c
> create mode 120000 lib/zstd/compress/common/error_private.h
> create mode 120000 lib/zstd/compress/common/fse.h
> create mode 120000 lib/zstd/compress/common/fse_decompress.c
> create mode 120000 lib/zstd/compress/common/huf.h
> create mode 120000 lib/zstd/compress/common/mem.h
> create mode 120000 lib/zstd/compress/common/zstd_common.c
> create mode 120000 lib/zstd/compress/common/zstd_deps.h
> create mode 120000 lib/zstd/compress/common/zstd_internal.h
> create mode 120000 lib/zstd/decompress/common/bitstream.h
> create mode 120000 lib/zstd/decompress/common/compiler.h
> create mode 120000 lib/zstd/decompress/common/cpu.h
> create mode 120000 lib/zstd/decompress/common/debug.c
> create mode 120000 lib/zstd/decompress/common/debug.h
> create mode 120000 lib/zstd/decompress/common/entropy_common.c
> create mode 120000 lib/zstd/decompress/common/error_private.c
> create mode 120000 lib/zstd/decompress/common/error_private.h
> create mode 120000 lib/zstd/decompress/common/fse.h
> create mode 120000 lib/zstd/decompress/common/fse_decompress.c
> create mode 120000 lib/zstd/decompress/common/huf.h
> create mode 120000 lib/zstd/decompress/common/mem.h
> create mode 120000 lib/zstd/decompress/common/zstd_common.c
> create mode 120000 lib/zstd/decompress/common/zstd_deps.h
> create mode 120000 lib/zstd/decompress/common/zstd_internal.h
>
> diff --git a/lib/zstd/Makefile b/lib/zstd/Makefile
> index fc45339fc3a3..6d785268f8c3 100644
> --- a/lib/zstd/Makefile
> +++ b/lib/zstd/Makefile
> @@ -13,11 +13,11 @@ obj-$(CONFIG_ZSTD_DECOMPRESS) += zstd_decompress.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/common/debug.o \
> + compress/common/entropy_common.o \
> + compress/common/error_private.o \
> + compress/common/fse_decompress.o \
> + compress/common/zstd_common.o \
> compress/fse_compress.o \
> compress/hist.o \
> compress/huf_compress.o \
> @@ -33,11 +33,11 @@ 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/common/debug.o \
> + decompress/common/entropy_common.o \
> + decompress/common/error_private.o \
> + decompress/common/fse_decompress.o \
> + decompress/common/zstd_common.o \
> decompress/huf_decompress.o \
> decompress/zstd_ddict.o \
> decompress/zstd_decompress.o \
> diff --git a/lib/zstd/compress/common/bitstream.h b/lib/zstd/compress/common/bitstream.h
> new file mode 120000
> index 000000000000..de97b72f47ce
> --- /dev/null
> +++ b/lib/zstd/compress/common/bitstream.h
> @@ -0,0 +1 @@
> +../../common/bitstream.h
> \ No newline at end of file
> diff --git a/lib/zstd/compress/common/compiler.h b/lib/zstd/compress/common/compiler.h
> new file mode 120000
> index 000000000000..a316286adf05
> --- /dev/null
> +++ b/lib/zstd/compress/common/compiler.h
> @@ -0,0 +1 @@
> +../../common/compiler.h
> \ No newline at end of file
> diff --git a/lib/zstd/compress/common/cpu.h b/lib/zstd/compress/common/cpu.h
> new file mode 120000
> index 000000000000..35282be494a2
> --- /dev/null
> +++ b/lib/zstd/compress/common/cpu.h
> @@ -0,0 +1 @@
> +../../common/cpu.h
> \ No newline at end of file
> diff --git a/lib/zstd/compress/common/debug.c b/lib/zstd/compress/common/debug.c
> new file mode 120000
> index 000000000000..5d7b272026d6
> --- /dev/null
> +++ b/lib/zstd/compress/common/debug.c
> @@ -0,0 +1 @@
> +../../common/debug.c
> \ No newline at end of file
> diff --git a/lib/zstd/compress/common/debug.h b/lib/zstd/compress/common/debug.h
> new file mode 120000
> index 000000000000..15c1e1cd5c95
> --- /dev/null
> +++ b/lib/zstd/compress/common/debug.h
> @@ -0,0 +1 @@
> +../../common/debug.h
> \ No newline at end of file
> diff --git a/lib/zstd/compress/common/entropy_common.c b/lib/zstd/compress/common/entropy_common.c
> new file mode 120000
> index 000000000000..221119c32817
> --- /dev/null
> +++ b/lib/zstd/compress/common/entropy_common.c
> @@ -0,0 +1 @@
> +../../common/entropy_common.c
> \ No newline at end of file
> diff --git a/lib/zstd/compress/common/error_private.c b/lib/zstd/compress/common/error_private.c
> new file mode 120000
> index 000000000000..f87d3cf6851f
> --- /dev/null
> +++ b/lib/zstd/compress/common/error_private.c
> @@ -0,0 +1 @@
> +../../common/error_private.c
> \ No newline at end of file
> diff --git a/lib/zstd/compress/common/error_private.h b/lib/zstd/compress/common/error_private.h
> new file mode 120000
> index 000000000000..30d469222942
> --- /dev/null
> +++ b/lib/zstd/compress/common/error_private.h
> @@ -0,0 +1 @@
> +../../common/error_private.h
> \ No newline at end of file
> diff --git a/lib/zstd/compress/common/fse.h b/lib/zstd/compress/common/fse.h
> new file mode 120000
> index 000000000000..29c44ebdd2da
> --- /dev/null
> +++ b/lib/zstd/compress/common/fse.h
> @@ -0,0 +1 @@
> +../../common/fse.h
> \ No newline at end of file
> diff --git a/lib/zstd/compress/common/fse_decompress.c b/lib/zstd/compress/common/fse_decompress.c
> new file mode 120000
> index 000000000000..658e375541f1
> --- /dev/null
> +++ b/lib/zstd/compress/common/fse_decompress.c
> @@ -0,0 +1 @@
> +../../common/fse_decompress.c
> \ No newline at end of file
> diff --git a/lib/zstd/compress/common/huf.h b/lib/zstd/compress/common/huf.h
> new file mode 120000
> index 000000000000..7c9142232da6
> --- /dev/null
> +++ b/lib/zstd/compress/common/huf.h
> @@ -0,0 +1 @@
> +../../common/huf.h
> \ No newline at end of file
> diff --git a/lib/zstd/compress/common/mem.h b/lib/zstd/compress/common/mem.h
> new file mode 120000
> index 000000000000..0d9921eb1ca4
> --- /dev/null
> +++ b/lib/zstd/compress/common/mem.h
> @@ -0,0 +1 @@
> +../../common/mem.h
> \ No newline at end of file
> diff --git a/lib/zstd/compress/common/zstd_common.c b/lib/zstd/compress/common/zstd_common.c
> new file mode 120000
> index 000000000000..5a7475cd3b87
> --- /dev/null
> +++ b/lib/zstd/compress/common/zstd_common.c
> @@ -0,0 +1 @@
> +../../common/zstd_common.c
> \ No newline at end of file
> diff --git a/lib/zstd/compress/common/zstd_deps.h b/lib/zstd/compress/common/zstd_deps.h
> new file mode 120000
> index 000000000000..21b3a7e967da
> --- /dev/null
> +++ b/lib/zstd/compress/common/zstd_deps.h
> @@ -0,0 +1 @@
> +../../common/zstd_deps.h
> \ No newline at end of file
> diff --git a/lib/zstd/compress/common/zstd_internal.h b/lib/zstd/compress/common/zstd_internal.h
> new file mode 120000
> index 000000000000..3bf2b94e718f
> --- /dev/null
> +++ b/lib/zstd/compress/common/zstd_internal.h
> @@ -0,0 +1 @@
> +../../common/zstd_internal.h
> \ No newline at end of file
> diff --git a/lib/zstd/decompress/common/bitstream.h b/lib/zstd/decompress/common/bitstream.h
> new file mode 120000
> index 000000000000..de97b72f47ce
> --- /dev/null
> +++ b/lib/zstd/decompress/common/bitstream.h
> @@ -0,0 +1 @@
> +../../common/bitstream.h
> \ No newline at end of file
> diff --git a/lib/zstd/decompress/common/compiler.h b/lib/zstd/decompress/common/compiler.h
> new file mode 120000
> index 000000000000..a316286adf05
> --- /dev/null
> +++ b/lib/zstd/decompress/common/compiler.h
> @@ -0,0 +1 @@
> +../../common/compiler.h
> \ No newline at end of file
> diff --git a/lib/zstd/decompress/common/cpu.h b/lib/zstd/decompress/common/cpu.h
> new file mode 120000
> index 000000000000..35282be494a2
> --- /dev/null
> +++ b/lib/zstd/decompress/common/cpu.h
> @@ -0,0 +1 @@
> +../../common/cpu.h
> \ No newline at end of file
> diff --git a/lib/zstd/decompress/common/debug.c b/lib/zstd/decompress/common/debug.c
> new file mode 120000
> index 000000000000..5d7b272026d6
> --- /dev/null
> +++ b/lib/zstd/decompress/common/debug.c
> @@ -0,0 +1 @@
> +../../common/debug.c
> \ No newline at end of file
> diff --git a/lib/zstd/decompress/common/debug.h b/lib/zstd/decompress/common/debug.h
> new file mode 120000
> index 000000000000..15c1e1cd5c95
> --- /dev/null
> +++ b/lib/zstd/decompress/common/debug.h
> @@ -0,0 +1 @@
> +../../common/debug.h
> \ No newline at end of file
> diff --git a/lib/zstd/decompress/common/entropy_common.c b/lib/zstd/decompress/common/entropy_common.c
> new file mode 120000
> index 000000000000..221119c32817
> --- /dev/null
> +++ b/lib/zstd/decompress/common/entropy_common.c
> @@ -0,0 +1 @@
> +../../common/entropy_common.c
> \ No newline at end of file
> diff --git a/lib/zstd/decompress/common/error_private.c b/lib/zstd/decompress/common/error_private.c
> new file mode 120000
> index 000000000000..f87d3cf6851f
> --- /dev/null
> +++ b/lib/zstd/decompress/common/error_private.c
> @@ -0,0 +1 @@
> +../../common/error_private.c
> \ No newline at end of file
> diff --git a/lib/zstd/decompress/common/error_private.h b/lib/zstd/decompress/common/error_private.h
> new file mode 120000
> index 000000000000..30d469222942
> --- /dev/null
> +++ b/lib/zstd/decompress/common/error_private.h
> @@ -0,0 +1 @@
> +../../common/error_private.h
> \ No newline at end of file
> diff --git a/lib/zstd/decompress/common/fse.h b/lib/zstd/decompress/common/fse.h
> new file mode 120000
> index 000000000000..29c44ebdd2da
> --- /dev/null
> +++ b/lib/zstd/decompress/common/fse.h
> @@ -0,0 +1 @@
> +../../common/fse.h
> \ No newline at end of file
> diff --git a/lib/zstd/decompress/common/fse_decompress.c b/lib/zstd/decompress/common/fse_decompress.c
> new file mode 120000
> index 000000000000..658e375541f1
> --- /dev/null
> +++ b/lib/zstd/decompress/common/fse_decompress.c
> @@ -0,0 +1 @@
> +../../common/fse_decompress.c
> \ No newline at end of file
> diff --git a/lib/zstd/decompress/common/huf.h b/lib/zstd/decompress/common/huf.h
> new file mode 120000
> index 000000000000..7c9142232da6
> --- /dev/null
> +++ b/lib/zstd/decompress/common/huf.h
> @@ -0,0 +1 @@
> +../../common/huf.h
> \ No newline at end of file
> diff --git a/lib/zstd/decompress/common/mem.h b/lib/zstd/decompress/common/mem.h
> new file mode 120000
> index 000000000000..0d9921eb1ca4
> --- /dev/null
> +++ b/lib/zstd/decompress/common/mem.h
> @@ -0,0 +1 @@
> +../../common/mem.h
> \ No newline at end of file
> diff --git a/lib/zstd/decompress/common/zstd_common.c b/lib/zstd/decompress/common/zstd_common.c
> new file mode 120000
> index 000000000000..5a7475cd3b87
> --- /dev/null
> +++ b/lib/zstd/decompress/common/zstd_common.c
> @@ -0,0 +1 @@
> +../../common/zstd_common.c
> \ No newline at end of file
> diff --git a/lib/zstd/decompress/common/zstd_deps.h b/lib/zstd/decompress/common/zstd_deps.h
> new file mode 120000
> index 000000000000..21b3a7e967da
> --- /dev/null
> +++ b/lib/zstd/decompress/common/zstd_deps.h
> @@ -0,0 +1 @@
> +../../common/zstd_deps.h
> \ No newline at end of file
> diff --git a/lib/zstd/decompress/common/zstd_internal.h b/lib/zstd/decompress/common/zstd_internal.h
> new file mode 120000
> index 000000000000..3bf2b94e718f
> --- /dev/null
> +++ b/lib/zstd/decompress/common/zstd_internal.h
> @@ -0,0 +1 @@
> +../../common/zstd_internal.h
> \ No newline at end of file
> --
> 2.37.2
>


--
Best Regards
Masahiro Yamada