lz4 / lz4

Extremely Fast Compression algorithm
http://www.lz4.org
Other
10.22k stars 1.38k forks source link

UNIX portability fixes for lz4 1.10.0 #1465

Open rklrkl opened 1 month ago

rklrkl commented 1 month ago

Describe the bug I had to make several changes to the source code of lz4 1.10.0 to get it to work on a non-Linux system (HP-UX 11.31 to be precise, but the fixes I'm listing should apply to other non-Linux UNIX systems too).

Expected behavior A nice, clean build.

To Reproduce Steps to reproduce the behavior: Attempt to run configure and build on a non-Linux UNIX system (I used HP-UX 11.31).

System (please complete the following information):

Here are the "generic UNIX" fixes that I had to make to lz4 1.10.0 (there were some HP-UX-specific fixes too w.r.t. things like compiler flags, but I won't list those here):

examples/Makefile: Should include ../Makefile.inc like all other sub-Makefile.in files do.

tests/lz4_full.c: This is concatenated from three other C files in the ../lib dir, but this causes duplicate definitions that occur in both ../lib/lz4.c and ../lib/lz4frame.c - see lines 302-320 of ../lib/lz4.c vs. lines 170-183 of ../lib/lz4frame.c. I put a #define BYTE_DEFINED statement in ../lib/lz4.c and then a #ifndef BYTE_DEFINED...#endif around the ../lib/lz4frame.c code.

lib/lz4frame.c, lib/lz4hc.c, programs/bench.c, programs/lorem.c, tests/datagen.c and tests/fuzzer.c: These files define MIN or MAX macros without doing a #undef MIN or #undef MAX beforehand. System header files will often define MIN or MAX, so this can generate a compiler warning.

programs/lz4io.c: Uses "if (LZ4IO_MULTITHREAD)", but LZ4IO_MULTITHREAD is a compile-time constant, so it should use "#if LZ4IO_MULTITHREAD"..."#else"..."#endif" instead (this is done correctly in other source files).

programs/threadpool.c: Has an unreachable assert(0); statement at line 355 - non-gcc compilers will generate a warning for this (they don't pick up the Unreachable comment). Probably should comment this out or surround it with #if 0...#endif if it's to be kept in the source code.

tests/fuzzer.c: sizeof(void) at line 193 is determined at compile time, so any systems where sizeof(void)==8 will report that the rest of the function code is unreachable. I put the rest of the function code from line 199 onwards in an else block.

tests/fullbench.c and tests/fuzzer.c: I pass -DLZ4_DISABLE_DEPRECATE_WARNINGS when compiling, but these two files both have a "#define LZ4_DISABLE_DEPRECATE_WARNINGS" statement that causes a compiler warning. Adding "#undef LZ4_DISABLE_DEPRECATE_WARNINGS" before that statement fixes this.

tests/test-lz4-basic.sh: "diff -q" is GNU diff-only - maybe remove the -q flag?

tests/test-lz4-dict.sh: Line 43 contains the code "(l > 65536 ? l - 65536 : 0)". This is bash-specific and isn't in "/bin/sh" on non-Linux systems. I would advise running the script with "bash test-lz4-dict.sh" to fix this (I wouldn't put "#! /bin/bash" at the start of the script because bash isn't in that location (or shipped at all!) by default on non-Linux systems).

Cyan4973 commented 1 month ago

I wonder if there would be a way to test such cases in CI. It would maintenance much more reliable.

t-mat commented 1 month ago

As for compiler issue, older version of simpler C compiler such as tcc may help us. But I don't check it yet.

vrangesync commented 1 month ago

static binary of lz4(1.10.0) you can download and use on 32 & 64bit unix/linux system. Standalone and no need dynamic loader. It should works on HP-UX which is also an unix system.

https://github.com/lz4/lz4/issues/1480

Cyan4973 commented 1 month ago

static binary can be built using default provided Makefile with the command :

LDFLAGS=-static make -j lz4

This doesn't work on every system though, some refuse or don't provide necessary elements for static linking. linux is most likely fine, but macos default for example will not complete the linking process.