Commit Graph

228 Commits

Author SHA1 Message Date
Lasse Collin 00eb6073c0
xz: Use my_landlock.h
A slightly silly thing is that xz may now query the ABI version up to
three times. We could call my_landlock_ruleset_attr_forbid_all() only
once and cache the result but it didn't seem worth doing.
2025-01-02 15:43:38 +02:00
Lasse Collin 0fc5a625d7
xzdec: Use my_landlock.h 2025-01-02 15:43:38 +02:00
Lasse Collin 1a8a1ad9a1
Build: Use -Wimplicit-fallthrough=5 when supported
Now that we have the FALLTHROUGH macro, use the strictest mode with
GCC so that comment-based fallthrough markings are no longer accepted.

In GCC, -Wextra includes -Wimplicit-fallthrough=3 and
-Wimplicit-fallthrough is the same as -Wimplicit-fallthrough=3.
Thus, the strict mode requires specifying -Wimplicit-fallthrough=5.

Clang has -Wimplicit-fallthrough which is *not* enabled by -Wextra.
Clang doesn't have a variant that takes an argument. Thus we need
to check for -Wimplicit-fallthrough. Do it before checking for
-Wimplicit-fallthrough=5 so that the latter overrides the former
when using GCC.
2025-01-02 15:43:37 +02:00
Lasse Collin 16821252c5
Windows: Make NLS require UCRT and gettext-runtime >= 0.23.1
Also remove the recently-added workaround from tuklib_gettext.h.
Requiring a new enough gettext-runtime is cleaner. I guess it's
mostly MSYS2 where xz is built with translation support, so once
MSYS2 has Gettext >= 0.23.1, this requirement shouldn't be a problem
in practice.
2025-01-02 15:35:25 +02:00
Lasse Collin cf54f70e14
CMake/macOS: Use GNU Libtool compatible shared library versioning
Because this increases the Mach-O compatibility_version, this commit
shouldn't cause any ABI compatibility trouble for existing CMake users
on macOS. This is assuming that they won't later downgrade to an older
liblzma version that was built with CMake before this commit.

Meson allows customising the Mach-O versioning too. So the three
build systems can be configured to be compatible.
2024-12-29 10:51:53 +02:00
Lasse Collin 94e1791668
CMake: Edit a comment 2024-12-29 10:51:53 +02:00
Lasse Collin f7a248f56e
CMake: Remove a duplicate word from a comment 2024-12-27 21:39:28 +02:00
Dexter Castor Döpping bf6da9a573
CMake: Disable unity builds project-wide
liblzma and xz can't be compiled as a unity/jumbo build because of
redeclarations and type name reuse. The CMake documentation recommends
setting UNITY_BUILD to false in this case.

This is especially important if we're compiled as a subproject and the
consumer wants to use CMAKE_UNITY_BUILD=ON for the rest of their code
base.

Closes: https://github.com/tukaani-project/xz/pull/158
2024-12-22 20:06:24 +02:00
Lasse Collin 22a35e64ce
lzmainfo: Use tuklib_mbstr_nonprint 2024-12-18 17:09:32 +02:00
Lasse Collin 03111595ee
xzdec: Use tuklib_mbstr_nonprint 2024-12-18 17:09:32 +02:00
Lasse Collin d22f96921f
xz: Use tuklib_mbstr_nonprint
Call tuklib_mask_nonprint() on filenames and also on a few other
strings from the command line too.

The filename printed by "xz --robot --list" (in list.c) is also masked.
It's good to get rid of tabs and newlines which would desync the output
but masking other chars wouldn't be strictly necessary. It might matter
with sensible filenames if LC_CTYPE is "C" (when iswprint() might reject
non-ASCII chars) and a script wants to read a filename from xz's output.
Hopefully it's an unusual enough corner case to not be a real problem.
2024-12-18 17:09:32 +02:00
Lasse Collin 3e9177fd20
xz: Use automatic word wrapping for help texts
--long-help is now one line longer because --lzma1 is now on its
own line.
2024-12-18 17:09:31 +02:00
Lasse Collin 61feaf681b
CMake: Bump maximum policy version to 3.31
With CMake 3.31, there were a few warnings from
CMP0177 "install() DESTINATION paths are normalized".
These occurred because the install(FILES) command in
my_install_man_lang() is called with a DESTINATION path
that contains two consecutive slashes, for example,
"share/man//man1". Such a path is for the English man pages.
With translated man pages, the language code goes between
the slashes. The warning was probably triggered because the
extra slash gets removed by the normalization.
2024-12-18 17:09:29 +02:00
Lasse Collin 74702ee00e Tests/Windows: Add the application manifest to the test programs
This ensures that the test programs get executed the same way as
the binaries that are installed.
2024-10-01 12:10:23 +03:00
Lasse Collin 46ee006162 Windows: Embed an application manifest in the EXE files
IMPORTANT: This includes a security fix to command line tool
           argument handling.

Some toolchains embed an application manifest by default to declare
UAC-compliance. Some also declare compatibility with Vista/8/8.1/10/11
to let the app access features newer than those of Vista.

We want all the above but also two more things:

  - Declare that the app is long path aware to support paths longer
    than 259 characters (this may also require a registry change).

  - Force the code page to UTF-8. This allows the command line tools
    to access files whose names contain characters that don't exist
    in the current legacy code page (except unpaired surrogates).
    The UTF-8 code page also fixes security issues in command line
    argument handling which can be exploited with malicious filenames.
    See the new file w32_application.manifest.comments.txt.

Thanks to Orange Tsai and splitline from DEVCORE Research Team
for discovering this issue.

Thanks to Vijay Sarvepalli for reporting the issue to me.

Thanks to Kelvin Lee for testing with MSVC and helping with
the required build system fixes.
2024-10-01 12:10:23 +03:00
Lasse Collin c3b9dad07d CMake: Add the resource files to the Cygwin and MSYS2 builds
Autotools-based build has always done this so this is for consistency.

However, the CMake build won't create the DEF file when building
for Cygwin or MSYS2 because in that context it should be useless.
(If Cygwin or MSYS2 is used to host building of normal Windows
binaries then the DEF file is still created.)
2024-09-29 01:26:45 +03:00
Lasse Collin da4f275bd1 CMake: Fix Windows resource file dependencies
If common_w32res.rc is modified, the resource files need to be rebuilt.
In contrast, the liblzma*.map files truly are link dependencies.
2024-09-29 01:26:13 +03:00
Lasse Collin 1c673c0aac CMake: Checking for CYGWIN covers MSYS2 too
On MSYS2, both CYGWIN and MSYS are set.
2024-09-29 01:26:13 +03:00
Lasse Collin dc7b9f24b7 Windows/CMake: Use the correct resource file for lzmadec.exe
CMakeLists.txt was using xzdec_w32res.rc for both xzdec and lzmadec.

Fixes: 998d0b2953
2024-09-25 21:31:06 +03:00
Lasse Collin d3e0e679b2 CMake: Don't install lzmadec.1 symlinks if XZ_TOOL_LZMADEC=OFF
Thanks-to: 榆柳松 (ZhengSen Wang) <wzhengsen@gmail.com>
Fixes: fb50c6ba1d
Closes: https://github.com/tukaani-project/xz/pull/134
2024-09-02 17:33:42 +03:00
Lasse Collin acdf21033a CMake: Fix the build when XZ_TOOL_LZMADEC=OFF
Co-developed-by: 榆柳松 (ZhengSen Wang) <wzhengsen@gmail.com>
Fixes: fb50c6ba1d
Fixes: https://github.com/tukaani-project/xz/pull/134
2024-09-02 17:33:06 +03:00
Lasse Collin bf901dee5d Build: Comment that elf_aux_info(3) will be available on OpenBSD >= 7.6 2024-07-19 20:06:24 +03:00
Lasse Collin f7103c2c2a Revert "liblzma: Add ARM64 CRC32 instruction support detection on OpenBSD"
This reverts commit dc03f6290f.

OpenBSD 7.6 will support elf_aux_info(3), and the detection code used
on FreeBSD will work on OpenBSD 7.6 too. Keep things simpler and drop
the OpenBSD-specific sysctl() method.

Thanks to Christian Weisgerber.
2024-07-19 20:06:24 +03:00
Lasse Collin 6408edac55 CMake: Bump maximum policy version to 3.30 2024-07-11 22:17:56 +03:00
Lasse Collin 9231c39ffb CMake: Require CMake 3.20 or later
This allows a few cleanups.
2024-07-11 20:11:38 +03:00
Lasse Collin b3e53122f4 CMake: Link xz against Threads::Threads if using pthreads
The liblzma target was recently changed to link against Threads::Threads
with the PRIVATE keyword. I had forgotten that xz itself depends on
pthreads too due to pthread_sigmask(). Thus, the build broke when
building shared liblzma and pthread_sigmask() wasn't in libc.

Thanks to Peter Seiderer for the bug report.

Fixes: ac05f1b0d7
Fixes: https://github.com/tukaani-project/xz/issues/129#issuecomment-2204522994
2024-07-03 20:45:48 +03:00
Lasse Collin 2d13d10357 CMake: Improve NLS error messages 2024-07-02 22:41:48 +03:00
Lasse Collin 628d8d2c4f CMake: Update the comment at the top of CMakeLists.txt
While po/*.gmo files won't be used from the release tarball,
the generated translated man pages will be used still. Those
are text files and po4a has slightly more dependencies than
gettext tools so installing po4a might be a bit more challenging
in some situations.
2024-07-02 22:41:48 +03:00
Lasse Collin b4b23c94fd CMake: Drop support for pre-generated po/*.gmo files
When a release tarball is created using Autotools, the tarball includes
po/*.gmo files which are binary files generated from po/*.po. Other
tarball creation methods don't and won't create the .gmo files.

It feels clearer if CMake will never install pre-generated binary files
from the source package. If people are able to install CMake, they
likely are able to install gettext tools as well (assuming they want
translations).
2024-07-02 22:41:00 +03:00
Lasse Collin fb99f8e8c5 CMake: Make XZ_NLS handling more robust
If a user set XZ_NLS=ON but find_package(Intl) failed or CMake version
wasn't at least 3.20, the configuration would fail in a cryptic way.

If XZ_NLS is enabled, require that CMake is new enough and that either
gettext tools or pre-generated .gmo files are available. Otherwise fail
the configuration. Previously missing gettext tools and .gmo files would
only result in a warning.

Missing man page translations are still only a warning.

Thanks to Peter Seiderer for the bug report.

Fixes: https://github.com/tukaani-project/xz/issues/129
Closes: https://github.com/tukaani-project/xz/pull/130
2024-07-02 22:40:37 +03:00
Lasse Collin 24f0f7e399 CMake: Fix ENABLE_NLS comment too
Fixes: 29f77c7b70
2024-07-02 22:39:46 +03:00
Lasse Collin a0df067613 CMake: The compile definition is ENABLE_NLS, not XZ_NLS
The CMake variables were renamed and accidentally also
the compile definition was renamed. As a result, translation
support wasn't actually enabled in the executables.

Fixes: 29f77c7b70
2024-07-02 18:39:43 +03:00
Xi Ruoyao 7baf6835cf liblzma: Speed up CRC32 calculation on 64-bit LoongArch
The crc.w.{b/h/w/d}.w instructions in LoongArch can calculate the CRC32
result for 1/2/4/8 bytes in a single operation. Using these is much
faster compared to the generic method.

Optimized CRC32 is enabled unconditionally on 64-bit LoongArch because
the LoongArch specification says that CRC32 instructions shall be
implemented for 64-bit processors. Optimized CRC32 isn't enabled for
32-bit LoongArch processors because not enough information is available
about them.

Co-authored-by: Lasse Collin <lasse.collin@tukaani.org>

Closes: https://github.com/tukaani-project/xz/pull/86
2024-07-01 17:09:57 +03:00
Lasse Collin 5279828635 CMake: Not experimental anymore
While the CMake support has gotten a lot less testing than
the Autotools-based build, the supported features should now
be equal. The output may differ slightly, for example,
liblzma.pc may have

    Libs.private: -pthread -lpthread

with Autotools on GNU/Linux. CMake doesn't put any options
in Libs.private because on modern glibc the pthread functions
are in libc. The options options aren't required to link static
liblzma into an application.

Autotools-based build doesn't generate or install
lib/cmake/liblzma-*.cmake files. This means that on most
platforms one cannot rely on

    find_package(liblzma 5.2.5 REQUIRED CONFIG)

or such finding those files.
2024-06-26 15:48:56 +03:00
Lasse Collin de215a0517 CMake: Use configure_file() to copy a file
I had missed this simpler method before. It does create a dependency
so that if .in.h changes the copying is done again.
2024-06-25 16:13:39 +03:00
Lasse Collin e620f35097 CMake: Always add pthread flags into CMAKE_REQUIRED_LIBRARIES
It was weird to add CMAKE_THREAD_LIBS_INIT in CMAKE_REQUIRED_LIBRARIES
only if CLOCK_MONOTONIC is available. Alternative would be to remove
the thread libs from CMAKE_REQUIRED_LIBRARIES after the check for
pthread_condattr_setclock() but keeping the libs should be fine too.
Then it's ready in case more pthread functions were wanted some day.
2024-06-25 15:56:39 +03:00
Sam James 068a70e549 CMake: Tweak comments
Co-authored-by: Lasse Collin <lasse.collin@tukaani.org>
2024-06-25 14:55:15 +03:00
Lasse Collin 3c95c93bca CMake: Edit white space for consistency 2024-06-25 14:54:53 +03:00
Lasse Collin 114cba69db CMake: Fix three checks if building with -flto
In CMake, check_c_source_compiles() always links too. With
link-time optimization, unused functions may get omitted if
main() doesn't depend on them. Consider the following which
tries to check if somefunction() is available when <someheader.h>
has been included:

    #include <someheader.h>
    int foo(void) { return somefunction(); }
    int main(void) { return 0; }

LTO may omit foo() completely because the program as a whole doesn't
need it and then the program will link even if the symbol somefunction
isn't available in libc or other library being linked in, and then
the test may pass when it shouldn't.

What happens if <someheader.h> doesn't declare somefunction()?
Shouldn't the test fail in the compilation phase already? It should
but many compilers don't follow the C99 and later standards that
prohibit implicit function declarations. Instead such compilers
assume that somefunction() exists, compilation succeeds (with a
warning), and then linker with LTO omits the call to somefunction().

Change the tests so that they are part of main(). If compiler accepts
implicitly declared functions, LTO cannot omit them because it has to
assume that they might have side effects and thus linking will fail.
On the other hand, if the functions/intrinsics being used are supported,
they might get optimized away but in that case it's fine because they
really are supported.

It is fine to use __attribute__((target(...))) for main(). At least
it works with GCC 4.9 to 14.1 on x86-64.

Reported-by: Sam James <sam@gentoo.org>
2024-06-25 14:54:53 +03:00
Lasse Collin 78e882205e CMake: Use MATCHES instead of multiple STREQUAL 2024-06-25 14:54:53 +03:00
Lasse Collin d3f20382fc CMake: Improve the comment about LIBS 2024-06-25 14:54:53 +03:00
Lasse Collin 33ec377729 CMake: Fix a typo in a message
It was spotted with codespell.
2024-06-24 20:01:25 +03:00
Lasse Collin a3d6eb797c CMake: Add autodetection for 32-bit x86 CRC assembly usage 2024-06-24 18:15:58 +03:00
Lasse Collin dbc14f213e CMake: Move option(XZ_ASM_I386) downwards a few lines 2024-06-23 23:09:14 +03:00
Lasse Collin 85b081f5d4 liblzma: Make 32-bit x86 CRC assembly co-exist with CLMUL
Now runtime detection of CLMUL support can pick between the CLMUL and
the generic assembly implementations. Whatever overhead this has for
builds that omit CLMUL completely isn't important because builds for
any non-ancient system is likely to include the CLMUL code too.

Handle the CRC tables in crcXX_fast.c files because now these files
are built even when assembly code is used.

If 32-bit x86 assembly is enabled then it will always be built even
if compiler flags were such that CLMUL would be allowed unconditionally.
That is, runtime detection will be used anyway. This keeps the build
rules simpler.

In LZ encoder, build and use lzma_lz_hash_table[256] if CLMUL CRC
is used without runtime detection. Previously this wasn't needed
because crc32_table.c included the lzma_crc32_table[][] in the build
unless encoder support had been disabled. Including an 8 KiB table
was silly when only 1 KiB is actually used. So now liblzma is 7 KiB
smaller if CLMUL is enabled without runtime detection.
2024-06-23 14:36:44 +03:00
Lasse Collin 1dca581ff2 CMake: Define HAVE_CRC_X86_ASM when 32-bit x86 CRC assembly is used 2024-06-23 14:36:44 +03:00
Lasse Collin 0232e66d5b CMake: Add XZ_EXTERNAL_SHA256 2024-06-20 21:53:07 +03:00
Lasse Collin 4535b80cae CMake: Move threading detection a few lines up
It feels clearer this way, and when support for external SHA-256
is added, this will keep the order of the library detection the
same as in configure.ac (check for pthreads before libmd) although
it shouldn't matter in practice.
2024-06-20 21:53:07 +03:00
Lasse Collin 94d062dbac CMake: Move the sandbox code out of the liblzma section
Sandboxing is for the command line tools, not liblzma.
No functional changes.
2024-06-20 21:53:07 +03:00
Lasse Collin 75ce4797d4 CMake: Keep existing options in LIBS when adding -lrt
This makes no difference yet because -lrt is currently the only option
that might be added to LIBS.
2024-06-20 21:53:07 +03:00