Commit Graph

1877 Commits

Author SHA1 Message Date
Lasse Collin 4083c8e950 liblzma: Add Cflags.private to liblzma.pc.in for MSYS2.
It properly adds -DLZMA_API_STATIC when compiling code that
will be linked against static liblzma. Having it there on
systems other than Windows does no harm.

See: https://www.msys2.org/docs/pkgconfig/
2023-10-31 18:44:59 +08:00
Lasse Collin 661549ecb7 CMake: Create liblzma.def when building liblzma.dll with MinGW-w64. 2023-10-31 18:44:59 +08:00
Lasse Collin 0e546eb4da CMake: Change one CMAKE_CURRENT_SOURCE_DIR to CMAKE_CURRENT_LIST_DIR.
In this case they have identical values.
2023-10-31 18:44:59 +08:00
Lasse Collin da4d04e4d6 CMake/Windows: Fix the import library filename.
Both PREFIX and IMPORT_PERFIX have to be set to "" to get
liblzma.dll and liblzma.dll.a.
2023-10-31 18:44:59 +08:00
Lasse Collin 007558a358 CMake: Don't shadow the cache entry ENABLE_THREADS with a normal variable.
Using set(ENABLE_THREADS "posix") is confusing because it sets
a new normal variable and leaves the cache entry with the same
name unchanged. The intent wasn't to change the cache entry so
this switches to a different variable name.
2023-10-31 18:44:59 +08:00
Lasse Collin 7d01de67ee CMake: Edit threading related messages.
It's mostly to change from "thread method" to "threading method".
2023-10-31 18:44:59 +08:00
Lasse Collin f8edcf3da6 CMake: Use FATAL_ERROR if user-supplied options aren't understood.
This way typos are caught quickly and compounding error messages
are avoided (a single typo could cause more than one error).

This keeps using SEND_ERROR when the system is lacking a feature
(like threading library or sandboxing method). This way the whole
configuration log will be generated in case someone wishes to
report a problem upstream.
2023-10-31 18:44:59 +08:00
Jia Tan 1695021e4a CMake: Add ALLOW_CLMUL_CRC option to enable/disable CLMUL.
The option is enabled by default, but will only be visible to a user
listing cache variables or using a CMake GUI application if the
immintrin.h header file is found.

This mirrors our Autotools build --disable-clmul-crc functionality.
2023-10-31 18:44:59 +08:00
Lasse Collin 5056bc5107 tuklib_integer: Revise unaligned reads and writes on strict-align archs.
In XZ Utils context this doesn't matter much because
unaligned reads and writes aren't used in hot code
when TUKLIB_FAST_UNALIGNED_ACCESS isn't #defined.
2023-10-31 18:44:59 +08:00
Lasse Collin 9e14743ee5 tuklib_integer: Add missing write64be and write64le fallback functions. 2023-10-31 18:44:59 +08:00
Jia Tan 4cc91ceb39 Build: Update visibility.m4 from Gnulib.
Updating from version 6 -> 8 from upstream. Declarations for variables
and function bodies were added to avoid unnecessary failures with
-Werror.
2023-10-31 18:44:59 +08:00
Lasse Collin 1824a6007c Update THANKS. 2023-10-31 18:44:59 +08:00
Jia Tan 8fdc71a27d CMake: Rename xz and man page symlink custom targets.
The Ninja Generator for CMake cannot have a custom target and its
BYPRODUCTS have the same name. This has prevented Ninja builds on
Unix-like systems since the xz symlinks were introduced in
80a1a8bb83.
2023-10-31 18:44:59 +08:00
Lasse Collin 38171492de CMake: Fix Windows build with Clang/LLVM 17.
llvm-windres 17.0.0 has more accurate emulation of GNU windres, so
the hack for GNU windres must now be used with llvm-windres too.

LLVM 16.0.6 has the old behavior and there likely won't be more
16.x releases. So we can simply check for >= 17.0.0.

The workaround must not be used with Clang that is acting in
MSVC mode. This checks for the known environments that need
the workaround instead of using "NOT MSVC".

See also:
2bcc0fdc58
2023-10-31 18:44:59 +08:00
Jia Tan 1bce6fe483 liblzma: Avoid compiler warning without creating extra symbol.
When the generic fast crc64 method is used, then we omit
lzma_crc64_table[][].

The C standards don't allow an empty translation unit which can be
avoided by declaring something, without exporting any symbols.
2023-10-31 18:44:59 +08:00
Lasse Collin dce95a593e Build: Update the comment about -Werror usage in checks. 2023-10-31 18:44:59 +08:00
Lasse Collin f3c32762ae Build: Fix underquoted AC_LANG_SOURCE.
It made no practical difference in this case.
2023-10-31 18:44:59 +08:00
Lasse Collin 7dd57f2f2c Build: Silence Autoconf warning.
There was a use of AC_COMPILE_IFELSE that didn't use
AC_LANG_SOURCE and Autoconf warned about this. The omission
had been intentional but it turned out that this didn't do
what I thought it would.

Autoconf 2.71 manual gives an impression that AC_LANG_SOURCE
inserts all #defines that have been made with AC_DEFINE so
far (confdefs.h). The idea was that omitting AC_LANG_SOURCE
would mean that only the exact code included in the
AC_COMPILE_IFELSE call would be compiled.

With C programs this is not true: the #defines get added without
AC_LANG_SOURCE too. There seems to be no neat way to avoid this.
Thus, with the C language at least, adding AC_LANG_SOURCE makes
no other difference than silencing a warning from Autoconf. The
generated "configure" remains identical. (Docs of AC_LANG_CONFTEST
say that the #defines have been inserted since Autoconf 2.63b and
that AC_COMPILE_IFELSE uses AC_LANG_CONFTEST. So the behavior is
documented if one also reads the docs of macros that one isn't
calling directly.)

Any extra code, including #defines, can cause problems for
these two tests because these tests must use -Werror.
CC=clang CFLAGS=-Weverything is the most extreme example.
It enables -Wreserved-macro-identifier which warns about
It's possible to write a test file that passes -Weverything but
it becomes impossible when Autoconf inserts confdefs.h.

So this commit adds AC_LANG_SOURCE to silence Autoconf warnings.
A different solution is needed for -Werror tests.
2023-10-31 18:44:59 +08:00
Jia Tan edec253e41 Build: Remove Gnulib dependency from tests.
The tests do not use any Gnulib replacements so they do not need to link
libgnu.a or have /lib in the include path.
2023-10-31 18:44:59 +08:00
Jia Tan 46cb133ce7 CMake: Remove /lib from tests include path.
The tests never included anything from /lib, so this was not needed.
2023-10-31 18:44:59 +08:00
Lasse Collin 4ae13cfe0d sysdefs.h: Update the comment about __USE_MINGW_ANSI_STDIO. 2023-10-31 18:44:59 +08:00
Lasse Collin 660c8c29e5 xz: Windows: Don't (de)compress to special files like "con" or "nul".
Before this commit, the following writes "foo" to the
console and deletes the input file:

    echo foo | xz > con_xz
    xz --suffix=_xz --decompress con_xz

It cannot happen without --suffix because names like con.xz
are also special and so attempting to decompress con.xz
(or compress con to con.xz) will already fail when opening
the input file.

Similar thing is possible when compressing. The following
writes to "nul" and the input file "n" is deleted.

    echo foo | xz > n
    xz --suffix=ul n

Now xz checks if the destination is a special file before
continuing. DOS/DJGPP version had a check for this but
Windows (and OS/2) didn't.
2023-10-31 18:44:59 +08:00
Lasse Collin b7ce6e8078 CMake: Wrap two overlong lines that are possible to wrap. 2023-10-31 18:44:59 +08:00
Lasse Collin 1595f454d5 CMake: Add a comment about threads on Cygwin. 2023-10-31 18:44:59 +08:00
Lasse Collin 5be6275f19 CMake: Bump maximum policy version to 3.27.
There are several new policies. CMP0149 may affect the Windows SDK
version that CMake will choose by default. The new behavior is more
predictable, always choosing the latest SDK version by default.

The other new policies shouldn't affect this package.
2023-10-31 18:44:58 +08:00
Lasse Collin e515643d75 Doxygen: Add more C macro names to PREDEFINED. 2023-10-31 01:03:25 +08:00
Lasse Collin e3478ae4f3 liblzma: Move a few __attribute__ uses in function declarations.
The API headers have many attributes but these were left
as is for now.
2023-10-31 01:03:25 +08:00
Lasse Collin b71b8922ef xz, xzdec, lzmainfo: Use tuklib_attr_noreturn.
For compatibility with C23's [[noreturn]], tuklib_attr_noreturn
must be at the beginning of declaration (before "extern" or
"static", and even before any GNU C's __attribute__).

This commit also moves all other function attributes to
the beginning of function declarations. "extern" is kept
at the beginning of a line so the attributes are listed on
separate lines before "extern" or "static".
2023-10-31 01:03:25 +08:00
Lasse Collin 359e5c6cb1 Remove incorrect uses of __attribute__((__malloc__)).
xrealloc() is obviously incorrect, modern GCC docs even
mention realloc() as an example where this attribute
cannot be used.

liblzma's lzma_alloc() and lzma_alloc_zero() would be
correct uses most of the time but custom allocators
may use a memory pool or otherwise hold the pointer
so aliasing issues could happen in theory.

The xstrdup() case likely was correct but I removed it anyway.
Now there are no __malloc__ attributes left in the code.
The allocations aren't in hot paths so this should make
no practical difference.
2023-10-31 01:03:25 +08:00
Lasse Collin 589b4cba22 Update THANKS. 2023-10-31 01:03:25 +08:00
Lasse Collin 43728ed226 Update THANKS. 2023-10-31 01:03:25 +08:00
Lasse Collin caf00e0988 liblzma: Mark crc64_clmul() with __attribute__((__no_sanitize_address__)).
Thanks to Agostino Sarubbo.
Fixes: https://github.com/tukaani-project/xz/issues/62
2023-10-31 01:03:25 +08:00
Jia Tan a70e96d2da CMake: Fix time.h checks not running on second CMake run.
If CMake was configured more than once, HAVE_CLOCK_GETTIME and
HAVE_CLOCK_MONOTONIC would not be set as compile definitions. The check
for librt being needed to provide HAVE_CLOCK_GETTIME was also
simplified.
2023-10-31 01:03:25 +08:00
Jia Tan d5275d83bd CMake: Fix unconditionally defining HAVE_CLOCK_MONOTONIC.
If HAVE_CLOCK_GETTIME was defined, then HAVE_CLOCK_MONOTONIC was always
added as a compile definition even if the check for it failed.
2023-10-31 01:03:25 +08:00
Lasse Collin 1f6e7c68fb xz: Refactor thousand separator detection and disable it on MSVC.
Now the two variations of the format strings are created with
a macro, and the whole detection code can be easily disabled
on platforms where thousand separator formatting is known to
not work (MSVC has no support, and on DJGPP 2.05 it can have
problems in some cases).
2023-10-31 01:03:25 +08:00
Lasse Collin ef71f83973 xz: Fix a too relaxed assertion and remove uses of SSIZE_MAX.
SSIZE_MAX isn't readily available on MSVC. Removing it means
that there is one thing less to worry when porting to MSVC.
2023-10-31 01:03:25 +08:00
Jia Tan cf8ba7c3a8 Tests: Improve invalid unpadded size check in test_lzma_index_append().
This check was extended to test the code added to fix a failing assert
in 68bda971bb.
2023-10-31 01:02:59 +08:00
Jia Tan 4a4180ce74 Tests: Improve comments in test_index.c. 2023-10-26 06:22:24 +08:00
Jia Tan 4b23b84b89 Update THANKS. 2023-10-26 06:22:24 +08:00
Jia Tan 773f1e8622 liblzma: Update assert in vli_ceil4().
The argument to vli_ceil4() should always guarantee the return value
is also a valid lzma_vli. Thus the highest three valid lzma_vli values
are invalid arguments. All uses of the function ensure this so the
assert is updated to match this.
2023-10-26 06:22:24 +08:00
Jia Tan 68bda971bb liblzma: Add overflow check for Unpadded size in lzma_index_append().
This was not a security bug since there was no path to overflow
UINT64_MAX in lzma_index_append() or when it calls index_file_size().
The bug was discovered by a failing assert() in vli_ceil4() when called
from index_file_size() when unpadded_sum (the sum of the compressed size
of current Stream and the unpadded_size parameter) exceeds LZMA_VLI_MAX.

Previously, the unpadded_size parameter was checked to be not greater
than UNPADDED_SIZE_MAX, but no check was done once compressed_base was
added.

This could not have caused an integer overflow in index_file_size() when
called by lzma_index_append(). The calculation for file_size breaks down
into the sum of:

- Compressed base from all previous Streams
- 2 * LZMA_STREAM_HEADER_SIZE (size of the current Streams header and
  footer)
- stream_padding (can be set by lzma_index_stream_padding())
- Compressed base from the current Stream
- Unpadded size (parameter to lzma_index_append())

The sum of everything except for Unpadded size must be less than
LZMA_VLI_MAX. This is guarenteed by overflow checks in the functions
that can set these values including lzma_index_stream_padding(),
lzma_index_append(), and lzma_index_cat(). The maximum value for
Unpadded size is enforced by lzma_index_append() to be less than or
equal UNPADDED_SIZE_MAX. Thus, the sum cannot exceed UINT64_MAX since
LZMA_VLI_MAX is half of UINT64_MAX.

Thanks to Joona Kannisto for reporting this.
2023-10-26 06:22:24 +08:00
Jia Tan b41bb79c60 Translations: Update the Esperanto translation. 2023-10-26 06:22:24 +08:00
Jia Tan 6614e6d4bf Docs: Update INSTALL for --enable-threads method win95.
The Autotools build allows win95 threads and --enable-small together now
if the compiler supports __attribute__((__constructor__)).
2023-10-26 06:22:24 +08:00
Jia Tan bfb623ad96 CMake: Conditionally allow win95 threads and --enable-small. 2023-10-26 06:22:24 +08:00
Jia Tan e919ebb29a Build: Conditionally allow win95 threads and --enable-small.
When the compiler supports __attribute__((__constructor__))
mythread_once() is never used, even with --enable-small. A configuration
with win95 threads and --enable-small will compile and be thread safe so
it can be allowed.

This isn't a very common configuration since MSVC does not support
__attribute__((__constructor__)), but MINGW32 and CLANG32 environments
for MSYS2 can use win95 threads and have
__attribute__((__constructor__)) support.
2023-10-26 06:22:24 +08:00
Jamaika1 c0c0cd4a48 mythread.h: Fix typo error in Vista threads mythread_once().
The "once_" variable was accidentally referred to as just "once". This
prevented building with Vista threads when
HAVE_FUNC_ATTRIBUTE_CONSTRUCTOR was not defined.
2023-10-26 06:22:24 +08:00
Jia Tan d93fbefcc4 Tests: Style fixes to test_lzip_decoder.c. 2023-10-26 06:22:24 +08:00
Jia Tan 65981d8e45 Translations: Update the Chinese (simplified) translation. 2023-10-26 06:22:22 +08:00
Lasse Collin a108ed5891 xz: Omit an empty paragraph on the man page. 2023-08-02 17:39:50 +03:00
Jia Tan 03c51c5c08 Bump version and soname for 5.4.4. 2023-08-02 20:32:20 +08:00