]> git.ipfire.org Git - thirdparty/xz.git/log
thirdparty/xz.git
21 months agoCMake: Generate and install liblzma.pc if not using MSVC.
Lasse Collin [Fri, 29 Sep 2023 23:14:25 +0000 (02:14 +0300)] 
CMake: Generate and install liblzma.pc if not using MSVC.

Autotools based build uses -pthread and thus adds it to Libs.private
in liblzma.pc. CMake doesn't use -pthread at all if pthread functions
are available in libc so Libs.private doesn't get -pthread either.

21 months agoCMake: Rearrange the PACKAGE_ variables.
Lasse Collin [Fri, 29 Sep 2023 22:13:13 +0000 (01:13 +0300)] 
CMake: Rearrange the PACKAGE_ variables.

The windres workaround now replaces spaces with \x20 so
the package name isn't repeated.

These changes will help with creation of liblzma.pc.

21 months agoliblzma: Add Cflags.private to liblzma.pc.in for MSYS2.
Lasse Collin [Fri, 29 Sep 2023 17:46:11 +0000 (20:46 +0300)] 
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/

21 months agoCMake: Create liblzma.def when building liblzma.dll with MinGW-w64.
Lasse Collin [Wed, 27 Sep 2023 19:46:20 +0000 (22:46 +0300)] 
CMake: Create liblzma.def when building liblzma.dll with MinGW-w64.

21 months agoCMake: Change one CMAKE_CURRENT_SOURCE_DIR to CMAKE_CURRENT_LIST_DIR.
Lasse Collin [Thu, 26 Oct 2023 18:44:42 +0000 (21:44 +0300)] 
CMake: Change one CMAKE_CURRENT_SOURCE_DIR to CMAKE_CURRENT_LIST_DIR.

In this case they have identical values.

21 months agoCMake/Windows: Fix the import library filename.
Lasse Collin [Sun, 1 Oct 2023 16:10:57 +0000 (19:10 +0300)] 
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.

21 months agoBuild: Detect -fsanitize= in CFLAGS and incompatible build options.
Lasse Collin [Wed, 25 Oct 2023 16:13:25 +0000 (19:13 +0300)] 
Build: Detect -fsanitize= in CFLAGS and incompatible build options.

Now configure will fail if -fsanitize= is found in CFLAGS
and sanitizer-incompatible ifunc or Landlock sandboxing
would be used. These are incompatible with one or more sanitizers.
It's simpler to reject all -fsanitize= uses instead of trying to
pass those that might not cause problems.

CMake-based build was updated similarly. It lets the configuration
finish (SEND_ERROR instead of FATAL_ERROR) so that both error
messages can be seen at once.

21 months agoCI: Disable sandboxing in fsanitize=address,undefined job.
Jia Tan [Mon, 23 Oct 2023 16:50:08 +0000 (00:50 +0800)] 
CI: Disable sandboxing in fsanitize=address,undefined job.

The sandboxing on Linux now supports Landlock, which restricts all
supported filesystem actions after xz opens the files it needs. The
sandbox is only enabled when one file is input and we are writing to
standard out. With fsanitize=address,undefined, the instrumentation
needs to read additional files after the sandbox is in place. This
forces all xz based test to fail, so the sandbox must instead be
disabled.

21 months agoCI: Allow disabling the sandbox in ci_build.sh.
Jia Tan [Mon, 23 Oct 2023 16:15:39 +0000 (00:15 +0800)] 
CI: Allow disabling the sandbox in ci_build.sh.

21 months agoCMake: Don't shadow the cache entry ENABLE_THREADS with a normal variable.
Lasse Collin [Wed, 11 Oct 2023 16:47:44 +0000 (19:47 +0300)] 
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.

21 months agoDocs: Update INSTALL about sandboxing support.
Lasse Collin [Mon, 9 Oct 2023 19:28:49 +0000 (22:28 +0300)] 
Docs: Update INSTALL about sandboxing support.

21 months agoxz: Support basic sandboxing with Linux Landlock (ABI versions 1-3).
Lasse Collin [Mon, 9 Oct 2023 19:07:52 +0000 (22:07 +0300)] 
xz: Support basic sandboxing with Linux Landlock (ABI versions 1-3).

It is enabled only when decompressing one file to stdout,
similar to how Capsicum is used.

Landlock was added in Linux 5.13.

21 months agoCMake: Edit threading related messages.
Lasse Collin [Mon, 9 Oct 2023 18:12:31 +0000 (21:12 +0300)] 
CMake: Edit threading related messages.

It's mostly to change from "thread method" to "threading method".

21 months agoCMake: Use FATAL_ERROR if user-supplied options aren't understood.
Lasse Collin [Mon, 9 Oct 2023 17:59:24 +0000 (20:59 +0300)] 
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.

21 months agoCMake: Add sandboxing support.
Lasse Collin [Mon, 9 Oct 2023 15:37:32 +0000 (18:37 +0300)] 
CMake: Add sandboxing support.

21 months agoSimplify detection of Capsicum support.
Lasse Collin [Mon, 9 Oct 2023 15:13:08 +0000 (18:13 +0300)] 
Simplify detection of Capsicum support.

This removes support for FreeBSD 10.0 and 10.1 which used
<sys/capability.h> instead of <sys/capsicum.h>. Support for
FreeBSD 10.1 ended on 2016-12-31. So now FreeBSD >= 10.2 is
required to enable Capsicum support.

This also removes support for Capsicum on Linux (libcaprights)
which seems to have been unmaintained since 2017 and Linux 4.11:
https://github.com/google/capsicum-linux

21 months agoxz/Windows: Allow clock_gettime with POSIX threads.
Lasse Collin [Sun, 24 Sep 2023 22:46:36 +0000 (01:46 +0300)] 
xz/Windows: Allow clock_gettime with POSIX threads.

If winpthreads are used for threading, it's OK to use clock_gettime()
from winpthreads too.

21 months agomythread.h: Make MYTHREAD_POSIX compatible with MinGW-w64's winpthreads.
Lasse Collin [Sun, 24 Sep 2023 22:39:26 +0000 (01:39 +0300)] 
mythread.h: Make MYTHREAD_POSIX compatible with MinGW-w64's winpthreads.

This might be almost useless but it doesn't need much extra code either.

21 months agoCMake: Check for clock_gettime() even on Windows.
Lasse Collin [Sat, 23 Sep 2023 00:06:36 +0000 (03:06 +0300)] 
CMake: Check for clock_gettime() even on Windows.

This mirrors configure.ac although currently MinGW-w64 builds
don't use clock_gettime() even if it is found.

21 months agoBuild: Check for clock_gettime() even if not using POSIX threads.
Lasse Collin [Sat, 23 Sep 2023 00:23:32 +0000 (03:23 +0300)] 
Build: Check for clock_gettime() even if not using POSIX threads.

See the new comment in the code.

This also makes the check for clock_gettime() run with MinGW-w64
with which we don't want to use clock_gettime(). The previous
commit already took care of this situation.

21 months agoxz/Windows: Ensure that clock_gettime() isn't used with MinGW-w64.
Lasse Collin [Sun, 24 Sep 2023 19:58:53 +0000 (22:58 +0300)] 
xz/Windows: Ensure that clock_gettime() isn't used with MinGW-w64.

This commit alone doesn't change anything in the real-world:

  - configure.ac currently checks for clock_gettime() only
    when using pthreads.

  - CMakeLists.txt doesn't check for clock_gettime() on Windows.

So clock_gettime() wasn't used with MinGW-w64 before either.

clock_gettime() provides monotonic time and it's better than
gettimeofday() in this sense. But clock_gettime() is defined
in winpthreads, and liblzma or xz needs nothing else from
winpthreads. By avoiding clock_gettime(), we avoid the dependency on
libwinpthread-1.dll or the need to link against the static version.

As a bonus, GetTickCount64() and MinGW-w64's gettimeofday() can be
faster than clock_gettime(CLOCK_MONOTONIC, &tv). The resolution
is more than good enough for the progress indicator in xz.

21 months agoxz/Windows: Use GetTickCount64() with MinGW-w64 if using Vista threads.
Lasse Collin [Sat, 23 Sep 2023 21:21:22 +0000 (00:21 +0300)] 
xz/Windows: Use GetTickCount64() with MinGW-w64 if using Vista threads.

21 months agoliblzma: Move is_clmul_supported() back to crc_common.h.
Jia Tan [Fri, 20 Oct 2023 11:17:46 +0000 (19:17 +0800)] 
liblzma: Move is_clmul_supported() back to crc_common.h.

This partially reverts creating crc_clmul.c
(8c0f9376f58c0696d5d6719705164d35542dd891) where is_clmul_supported()
was moved, extern'ed, and renamed to lzma_is_clmul_supported(). This
caused a problem when the function call to lzma_is_clmul_supported()
results in a call through the PLT. ifunc resolvers run very early in
the dynamic loading sequence, so the PLT may not be setup properly at
this point. Whether the PLT is used or not for
lzma_is_clmul_supported() depened upon the compiler-toolchain used and
flags.

In liblzma compiled with GCC, for instance, GCC will go through the PLT
for function calls internal to liblzma if the version scripts and
symbol visibility hiding are not used. If lazy-binding is disabled,
then it would have made any program linked with liblzma fail during
dynamic loading in the ifunc resolver.

21 months agoBuild: Remove check for COND_CHECK_CRC32 in check/Makefile.inc.
Jia Tan [Thu, 19 Oct 2023 08:23:32 +0000 (16:23 +0800)] 
Build: Remove check for COND_CHECK_CRC32 in check/Makefile.inc.

Currently crc32 is always enabled, so COND_CHECK_CRC32 must always be
set. Because of this, it makes the recent change to conditionally
compile check/crc_clmul.c appear wrong since that file has CLMUL
implementations for both CRC32 and CRC64.

21 months agoCMake: Add ALLOW_CLMUL_CRC option to enable/disable CLMUL.
Jia Tan [Thu, 19 Oct 2023 08:09:01 +0000 (16:09 +0800)] 
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.

21 months agoliblzma: Fix -fsanitize=address failure with crc_clmul functions.
Jia Tan [Wed, 18 Oct 2023 16:22:50 +0000 (00:22 +0800)] 
liblzma: Fix -fsanitize=address failure with crc_clmul functions.

After forcing crc_simd_body() to always be inlined it caused
-fsanitize=address to fail for lzma_crc32_clmul() and
lzma_crc64_clmul(). The __no_sanitize_address__ attribute was added
to lzma_crc32_clmul() and lzma_crc64_clmul(), but not removed from
crc_simd_body(). ASAN and inline functions behavior has changed over
the years for GCC specifically, so while strictly required we will
keep __attribute__((__no_sanitize_address__)) on crc_simd_body() in
case this becomes a requirement in the future.

Older GCC versions refuse to inline a function with ASAN if the
caller and callee do not agree on sanitization flags
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89124#c3). If the
function was forced to be inlined, it will not compile if the callee
function has __no_sanitize_address__ but the caller doesn't.

21 months agotuklib_integer: Update the CMake test for fast unaligned access.
Lasse Collin [Sat, 14 Oct 2023 17:16:13 +0000 (20:16 +0300)] 
tuklib_integer: Update the CMake test for fast unaligned access.

21 months agoBuild: Enabled unaligned access by default on PowerPC64LE and some RISC-V.
Lasse Collin [Sat, 23 Sep 2023 20:28:48 +0000 (23:28 +0300)] 
Build: Enabled unaligned access by default on PowerPC64LE and some RISC-V.

PowerPC64LE wasn't tested but it seems like a safe change.
POWER8 supports unaligned access in little endian mode. Testing
on godbolt.org shows that GCC uses unaligned access by default.

The RISC-V macro __riscv_misaligned_fast is very new and not
in any stable compiler release yet.

Documentation in INSTALL was updated to match.

Documentation about an autodetection bug when using ARM64 GCC
with -mstrict-align was added to INSTALL.

CMake files weren't updated yet.

21 months agotuklib_integer: Revise unaligned reads and writes on strict-align archs.
Lasse Collin [Sat, 14 Oct 2023 14:56:59 +0000 (17:56 +0300)] 
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.

21 months agotuklib_integer: Add missing write64be and write64le fallback functions.
Lasse Collin [Fri, 22 Sep 2023 23:21:49 +0000 (02:21 +0300)] 
tuklib_integer: Add missing write64be and write64le fallback functions.

21 months agoliblzma: Set the MSVC optimization fix to only cover lzma_crc64_clmul().
Jia Tan [Wed, 18 Oct 2023 11:57:10 +0000 (19:57 +0800)] 
liblzma: Set the MSVC optimization fix to only cover lzma_crc64_clmul().

After testing a 32-bit Release build on MSVC, only lzma_crc64_clmul()
has the bug. crc_simd_body() and lzma_crc32_clmul() do not need the
optimizations disabled.

21 months agoliblzma: CRC_USE_GENERIC_FOR_SMALL_INPUTS cannot be used with ifunc.
Lasse Collin [Wed, 18 Oct 2023 11:30:00 +0000 (14:30 +0300)] 
liblzma: CRC_USE_GENERIC_FOR_SMALL_INPUTS cannot be used with ifunc.

21 months agoliblzma: Include common.h in crc_common.h.
Lasse Collin [Tue, 17 Oct 2023 18:53:11 +0000 (21:53 +0300)] 
liblzma: Include common.h in crc_common.h.

crc_common.h depends on common.h. The headers include common.h except
when there is a reason to not do so.

21 months agoliblzma: Add include guards to crc_common.h.
Jia Tan [Tue, 17 Oct 2023 17:23:26 +0000 (01:23 +0800)] 
liblzma: Add include guards to crc_common.h.

21 months agoliblzma: Add the crc_always_inline macro to crc_simd_body().
Jia Tan [Wed, 18 Oct 2023 14:50:25 +0000 (22:50 +0800)] 
liblzma: Add the crc_always_inline macro to crc_simd_body().

Forcing this to be inline has a significant speed improvement at the
cost of a few repeated instructions. The compilers tested on did not
inline this function since it is large and is used twice in the same
translation unit.

21 months agoliblzma: Create crc_always_inline macro.
Jia Tan [Wed, 18 Oct 2023 14:48:19 +0000 (22:48 +0800)] 
liblzma: Create crc_always_inline macro.

This macro must be used instead of the inline keyword. On MSVC, it is
a replacement for __forceinline which is an MSVC specific keyword that
should not be used with inline (it will issue a warning if it is).

It does not use a build system check to determine if
__attribute__((__always_inline__)) since all compilers that can use
CLMUL extensions (except the special case for MSVC) should support this
attribute. If this assumption is incorrect then it will result in a bug
report instead of silently producing slow code.

21 months agoliblzma: Refactor CRC comments.
Jia Tan [Sat, 14 Oct 2023 05:23:23 +0000 (13:23 +0800)] 
liblzma: Refactor CRC comments.

A detailed description of the three dispatch methods was added. Also,
duplicated comments now only appear in crc32_fast.c or were removed from
both crc32_fast.c and crc64_fast.c if they appeared in crc_clmul.c.

21 months agoliblzma: Create crc_clmul.c.
Jia Tan [Sat, 14 Oct 2023 04:17:57 +0000 (12:17 +0800)] 
liblzma: Create crc_clmul.c.

Both crc32_clmul() and crc64_clmul() are now exported from
crc32_clmul.c as lzma_crc32_clmul() and lzma_crc64_clmul(). This
ensures that is_clmul_supported() (now lzma_is_clmul_supported()) is
not duplicated between crc32_fast.c and crc64_fast.c.

Also, it encapsulates the complexity of the CLMUL implementations into a
single file and reduces the complexity of crc32_fast.c and crc64_fast.c.
Before, CLMUL code was present in crc32_fast.c, crc64_fast.c, and
crc_common.h.

During the conversion, various cleanups were applied to code (thanks to
Lasse Collin) including:

- Require using semicolons with MASK_/L/H/LH macros.
- Variable typing and const handling improvements.
- Improvements to comments.
- Fixes to the pragmas used.
- Removed unneeded variables.
- Whitespace improvements.
- Fixed CRC_USE_GENERIC_FOR_SMALL_INPUTS handling.
- Silenced warnings and removed the need for some #pragmas

21 months agoliblzma: Define CRC_USE_IFUNC in crc_common.h.
Jia Tan [Sat, 14 Oct 2023 02:23:03 +0000 (10:23 +0800)] 
liblzma: Define CRC_USE_IFUNC in crc_common.h.

When ifunc is supported, we can define a simpler macro instead of
repeating the more complex check in both crc32_fast.c and crc64_fast.c.

21 months agoliblzma: Added crc32_clmul to crc32_fast.c.
Hans Jansen [Thu, 12 Oct 2023 17:37:01 +0000 (19:37 +0200)] 
liblzma: Added crc32_clmul to crc32_fast.c.

21 months agoliblzma: Moved CLMUL CRC logic to crc_common.h.
Hans Jansen [Thu, 12 Oct 2023 17:23:40 +0000 (19:23 +0200)] 
liblzma: Moved CLMUL CRC logic to crc_common.h.

crc64_fast.c was updated to use the code from crc_common.h instead.

21 months agoliblzma: Rename crc_macros.h to crc_common.h.
Hans Jansen [Thu, 12 Oct 2023 17:07:50 +0000 (19:07 +0200)] 
liblzma: Rename crc_macros.h to crc_common.h.

21 months agoCI: Bump and ref actions by commit SHA in windows-ci.yml
Gabriela Gutierrez [Tue, 26 Sep 2023 15:55:13 +0000 (15:55 +0000)] 
CI: Bump and ref actions by commit SHA in windows-ci.yml

Referencing actions by commit SHA in GitHub workflows guarantees you are using an immutable version. Actions referenced by tags and branches are more vulnerable to attacks, such as the tag being moved to a malicious commit or a malicious commit being pushed to the branch.

It's important to make sure the SHA's are from the original repositories and not forks.

For reference:

https://github.com/msys2/setup-msys2/releases/tag/v2.20.1
https://github.com/msys2/setup-msys2/commit/27b3aa77f672cb6b3054121cfd80c3d22ceebb1d

https://github.com/actions/checkout/releases/tag/v4.1.0
https://github.com/actions/checkout/commit/8ade135a41bc03ea155e62e844d188df1ea18608

https://github.com/actions/upload-artifact/releases/tag/v3.1.3
https://github.com/actions/upload-artifact/commit/a8a3f3ad30e3422c9c7b888a15615d19a852ae32

Signed-off-by: Gabriela Gutierrez <gabigutierrez@google.com>
21 months agoCI: Bump and ref actions by commit SHA in ci.yml
Gabriela Gutierrez [Tue, 26 Sep 2023 14:35:08 +0000 (14:35 +0000)] 
CI: Bump and ref actions by commit SHA in ci.yml

Referencing actions by commit SHA in GitHub workflows guarantees you are using an immutable version. Actions referenced by tags and branches are more vulnerable to attacks, such as the tag being moved to a malicious commit or a malicious commit being pushed to the branch.

It's important to make sure the SHA's are from the original repositories and not forks.

For reference:

https://github.com/actions/checkout/releases/tag/v4.1.0
https://github.com/actions/checkout/commit/8ade135a41bc03ea155e62e844d188df1ea18608

https://github.com/actions/upload-artifact/releases/tag/v3.1.3
https://github.com/actions/upload-artifact/commit/a8a3f3ad30e3422c9c7b888a15615d19a852ae32

Signed-off-by: Gabriela Gutierrez <gabigutierrez@google.com>
21 months agoBuild: Update visibility.m4 from Gnulib.
Jia Tan [Thu, 12 Oct 2023 12:12:18 +0000 (20:12 +0800)] 
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.

22 months agoUpdate THANKS.
Lasse Collin [Fri, 6 Oct 2023 16:36:35 +0000 (19:36 +0300)] 
Update THANKS.

22 months agoCMake/Windows: Fix when the windres workaround is applied.
Lasse Collin [Fri, 6 Oct 2023 15:55:57 +0000 (18:55 +0300)] 
CMake/Windows: Fix when the windres workaround is applied.

CMake doesn't set WIN32 on CYGWIN but the workaround is
probably needed on Cygwin too. Same for MSYS and MSYS2.

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

Thanks to Martin Storsjö.
https://github.com/tukaani-project/xz/commit/0570308ddd9c0e39e85597ebc0e31d4fc81d436f#commitcomment-129098431

22 months agoCI: Disable CLANG64 MSYS2 environment until bug is resolved.
Jia Tan [Fri, 29 Sep 2023 14:11:54 +0000 (22:11 +0800)] 
CI: Disable CLANG64 MSYS2 environment until bug is resolved.

lld 17.0.1 searches for libraries to link first in the toolchain
directories before the local directory when building. The is a problem
for us because liblzma.a is installed in MSYS2 CLANG64 by default and
xz.exe will thus use the installed library instead of the one being
built.

This causes tests to fail when they are expecting features to be
disabled. More importantly, it will compile xz.exe with an incorrect
liblzma and could cause unexpected behavior by being unable to update
liblzma code in static builds. The CLANG64 environment can be tested
again once this is fixed.

Link to bug: https://github.com/llvm/llvm-project/issues/67779.

22 months agoCMake: Rename xz and man page symlink custom targets.
Jia Tan [Fri, 29 Sep 2023 12:14:39 +0000 (20:14 +0800)] 
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
80a1a8bb838842a2be343bd88ad1462c21c5e2c9.

22 months agoCMake: Specify LINKER_LANGUAGE for libgnu target to fix Ninja Generator.
Jia Tan [Fri, 29 Sep 2023 11:58:44 +0000 (19:58 +0800)] 
CMake: Specify LINKER_LANGUAGE for libgnu target to fix Ninja Generator.

CMake is unable to guess the linker language for just a header file so
it must be explicitly set.

22 months agoCMake: Fix Windows build with Clang/LLVM 17.
Lasse Collin [Wed, 27 Sep 2023 16:54:35 +0000 (19:54 +0300)] 
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.

See also:
https://github.com/llvm/llvm-project/commit/2bcc0fdc58a220cb9921b47ec8a32c85f2511a47

22 months agoliblzma: Update a comment.
Lasse Collin [Tue, 26 Sep 2023 18:47:13 +0000 (21:47 +0300)] 
liblzma: Update a comment.

The C standards don't allow an empty translation unit which can be
avoided by declaring something, without exporting any symbols.

When I committed f644473a211394447824ea00518d0a214ff3f7f2 I had
a feeling that some specific toolchain somewhere didn't like
empty object files (assembler or maybe "ar" complained) but
I cannot find anything to confirm this now. Quite likely I
remembered nonsense. I leave this here as a note to my future self. :-)

22 months agoliblzma: Avoid compiler warning without creating extra symbol.
Jia Tan [Tue, 26 Sep 2023 16:02:11 +0000 (00:02 +0800)] 
liblzma: Avoid compiler warning without creating extra symbol.

When the generic fast crc64 method is used, then we omit
lzma_crc64_table[][]. Similar to
d9166b52cf3458a4da3eb92224837ca8fc208d79, we can avoid compiler warnings
with -Wempty-translation-unit (Clang) or -pedantic (GCC) by creating a
never used typedef instead of an extra symbol.

22 months agoBuild: Update the comment about -Werror usage in checks.
Lasse Collin [Tue, 26 Sep 2023 14:24:15 +0000 (17:24 +0300)] 
Build: Update the comment about -Werror usage in checks.

22 months agoBuild: Fix __attribute__((ifunc(...))) detection with clang -Wall.
Lasse Collin [Tue, 26 Sep 2023 12:00:43 +0000 (15:00 +0300)] 
Build: Fix __attribute__((ifunc(...))) detection with clang -Wall.

Now if user-supplied CFLAGS contains -Wall -Wextra -Wpedantic
the two checks that need -Werror will still work.

At CMake side there is add_compile_options(-Wall -Wextra)
but it didn't affect the -Werror tests. So with both Autotools
and CMake only user-supplied CFLAGS could make the checks fail
when they shouldn't.

This is not a full fix as things like -Wunused-macros in
user-supplied CFLAGS will still cause problems with both
GCC and Clang.

22 months agoBuild: Fix underquoted AC_LANG_SOURCE.
Lasse Collin [Tue, 26 Sep 2023 10:51:31 +0000 (13:51 +0300)] 
Build: Fix underquoted AC_LANG_SOURCE.

It made no practical difference in this case.

22 months agoBuild: Silence two Autoconf warnings.
Lasse Collin [Tue, 26 Sep 2023 10:14:37 +0000 (13:14 +0300)] 
Build: Silence two Autoconf warnings.

There were two uses of AC_COMPILE_IFELSE that didn't use
AC_LANG_SOURCE and Autoconf warned about these. 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
#define __EXTENSIONS__ 1 because it begins with two underscores.
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.

22 months agoCMake: Remove accidental extra newline.
Jia Tan [Mon, 25 Sep 2023 17:17:11 +0000 (01:17 +0800)] 
CMake: Remove accidental extra newline.

22 months agoBuild: Remove Gnulib dependency from tests.
Jia Tan [Mon, 25 Sep 2023 16:47:26 +0000 (00:47 +0800)] 
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.

22 months agoCMake: Remove /lib from tests include path.
Jia Tan [Mon, 25 Sep 2023 16:43:43 +0000 (00:43 +0800)] 
CMake: Remove /lib from tests include path.

The tests never included anything from /lib, so this was not needed.

22 months agoScripts: Change quoting style from `...' to '...'.
Jia Tan [Sun, 24 Sep 2023 14:10:41 +0000 (22:10 +0800)] 
Scripts: Change quoting style from `...' to '...'.

22 months agoxz: Change quoting style from `...' to '...'.
Jia Tan [Sun, 24 Sep 2023 14:10:18 +0000 (22:10 +0800)] 
xz: Change quoting style from `...' to '...'.

22 months agoliblzma: Change quoting style from `...' to '...'.
Jia Tan [Sun, 24 Sep 2023 14:09:47 +0000 (22:09 +0800)] 
liblzma: Change quoting style from `...' to '...'.

This was done for both internal and API headers.

22 months agoBuild: Change quoting style from `...' to '...'.
Jia Tan [Sun, 24 Sep 2023 14:09:16 +0000 (22:09 +0800)] 
Build: Change quoting style from `...' to '...'.

22 months agoDocs: Change quoting style from `...' to '...'.
Jia Tan [Sun, 24 Sep 2023 14:05:02 +0000 (22:05 +0800)] 
Docs: Change quoting style from `...' to '...'.

These days the ` and ' do not look symmetric. This quoting style has
been changed in various apps over the years including the GNU tools.

22 months agolib: Silence -Wsign-conversion in getopt.c.
Jia Tan [Sun, 24 Sep 2023 13:25:01 +0000 (21:25 +0800)] 
lib: Silence -Wsign-conversion in getopt.c.

22 months agoBuild: Update getopt.m4 from Gnulib.
Jia Tan [Sun, 24 Sep 2023 12:48:52 +0000 (20:48 +0800)] 
Build: Update getopt.m4 from Gnulib.

This file was modified from upstream since we do not need to replace
getopt() and can avoid complexity and feature tests.

22 months agoCMake: Add /lib to include path.
Jia Tan [Mon, 25 Sep 2023 16:09:53 +0000 (00:09 +0800)] 
CMake: Add /lib to include path.

22 months agoCMake: Update libgnu target with new header files.
Jia Tan [Sun, 24 Sep 2023 12:36:34 +0000 (20:36 +0800)] 
CMake: Update libgnu target with new header files.

22 months agolib: Update Makefile.am for new header files.
Jia Tan [Fri, 22 Sep 2023 16:47:52 +0000 (00:47 +0800)] 
lib: Update Makefile.am for new header files.

22 months agolib: Update getopt1.c from Gnulib.
Jia Tan [Sun, 24 Sep 2023 12:34:03 +0000 (20:34 +0800)] 
lib: Update getopt1.c from Gnulib.

The only difference was maintaining the conditional inclusion for
config.h.

22 months agolib: Update getopt.in.h from Gnulib with modifications.
Jia Tan [Fri, 22 Sep 2023 19:27:00 +0000 (03:27 +0800)] 
lib: Update getopt.in.h from Gnulib with modifications.

We can still avoid modifying the contents of this file during
configuration to simplify the build systems. Gnulib added replacements
for inclusions guards for Cygwin. Cygwin should not need getopt_long
replacement so this feature can be omitted.

<unistd.h> is conditionally included to avoid MSVC since it is not
available.

The definition for _GL_ARG_NONNULL was also copied into this file from
Gnulib since this stage is usually done during gnulib-tool.

22 months agolib: Update getopt_int.h from Gnulib.
Jia Tan [Fri, 22 Sep 2023 16:31:55 +0000 (00:31 +0800)] 
lib: Update getopt_int.h from Gnulib.

22 months agolib: Update getopt.c from Gnulib with modifications.
Jia Tan [Fri, 22 Sep 2023 16:27:23 +0000 (00:27 +0800)] 
lib: Update getopt.c from Gnulib with modifications.

The code maintains the prior modifications of conditionally including
config.h and disabling NLS support.

_GL_UNUSED is repalced with the simple cast to void trick. _GL_UNUSED
is only used for these two parameters so its simpler than having to
define it.

22 months agolib: Add getopt-cdefs.h for getopt_long update.
Jia Tan [Fri, 22 Sep 2023 16:18:56 +0000 (00:18 +0800)] 
lib: Add getopt-cdefs.h for getopt_long update.

This was modified slightly from Gnulib. In Gnulib, it expects the
@HAVE_SYS_CDEFS_H@ to be replaced. Instead, we can set HAVE_SYS_CDEFS_H
on systems that have it and avoid copying another file into the build
directory. Since we are not using gnulib-tool, copying extra files
requires extra build system updates (and special handling with CMake) so
we should avoid when possible.

22 months agolib: Copy new header files from Gnulib without modification.
Jia Tan [Fri, 22 Sep 2023 16:15:25 +0000 (00:15 +0800)] 
lib: Copy new header files from Gnulib without modification.

The getopt related files have changed from Gnulib by splitting up
getopt.in.h into more modular header files. We could have kept
everything in just getopt.in.h, but this will help us continue to update
in the future.

22 months agoWindows: Update the version requirement comments from Win95 to W2k.
Lasse Collin [Fri, 22 Sep 2023 18:16:52 +0000 (21:16 +0300)] 
Windows: Update the version requirement comments from Win95 to W2k.

22 months agotuklib_physmem: Comment out support for Windows versions older than 2000.
Lasse Collin [Fri, 22 Sep 2023 18:12:54 +0000 (21:12 +0300)] 
tuklib_physmem: Comment out support for Windows versions older than 2000.

22 months agosysdefs.h: Update the comment about __USE_MINGW_ANSI_STDIO.
Lasse Collin [Sun, 24 Sep 2023 13:32:32 +0000 (16:32 +0300)] 
sysdefs.h: Update the comment about __USE_MINGW_ANSI_STDIO.

22 months agoxz: Windows: Don't (de)compress to special files like "con" or "nul".
Lasse Collin [Thu, 21 Sep 2023 23:33:29 +0000 (02:33 +0300)] 
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.

22 months agoCMake: Wrap two overlong lines that are possible to wrap.
Lasse Collin [Thu, 21 Sep 2023 17:42:52 +0000 (20:42 +0300)] 
CMake: Wrap two overlong lines that are possible to wrap.

22 months agoCMake: Add a comment about threads on Cygwin.
Lasse Collin [Thu, 21 Sep 2023 17:36:31 +0000 (20:36 +0300)] 
CMake: Add a comment about threads on Cygwin.

22 months agoMSVC: Remove Visual Studio project files and update INSTALL-MSVC.txt.
Lasse Collin [Tue, 12 Sep 2023 20:53:25 +0000 (23:53 +0300)] 
MSVC: Remove Visual Studio project files and update INSTALL-MSVC.txt.

CMake is now the preferred build file generator when building
with MSVC.

22 months agoCMake: Require VS2015 or later for building xzdec.
Lasse Collin [Thu, 21 Sep 2023 16:17:40 +0000 (19:17 +0300)] 
CMake: Require VS2015 or later for building xzdec.

xzdec might build with VS2013 but it hasn't been tested.
It was never supported before and VS2013 is old anyway
so for simplicity only liblzma is supported with VS2013.

22 months agoCMake: Allow building xz with Visual Studio 2015 and later.
Lasse Collin [Tue, 12 Sep 2023 20:43:49 +0000 (23:43 +0300)] 
CMake: Allow building xz with Visual Studio 2015 and later.

Building the command line tools xz and xzdec with the combination
of CMake + Visual Studio 2015/2017/2019/2022 works now.

VS2013 update 2 should still be able to build liblzma.
VS2013 cannot build the xz command line tool because xz
needs snprintf() that roughly conforms to C99.
VS2013 is old and no extra code will be added to support it.

Thanks to Kelvin Lee and Jia Tan for testing.

22 months agoMSVC: #define inline and restrict only when needed.
Lasse Collin [Tue, 12 Sep 2023 20:34:31 +0000 (23:34 +0300)] 
MSVC: #define inline and restrict only when needed.

This also drops the check for _WIN32 as that shouldn't be needed.

22 months agoCMake: Add support for replacement getopt_long (lib/getopt*).
Lasse Collin [Tue, 12 Sep 2023 19:16:56 +0000 (22:16 +0300)] 
CMake: Add support for replacement getopt_long (lib/getopt*).

Thanks to Jia Tan for the initial work. I added the libgnu target
and made a few related minor edits.

22 months agoCMake: Bump maximum policy version to 3.27.
Lasse Collin [Tue, 12 Sep 2023 18:12:34 +0000 (21:12 +0300)] 
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.

22 months agolib/getopt*.c: Include <config.h> only HAVE_CONFIG_H is defined.
Lasse Collin [Tue, 12 Sep 2023 17:55:10 +0000 (20:55 +0300)] 
lib/getopt*.c: Include <config.h> only HAVE_CONFIG_H is defined.

The CMake-based build doesn't use config.h.

Up-to-date getopt_long in Gnulib is LGPLv2 so at some
point it could be included in XZ Utils too but for now
this commit is enough to make CMake-based build possible.

22 months agoDoxygen: Add more C macro names to PREDEFINED.
Lasse Collin [Fri, 8 Sep 2023 16:08:57 +0000 (19:08 +0300)] 
Doxygen: Add more C macro names to PREDEFINED.

22 months agoliblzma: Move a few __attribute__ uses in function declarations.
Lasse Collin [Mon, 11 Sep 2023 15:47:26 +0000 (18:47 +0300)] 
liblzma: Move a few __attribute__ uses in function declarations.

The API headers have many attributes but these were left
as is for now.

22 months agoxz, xzdec, lzmainfo: Use tuklib_attr_noreturn.
Lasse Collin [Mon, 11 Sep 2023 16:03:35 +0000 (19:03 +0300)] 
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".

22 months agoRemove incorrect uses of __attribute__((__malloc__)).
Lasse Collin [Mon, 11 Sep 2023 15:53:31 +0000 (18:53 +0300)] 
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.

22 months agoBuild: Omit -Wc99-c11-compat since it warns about _Noreturn.
Lasse Collin [Fri, 8 Sep 2023 15:41:25 +0000 (18:41 +0300)] 
Build: Omit -Wc99-c11-compat since it warns about _Noreturn.

22 months agotuklib: Update tuklib_attr_noreturn for C11/C17 and C23.
Lasse Collin [Fri, 8 Sep 2023 15:19:26 +0000 (18:19 +0300)] 
tuklib: Update tuklib_attr_noreturn for C11/C17 and C23.

This makes no difference for GCC or Clang as they support
GNU C's __attribute__((__noreturn__)) but this helps with MSVC:

  - VS 2019 version 16.7 and later support _Noreturn if the
    options /std:c11 or /std:c17 are used. This gets handled
    with the check for __STDC_VERSION__ >= 201112.

  - When MSVC isn't in C11/C17 mode, __declspec(noreturn) is used.

C23 will deprecate _Noreturn (and <stdnoreturn.h>)
for [[noreturn]]. This commit anticipates that but
the final __STDC_VERSION__ value isn't known yet.

22 months agoUpdate THANKS.
Lasse Collin [Mon, 11 Sep 2023 14:22:44 +0000 (17:22 +0300)] 
Update THANKS.

22 months agoMSVC: xz: Make file_io.c and file_io.h compatible with MSVC.
Lasse Collin [Tue, 5 Sep 2023 19:42:10 +0000 (22:42 +0300)] 
MSVC: xz: Make file_io.c and file_io.h compatible with MSVC.

Thanks to Kelvin Lee for the original patches
and testing the modifications I made.

22 months agoMSVC: xz: Use GetTickCount64() to implement mytime_now().
Lasse Collin [Tue, 5 Sep 2023 18:33:35 +0000 (21:33 +0300)] 
MSVC: xz: Use GetTickCount64() to implement mytime_now().

It's available since Windows Vista.

22 months agoMSVC: xz: Use _stricmp() instead of strcasecmp() in suffix.c.
Kelvin Lee [Tue, 5 Sep 2023 12:05:09 +0000 (15:05 +0300)] 
MSVC: xz: Use _stricmp() instead of strcasecmp() in suffix.c.

22 months agoMSVC: xz: Use _isatty() from <io.h> to implement isatty().
Kelvin Lee [Tue, 5 Sep 2023 12:01:10 +0000 (15:01 +0300)] 
MSVC: xz: Use _isatty() from <io.h> to implement isatty().