Browse Source

Update contrib/libs/lzma to 5.4.6

robot-contrib 1 year ago
parent
commit
1daa4c5f73

+ 13 - 1
contrib/libs/lzma/COPYING

@@ -21,6 +21,17 @@ XZ Utils Licensing
         XZ Utils specific documentation files in other directories
         are in the public domain.
 
+        Note: The JavaScript files (under the MIT license) have
+        been removed from the Doxygen-generated HTML version of the
+        liblzma API documentation. Doxygen itself is under the GNU GPL
+        but the remaining files generated by Doxygen are not affected
+        by the licenses used in Doxygen because Doxygen licensing has
+        the following exception:
+
+            "Documents produced by doxygen are derivative works
+            derived from the input used in their production;
+            they are not affected by this license."
+
       - Translated messages are in the public domain.
 
       - The build system contains public domain files, and files that
@@ -47,7 +58,8 @@ XZ Utils Licensing
     naturally it is not legally required. Here is an example of a good
     notice to put into "about box" or into documentation:
 
-        This software includes code from XZ Utils <https://tukaani.org/xz/>.
+        This software includes code from XZ Utils
+        <https://xz.tukaani.org/xz-utils/>.
 
     The following license texts are included in the following files:
       - COPYING.LGPLv2.1: GNU Lesser General Public License version 2.1

+ 4 - 4
contrib/libs/lzma/COPYING.GPLv3

@@ -1,7 +1,7 @@
                     GNU GENERAL PUBLIC LICENSE
                        Version 3, 29 June 2007
 
- Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
  Everyone is permitted to copy and distribute verbatim copies
  of this license document, but changing it is not allowed.
 
@@ -645,7 +645,7 @@ the "copyright" line and a pointer to where the full notice is found.
     GNU General Public License for more details.
 
     You should have received a copy of the GNU General Public License
-    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+    along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
 Also add information on how to contact you by electronic and paper mail.
 
@@ -664,11 +664,11 @@ might be different; for a GUI interface, you would use an "about box".
   You should also get your employer (if you work as a programmer) or school,
 if any, to sign a "copyright disclaimer" for the program, if necessary.
 For more information on this, and how to apply and follow the GNU GPL, see
-<http://www.gnu.org/licenses/>.
+<https://www.gnu.org/licenses/>.
 
   The GNU General Public License does not permit incorporating your program
 into proprietary programs.  If your program is a subroutine library, you
 may consider it more useful to permit linking proprietary applications with
 the library.  If this is what you want to do, use the GNU Lesser General
 Public License instead of this License.  But first, please read
-<http://www.gnu.org/philosophy/why-not-lgpl.html>.
+<https://www.gnu.org/licenses/why-not-lgpl.html>.

+ 69 - 20
contrib/libs/lzma/INSTALL

@@ -22,13 +22,16 @@ XZ Utils Installation
     3. xzgrep and other scripts
        3.1. Dependencies
        3.2. PATH
-    4. Troubleshooting
-       4.1. "No C99 compiler was found."
-       4.2. "No POSIX conforming shell (sh) was found."
-       4.3. configure works but build fails at crc32_x86.S
-       4.4. Lots of warnings about symbol visibility
-       4.5. "make check" fails
-       4.6. liblzma.so (or similar) not found when running xz
+    4. Tests
+       4.1 Testing in parallel
+       4.2 Cross compiling
+    5. Troubleshooting
+       5.1. "No C99 compiler was found."
+       5.2. "No POSIX conforming shell (sh) was found."
+       5.3. configure works but build fails at crc32_x86.S
+       5.4. Lots of warnings about symbol visibility
+       5.5. "make check" fails
+       5.6. liblzma.so (or similar) not found when running xz
 
 
 0. Preface
@@ -100,7 +103,7 @@ XZ Utils Installation
     XZ Utils doesn't have code to detect the amount of physical RAM and
     number of CPU cores on MINIX 3.
 
-    See section 4.4 in this file about symbol visibility warnings (you
+    See section 5.4 in this file about symbol visibility warnings (you
     may want to pass gl_cv_cc_visibility=no to configure).
 
 
@@ -127,14 +130,14 @@ XZ Utils Installation
     missing from PATH (/usr/xpg4/bin or /usr/xpg6/bin). Nowadays
     /usr/xpg4/bin is added to the script PATH by default on Solaris
     (see --enable-path-for-scripts=PREFIX in section 2), but old xz
-    releases needed extra steps. See sections 4.5 and 3.2 for more
+    releases needed extra steps. See sections 5.5 and 3.2 for more
     information.
 
 
 1.2.6. Tru64
 
     If you try to use the native C compiler on Tru64 (passing CC=cc to
-    configure), you may need the workaround mention in section 4.1 in
+    configure), you may need the workaround mention in section 5.1 in
     this file (pass also ac_cv_prog_cc_c99= to configure).
 
 
@@ -455,8 +458,10 @@ XZ Utils Installation
                         win95   Use Windows 95 compatible threads. This
                                 is compatible with Windows XP and later
                                 too. This is the default for 32-bit x86
-                                Windows builds. The `win95' threading is
-                                incompatible with --enable-small.
+                                Windows builds. Unless the compiler
+                                supports __attribute__((__constructor__)),
+                                the `win95' threading is incompatible with
+                                --enable-small.
 
                         vista   Use Windows Vista compatible threads. The
                                 resulting binaries won't run on Windows XP
@@ -596,7 +601,7 @@ XZ Utils Installation
     a fallback xzdiff will use mkdir to securely create a temporary
     directory. Having mktemp available is still recommended since the
     mkdir fallback method isn't as robust as mktemp is. The original
-    mktemp can be found from <http://www.mktemp.org/>. On GNU, most will
+    mktemp can be found from <https://www.mktemp.org/>. On GNU, most will
     use the mktemp program from GNU coreutils instead of the original
     implementation. Both mktemp versions are fine.
 
@@ -624,10 +629,54 @@ XZ Utils Installation
                 src/scripts/xz*.in
 
 
-4. Troubleshooting
+4. Tests
+--------
+
+    The test framework can be built and run by executing "make check" in
+    the build directory. The tests are a mix of executables and POSIX
+    shell scripts (sh). All tests should pass if the default configuration
+    is used. Disabling features through the configure options may cause
+    some tests to be skipped. If any tests do not pass, see section 5.5.
+
+
+4.1. Testing in parallel
+
+    The tests can be run in parallel using the "-j" make option on systems
+    that support it. For instance, "make -j4 check" will run up to four
+    tests simultaneously.
+
+
+4.2. Cross compiling
+
+    The tests can be built without running them:
+
+        make check TESTS=
+
+    The TESTS variable is the list of tests you wish to run. Leaving it
+    empty will compile the tests without running any.
+
+    If the tests are copied to a target machine to execute, the test data
+    files in the directory tests/files must also be copied. The tests
+    search for the data files using the environment variable $srcdir,
+    expecting to find the data files under $srcdir/files/. If $srcdir
+    isn't set then it defaults to the current directory.
+
+    The shell script tests can be copied from the source directory to the
+    target machine to execute. In addition to the test files, these tests
+    will expect the following relative file paths to execute properly:
+
+        ./create_compress_files
+        ../config.h
+        ../src/xz/xz
+        ../src/xzdec/xzdec
+        ../src/scripts/xzdiff
+        ../src/scripts/xzgrep
+
+
+5. Troubleshooting
 ------------------
 
-4.1. "No C99 compiler was found."
+5.1. "No C99 compiler was found."
 
     You need a C99 compiler to build XZ Utils. If the configure script
     cannot find a C99 compiler and you think you have such a compiler
@@ -642,7 +691,7 @@ XZ Utils Installation
     support enough C99.
 
 
-4.2. "No POSIX conforming shell (sh) was found."
+5.2. "No POSIX conforming shell (sh) was found."
 
     xzgrep and other scripts need a shell that (roughly) conforms
     to POSIX. The configure script tries to find such a shell. If
@@ -652,7 +701,7 @@ XZ Utils Installation
     this error by passing --disable-scripts to configure.
 
 
-4.3. configure works but build fails at crc32_x86.S
+5.3. configure works but build fails at crc32_x86.S
 
     The easy fix is to pass --disable-assembler to the configure script.
 
@@ -669,7 +718,7 @@ XZ Utils Installation
     (see INSTALL.generic).
 
 
-4.4. Lots of warnings about symbol visibility
+5.4. Lots of warnings about symbol visibility
 
     On some systems where symbol visibility isn't supported, GCC may
     still accept the visibility options and attributes, which will make
@@ -681,7 +730,7 @@ XZ Utils Installation
     using --enable-werror.
 
 
-4.5. "make check" fails
+5.5. "make check" fails
 
     If the other tests pass but test_scripts.sh fails, then the problem
     is in the scripts in src/scripts. Comparing the contents of
@@ -707,7 +756,7 @@ XZ Utils Installation
     information.
 
 
-4.6. liblzma.so (or similar) not found when running xz
+5.6. liblzma.so (or similar) not found when running xz
 
     If you installed the package with "make install" and get an error
     about liblzma.so (or a similarly named file) being missing, try

+ 268 - 1
contrib/libs/lzma/NEWS

@@ -2,6 +2,273 @@
 XZ Utils Release Notes
 ======================
 
+5.4.6 (2024-01-26)
+
+    * Fixed a bug involving internal function pointers in liblzma not
+      being initialized to NULL. The bug can only be triggered if
+      lzma_filters_update() is called on a LZMA1 encoder, so it does
+      not affect xz or any application known to us that uses liblzma.
+
+    * xz:
+
+        - Fixed a regression introduced in 5.4.2 that caused encoding
+          in the raw format to unnecessarily fail if --suffix was not
+          used. For instance, the following command no longer reports
+          that --suffix must be used:
+
+              echo foo | xz --format=raw --lzma2 | wc -c
+
+        - Fixed an issue on MinGW-w64 builds that prevented reading
+          from or writing to non-terminal character devices like NUL.
+
+    * Added a new test.
+
+
+5.4.5 (2023-11-01)
+
+    * liblzma:
+
+        - Use __attribute__((__no_sanitize_address__)) to avoid address
+          sanitization with CRC64 CLMUL. It uses 16-byte-aligned reads
+          which can extend past the bounds of the input buffer and
+          inherently trigger address sanitization errors. This isn't
+          a bug.
+
+        - Fixed an assertion failure that could be triggered by a large
+          unpadded_size argument. It was verified that there was no
+          other bug than the assertion failure.
+
+        - Fixed a bug that prevented building with Windows Vista
+          threading when __attribute__((__constructor__)) is not
+          supported.
+
+    * xz now properly handles special files such as "con" or "nul" on
+      Windows. Before this fix, the following wrote "foo" to the
+      console and deleted the input file "con_xz":
+
+          echo foo | xz > con_xz
+          xz --suffix=_xz --decompress con_xz
+
+    * Build systems:
+
+        - Allow builds with Windows win95 threading and small mode when
+          __attribute__((__constructor__)) is supported.
+
+        - Added a new line to liblzma.pc for MSYS2 (Windows):
+
+              Cflags.private: -DLZMA_API_STATIC
+
+          When compiling code that will link against static liblzma,
+          the LZMA_API_STATIC macro needs to be defined on Windows.
+
+        - CMake specific changes:
+
+            * Fixed a bug that allowed CLOCK_MONOTONIC to be used even
+              if the check for it failed.
+
+            * Fixed a bug where configuring CMake multiple times
+              resulted in HAVE_CLOCK_GETTIME and HAVE_CLOCK_MONOTONIC
+              not being set.
+
+            * Fixed the build with MinGW-w64-based Clang/LLVM 17.
+              llvm-windres now has more accurate GNU windres emulation
+              so the GNU windres workaround from 5.4.1 is needed with
+              llvm-windres version 17 too.
+
+            * The import library on Windows is now properly named
+              "liblzma.dll.a" instead of "libliblzma.dll.a"
+
+            * Fixed a bug causing the Ninja Generator to fail on
+              UNIX-like systems. This bug was introduced in 5.4.0.
+
+            * Added a new option to disable CLMUL CRC64.
+
+            * A module-definition (.def) file is now created when
+              building liblzma.dll with MinGW-w64.
+
+            * The pkg-config liblzma.pc file is now installed on all
+              builds except when using MSVC on Windows.
+
+            * Added large file support by default for platforms that
+              need it to handle files larger than 2 GiB. This includes
+              MinGW-w64, even 64-bit builds.
+
+    * Small fixes and improvements to the tests.
+
+    * Updated translations: Chinese (simplified) and Esperanto.
+
+
+5.4.4 (2023-08-02)
+
+    * liblzma and xzdec can now build against WASI SDK when threading
+      support is disabled. xz and tests don't build yet.
+
+    * CMake:
+
+        - Fixed a bug preventing other projects from including liblzma
+          multiple times using find_package().
+
+        - Don't create broken symlinks in Cygwin and MSYS2 unless
+          supported by the environment. This prevented building for the
+          default MSYS2 environment. The problem was introduced in
+          xz 5.4.0.
+
+    * Documentation:
+
+        - Small improvements to man pages.
+
+        - Small improvements and typo fixes for liblzma API
+          documentation.
+
+    * Tests:
+
+        - Added a new section to INSTALL to describe basic test usage
+          and address recent questions about building the tests when
+          cross compiling.
+
+        - Small fixes and improvements to the tests.
+
+    * Translations:
+
+        - Fixed a mistake that caused one of the error messages to not
+          be translated. This only affected versions 5.4.2 and 5.4.3.
+
+        - Updated the Chinese (simplified), Croatian, Esperanto, German,
+          Korean, Polish, Romanian, Spanish, Swedish, Ukrainian, and
+          Vietnamese translations.
+
+        - Updated the German, Korean, Romanian, and Ukrainian man page
+          translations.
+
+
+5.4.3 (2023-05-04)
+
+    * All fixes from 5.2.12
+
+    * Features in the CMake build can now be disabled as CMake cache
+      variables, similar to the Autotools build.
+
+    * Minor update to the Croatian translation.
+
+
+5.4.2 (2023-03-18)
+
+    * All fixes from 5.2.11 that were not included in 5.4.1.
+
+    * If xz is built with support for the Capsicum sandbox but running
+      in an environment that doesn't support Capsicum, xz now runs
+      normally without sandboxing instead of exiting with an error.
+
+    * liblzma:
+
+        - Documentation was updated to improve the style, consistency,
+          and completeness of the liblzma API headers.
+
+        - The Doxygen-generated HTML documentation for the liblzma API
+          header files is now included in the source release and is
+          installed as part of "make install". All JavaScript is
+          removed to simplify license compliance and to reduce the
+          install size.
+
+        - Fixed a minor bug in lzma_str_from_filters() that produced
+          too many filters in the output string instead of reporting
+          an error if the input array had more than four filters. This
+          bug did not affect xz.
+
+    * Build systems:
+
+        - autogen.sh now invokes the doxygen tool via the new wrapper
+          script doxygen/update-doxygen, unless the command line option
+          --no-doxygen is used.
+
+        - Added microlzma_encoder.c and microlzma_decoder.c to the
+          VS project files for Windows and to the CMake build. These
+          should have been included in 5.3.2alpha.
+
+    * Tests:
+
+        - Added a test to the CMake build that was forgotten in the
+          previous release.
+
+        - Added and refactored a few tests.
+
+    * Translations:
+
+        - Updated the Brazilian Portuguese translation.
+
+        - Added Brazilian Portuguese man page translation.
+
+
+5.4.1 (2023-01-11)
+
+    * liblzma:
+
+        - Fixed the return value of lzma_microlzma_encoder() if the
+          LZMA options lc/lp/pb are invalid. Invalid lc/lp/pb options
+          made the function return LZMA_STREAM_END without encoding
+          anything instead of returning LZMA_OPTIONS_ERROR.
+
+        - Windows / Visual Studio: Workaround a possible compiler bug
+          when targeting 32-bit x86 and compiling the CLMUL version of
+          the CRC64 code. The CLMUL code isn't enabled by the Windows
+          project files but it is in the CMake-based builds.
+
+    * Build systems:
+
+        - Windows-specific CMake changes:
+
+            * Don't try to enable CLMUL CRC64 code if _mm_set_epi64x()
+              isn't available. This fixes CMake-based build with Visual
+              Studio 2013.
+
+            * Created a workaround for a build failure with windres
+              from GNU binutils. It is used only when the C compiler
+              is GCC (not Clang). The workaround is incompatible
+              with llvm-windres, resulting in "XZx20Utils" instead
+              of "XZ Utils" in the resource file, but without the
+              workaround llvm-windres works correctly. See the
+              comment in CMakeLists.txt for details.
+
+            * Included the resource files in the xz and xzdec build
+              rules. Building the command line tools is still
+              experimental but possible with MinGW-w64.
+
+        - Visual Studio: Added stream_decoder_mt.c to the project
+          files. Now the threaded decompressor lzma_stream_decoder_mt()
+          gets built. CMake-based build wasn't affected.
+
+        - Updated windows/INSTALL-MSVC.txt to mention that CMake-based
+          build is now the preferred method with Visual Studio. The
+          project files will probably be removed after 5.4.x releases.
+
+        - Changes to #defines in config.h:
+
+            * HAVE_DECL_CLOCK_MONOTONIC was replaced by
+              HAVE_CLOCK_MONOTONIC. The old macro was always defined
+              in configure-generated config.h to either 0 or 1. The
+              new macro is defined (to 1) only if the declaration of
+              CLOCK_MONOTONIC is available. This matches the way most
+              other config.h macros work and makes things simpler with
+              other build systems.
+
+            * HAVE_DECL_PROGRAM_INVOCATION_NAME was replaced by
+              HAVE_PROGRAM_INVOCATION_NAME for the same reason.
+
+    * Tests:
+
+        - Fixed test script compatibility with ancient /bin/sh
+          versions. Now the five test_compress_* tests should
+          no longer fail on Solaris 10.
+
+        - Added and refactored a few tests.
+
+    * Translations:
+
+        - Updated the Catalan and Esperanto translations.
+
+        - Added Korean and Ukrainian man page translations.
+
+
 5.4.0 (2022-12-13)
 
     This bumps the minor version of liblzma because new features were
@@ -830,7 +1097,7 @@ XZ Utils Release Notes
           of the deprecated egrep and fgrep commands.
 
         - Fixed parsing of the options -E, -F, -G, -P, and -X. The
-          problem occurred when multiple options were specied in
+          problem occurred when multiple options were specified in
           a single argument, for example,
 
               echo foo | xzgrep -Fe foo

+ 9 - 5
contrib/libs/lzma/README

@@ -113,8 +113,8 @@ XZ Utils
     Since the liblzma API has similarities to the zlib API, some people
     may find it useful to read the zlib docs and tutorial too:
 
-        http://zlib.net/manual.html
-        http://zlib.net/zlib_how.html
+        https://zlib.net/manual.html
+        https://zlib.net/zlib_how.html
 
 
 2. Version numbering
@@ -281,13 +281,17 @@ XZ Utils
     7-Zip and the p7zip port of 7-Zip support the .xz format starting
     from the version 9.00alpha.
 
-        http://7-zip.org/
-        http://p7zip.sourceforge.net/
+        https://7-zip.org/
+        https://p7zip.sourceforge.net/
 
     XZ Embedded is a limited implementation written for use in the Linux
     kernel, but it is also suitable for other embedded use.
 
-        https://tukaani.org/xz/embedded.html
+        https://xz.tukaani.org/xz-embedded/
+
+    XZ for Java is a complete implementation written in pure Java.
+
+        https://xz.tukaani.org/xz-for-java/
 
 
 6. Contact information

+ 13 - 7
contrib/libs/lzma/common/mythread.h

@@ -79,7 +79,7 @@ do { \
 } while (0)
 
 
-#if !(defined(_WIN32) && !defined(__CYGWIN__))
+#if !(defined(_WIN32) && !defined(__CYGWIN__)) && !defined(__wasm__)
 // Use sigprocmask() to set the signal mask in single-threaded programs.
 #include <signal.h>
 
@@ -100,12 +100,18 @@ mythread_sigmask(int how, const sigset_t *restrict set,
 // Using pthreads //
 ////////////////////
 
-#include <sys/time.h>
 #include <pthread.h>
 #include <signal.h>
 #include <time.h>
 #include <errno.h>
 
+// If clock_gettime() isn't available, use gettimeofday() from <sys/time.h>
+// as a fallback. gettimeofday() is in SUSv2 and thus is supported on all
+// relevant POSIX systems.
+#ifndef HAVE_CLOCK_GETTIME
+#	include <sys/time.h>
+#endif
+
 #define MYTHREAD_RET_TYPE void *
 #define MYTHREAD_RET_VALUE NULL
 
@@ -219,8 +225,8 @@ static inline int
 mythread_cond_init(mythread_cond *mycond)
 {
 #ifdef HAVE_CLOCK_GETTIME
-	// NOTE: HAVE_DECL_CLOCK_MONOTONIC is always defined to 0 or 1.
-#	if defined(HAVE_PTHREAD_CONDATTR_SETCLOCK) && HAVE_DECL_CLOCK_MONOTONIC
+#	if defined(HAVE_PTHREAD_CONDATTR_SETCLOCK) && \
+		defined(HAVE_CLOCK_MONOTONIC)
 	struct timespec ts;
 	pthread_condattr_t condattr;
 
@@ -294,8 +300,8 @@ static inline void
 mythread_condtime_set(mythread_condtime *condtime, const mythread_cond *cond,
 		uint32_t timeout_ms)
 {
-	condtime->tv_sec = timeout_ms / 1000;
-	condtime->tv_nsec = (timeout_ms % 1000) * 1000000;
+	condtime->tv_sec = (time_t)(timeout_ms / 1000);
+	condtime->tv_nsec = (long)((timeout_ms % 1000) * 1000000);
 
 #ifdef HAVE_CLOCK_GETTIME
 	struct timespec now;
@@ -372,7 +378,7 @@ typedef struct {
 			abort(); \
 		if (pending_) { \
 			func(); \
-			if (!InitOnceComplete(&once, 0, NULL)) \
+			if (!InitOnceComplete(&once_, 0, NULL)) \
 				abort(); \
 		} \
 	} while (0)

+ 10 - 12
contrib/libs/lzma/common/sysdefs.h

@@ -24,7 +24,15 @@
 #	include <config.h>
 #endif
 
-// Get standard-compliant stdio functions under MinGW and MinGW-w64.
+// This #define ensures that C99 and POSIX compliant stdio functions are
+// available with MinGW-w64 (both 32-bit and 64-bit). Modern MinGW-w64 adds
+// this automatically, for example, when the compiler is in C99 (or later)
+// mode when building against msvcrt.dll. It still doesn't hurt to be explicit
+// that we always want this and #define this unconditionally.
+//
+// With Universal CRT (UCRT) this is less important because UCRT contains
+// C99-compatible stdio functions. It's still nice to #define this as UCRT
+// doesn't support the POSIX thousand separator flag in printf (like "%'u").
 #ifdef __MINGW32__
 #	define __USE_MINGW_ANSI_STDIO 1
 #endif
@@ -127,7 +135,7 @@
 #include <stdlib.h>
 #include <assert.h>
 
-// Pre-C99 systems lack stdbool.h. All the code in LZMA Utils must be written
+// Pre-C99 systems lack stdbool.h. All the code in XZ Utils must be written
 // so that it works with fake bool type, for example:
 //
 //    bool foo = (flags & 0x100) != 0;
@@ -149,18 +157,8 @@ typedef unsigned char _Bool;
 #	define __bool_true_false_are_defined 1
 #endif
 
-// string.h should be enough but let's include strings.h and memory.h too if
-// they exists, since that shouldn't do any harm, but may improve portability.
 #include <string.h>
 
-#ifdef HAVE_STRINGS_H
-#	include <strings.h>
-#endif
-
-#ifdef HAVE_MEMORY_H
-#	include <memory.h>
-#endif
-
 // As of MSVC 2013, inline and restrict are supported with
 // non-standard keywords.
 #if defined(_WIN32) && defined(_MSC_VER)

+ 228 - 66
contrib/libs/lzma/common/tuklib_integer.h

@@ -52,6 +52,12 @@
 // and such functions.
 #if defined(__INTEL_COMPILER) && (__INTEL_COMPILER >= 1500)
 #	include <immintrin.h>
+// Only include <intrin.h> when it is needed. GCC and Clang can both
+// use __builtin's, so we only need Windows instrincs when using MSVC.
+// GCC and Clang can set _MSC_VER on Windows, so we need to exclude these
+// cases explicitly.
+#elif defined(_MSC_VER) && !TUKLIB_GNUC_REQ(3, 4) && !defined(__clang__)
+#	include <intrin.h>
 #endif
 
 
@@ -189,6 +195,9 @@
 // Unaligned reads and writes //
 ////////////////////////////////
 
+// No-strict-align archs like x86-64
+// ---------------------------------
+//
 // The traditional way of casting e.g. *(const uint16_t *)uint8_pointer
 // is bad even if the uint8_pointer is properly aligned because this kind
 // of casts break strict aliasing rules and result in undefined behavior.
@@ -203,12 +212,115 @@
 // build time. A third method, casting to a packed struct, would also be
 // an option but isn't provided to keep things simpler (it's already a mess).
 // Hopefully this is flexible enough in practice.
+//
+// Some compilers on x86-64 like Clang >= 10 and GCC >= 5.1 detect that
+//
+//     buf[0] | (buf[1] << 8)
+//
+// reads a 16-bit value and can emit a single 16-bit load and produce
+// identical code than with the memcpy() method. In other cases Clang and GCC
+// produce either the same or better code with memcpy(). For example, Clang 9
+// on x86-64 can detect 32-bit load but not 16-bit load.
+//
+// MSVC uses unaligned access with the memcpy() method but emits byte-by-byte
+// code for "buf[0] | (buf[1] << 8)".
+//
+// Conclusion: The memcpy() method is the best choice when unaligned access
+// is supported.
+//
+// Strict-align archs like SPARC
+// -----------------------------
+//
+// GCC versions from around 4.x to to at least 13.2.0 produce worse code
+// from the memcpy() method than from simple byte-by-byte shift-or code
+// when reading a 32-bit integer:
+//
+//     (1) It may be constructed on stack using using four 8-bit loads,
+//         four 8-bit stores to stack, and finally one 32-bit load from stack.
+//
+//     (2) Especially with -Os, an actual memcpy() call may be emitted.
+//
+// This is true on at least on ARM, ARM64, SPARC, SPARC64, MIPS64EL, and
+// RISC-V. Of these, ARM, ARM64, and RISC-V support unaligned access in
+// some processors but not all so this is relevant only in the case when
+// GCC assumes that unaligned is not supported or -mstrict-align or
+// -mno-unaligned-access is used.
+//
+// For Clang it makes little difference. ARM64 with -O2 -mstrict-align
+// was one the very few with a minor difference: the memcpy() version
+// was one instruction longer.
+//
+// Conclusion: At least in case of GCC and Clang, byte-by-byte code is
+// the best choice for strict-align archs to do unaligned access.
+//
+// See also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111502
+//
+// Thanks to <https://godbolt.org/> it was easy to test different compilers.
+// The following is for little endian targets:
+/*
+#include <stdint.h>
+#include <string.h>
+
+uint32_t bytes16(const uint8_t *b)
+{
+    return (uint32_t)b[0]
+        | ((uint32_t)b[1] << 8);
+}
+
+uint32_t copy16(const uint8_t *b)
+{
+    uint16_t v;
+    memcpy(&v, b, sizeof(v));
+    return v;
+}
+
+uint32_t bytes32(const uint8_t *b)
+{
+    return (uint32_t)b[0]
+        | ((uint32_t)b[1] << 8)
+        | ((uint32_t)b[2] << 16)
+        | ((uint32_t)b[3] << 24);
+}
+
+uint32_t copy32(const uint8_t *b)
+{
+    uint32_t v;
+    memcpy(&v, b, sizeof(v));
+    return v;
+}
+
+void wbytes16(uint8_t *b, uint16_t v)
+{
+    b[0] = (uint8_t)v;
+    b[1] = (uint8_t)(v >> 8);
+}
+
+void wcopy16(uint8_t *b, uint16_t v)
+{
+    memcpy(b, &v, sizeof(v));
+}
+
+void wbytes32(uint8_t *b, uint32_t v)
+{
+    b[0] = (uint8_t)v;
+    b[1] = (uint8_t)(v >> 8);
+    b[2] = (uint8_t)(v >> 16);
+    b[3] = (uint8_t)(v >> 24);
+}
+
+void wcopy32(uint8_t *b, uint32_t v)
+{
+    memcpy(b, &v, sizeof(v));
+}
+*/
+
+
+#ifdef TUKLIB_FAST_UNALIGNED_ACCESS
 
 static inline uint16_t
 read16ne(const uint8_t *buf)
 {
-#if defined(TUKLIB_FAST_UNALIGNED_ACCESS) \
-		&& defined(TUKLIB_USE_UNSAFE_TYPE_PUNNING)
+#ifdef TUKLIB_USE_UNSAFE_TYPE_PUNNING
 	return *(const uint16_t *)buf;
 #else
 	uint16_t num;
@@ -221,8 +333,7 @@ read16ne(const uint8_t *buf)
 static inline uint32_t
 read32ne(const uint8_t *buf)
 {
-#if defined(TUKLIB_FAST_UNALIGNED_ACCESS) \
-		&& defined(TUKLIB_USE_UNSAFE_TYPE_PUNNING)
+#ifdef TUKLIB_USE_UNSAFE_TYPE_PUNNING
 	return *(const uint32_t *)buf;
 #else
 	uint32_t num;
@@ -235,8 +346,7 @@ read32ne(const uint8_t *buf)
 static inline uint64_t
 read64ne(const uint8_t *buf)
 {
-#if defined(TUKLIB_FAST_UNALIGNED_ACCESS) \
-		&& defined(TUKLIB_USE_UNSAFE_TYPE_PUNNING)
+#ifdef TUKLIB_USE_UNSAFE_TYPE_PUNNING
 	return *(const uint64_t *)buf;
 #else
 	uint64_t num;
@@ -249,8 +359,7 @@ read64ne(const uint8_t *buf)
 static inline void
 write16ne(uint8_t *buf, uint16_t num)
 {
-#if defined(TUKLIB_FAST_UNALIGNED_ACCESS) \
-		&& defined(TUKLIB_USE_UNSAFE_TYPE_PUNNING)
+#ifdef TUKLIB_USE_UNSAFE_TYPE_PUNNING
 	*(uint16_t *)buf = num;
 #else
 	memcpy(buf, &num, sizeof(num));
@@ -262,8 +371,7 @@ write16ne(uint8_t *buf, uint16_t num)
 static inline void
 write32ne(uint8_t *buf, uint32_t num)
 {
-#if defined(TUKLIB_FAST_UNALIGNED_ACCESS) \
-		&& defined(TUKLIB_USE_UNSAFE_TYPE_PUNNING)
+#ifdef TUKLIB_USE_UNSAFE_TYPE_PUNNING
 	*(uint32_t *)buf = num;
 #else
 	memcpy(buf, &num, sizeof(num));
@@ -275,8 +383,7 @@ write32ne(uint8_t *buf, uint32_t num)
 static inline void
 write64ne(uint8_t *buf, uint64_t num)
 {
-#if defined(TUKLIB_FAST_UNALIGNED_ACCESS) \
-		&& defined(TUKLIB_USE_UNSAFE_TYPE_PUNNING)
+#ifdef TUKLIB_USE_UNSAFE_TYPE_PUNNING
 	*(uint64_t *)buf = num;
 #else
 	memcpy(buf, &num, sizeof(num));
@@ -288,68 +395,122 @@ write64ne(uint8_t *buf, uint64_t num)
 static inline uint16_t
 read16be(const uint8_t *buf)
 {
-#if defined(WORDS_BIGENDIAN) || defined(TUKLIB_FAST_UNALIGNED_ACCESS)
 	uint16_t num = read16ne(buf);
 	return conv16be(num);
-#else
-	uint16_t num = ((uint16_t)buf[0] << 8) | (uint16_t)buf[1];
-	return num;
-#endif
 }
 
 
 static inline uint16_t
 read16le(const uint8_t *buf)
 {
-#if !defined(WORDS_BIGENDIAN) || defined(TUKLIB_FAST_UNALIGNED_ACCESS)
 	uint16_t num = read16ne(buf);
 	return conv16le(num);
-#else
-	uint16_t num = ((uint16_t)buf[0]) | ((uint16_t)buf[1] << 8);
-	return num;
-#endif
 }
 
 
 static inline uint32_t
 read32be(const uint8_t *buf)
 {
-#if defined(WORDS_BIGENDIAN) || defined(TUKLIB_FAST_UNALIGNED_ACCESS)
 	uint32_t num = read32ne(buf);
 	return conv32be(num);
+}
+
+
+static inline uint32_t
+read32le(const uint8_t *buf)
+{
+	uint32_t num = read32ne(buf);
+	return conv32le(num);
+}
+
+
+static inline uint64_t
+read64be(const uint8_t *buf)
+{
+	uint64_t num = read64ne(buf);
+	return conv64be(num);
+}
+
+
+static inline uint64_t
+read64le(const uint8_t *buf)
+{
+	uint64_t num = read64ne(buf);
+	return conv64le(num);
+}
+
+
+// NOTE: Possible byte swapping must be done in a macro to allow the compiler
+// to optimize byte swapping of constants when using glibc's or *BSD's
+// byte swapping macros. The actual write is done in an inline function
+// to make type checking of the buf pointer possible.
+#define write16be(buf, num) write16ne(buf, conv16be(num))
+#define write32be(buf, num) write32ne(buf, conv32be(num))
+#define write64be(buf, num) write64ne(buf, conv64be(num))
+#define write16le(buf, num) write16ne(buf, conv16le(num))
+#define write32le(buf, num) write32ne(buf, conv32le(num))
+#define write64le(buf, num) write64ne(buf, conv64le(num))
+
 #else
+
+#ifdef WORDS_BIGENDIAN
+#	define read16ne read16be
+#	define read32ne read32be
+#	define read64ne read64be
+#	define write16ne write16be
+#	define write32ne write32be
+#	define write64ne write64be
+#else
+#	define read16ne read16le
+#	define read32ne read32le
+#	define read64ne read64le
+#	define write16ne write16le
+#	define write32ne write32le
+#	define write64ne write64le
+#endif
+
+
+static inline uint16_t
+read16be(const uint8_t *buf)
+{
+	uint16_t num = ((uint16_t)buf[0] << 8) | (uint16_t)buf[1];
+	return num;
+}
+
+
+static inline uint16_t
+read16le(const uint8_t *buf)
+{
+	uint16_t num = ((uint16_t)buf[0]) | ((uint16_t)buf[1] << 8);
+	return num;
+}
+
+
+static inline uint32_t
+read32be(const uint8_t *buf)
+{
 	uint32_t num = (uint32_t)buf[0] << 24;
 	num |= (uint32_t)buf[1] << 16;
 	num |= (uint32_t)buf[2] << 8;
 	num |= (uint32_t)buf[3];
 	return num;
-#endif
 }
 
 
 static inline uint32_t
 read32le(const uint8_t *buf)
 {
-#if !defined(WORDS_BIGENDIAN) || defined(TUKLIB_FAST_UNALIGNED_ACCESS)
-	uint32_t num = read32ne(buf);
-	return conv32le(num);
-#else
 	uint32_t num = (uint32_t)buf[0];
 	num |= (uint32_t)buf[1] << 8;
 	num |= (uint32_t)buf[2] << 16;
 	num |= (uint32_t)buf[3] << 24;
 	return num;
-#endif
 }
 
 
 static inline uint64_t
 read64be(const uint8_t *buf)
 {
-#if defined(WORDS_BIGENDIAN) || defined(TUKLIB_FAST_UNALIGNED_ACCESS)
-	uint64_t num = read64ne(buf);
-	return conv64be(num);
-#else
 	uint64_t num = (uint64_t)buf[0] << 56;
 	num |= (uint64_t)buf[1] << 48;
 	num |= (uint64_t)buf[2] << 40;
@@ -359,17 +520,12 @@ read64be(const uint8_t *buf)
 	num |= (uint64_t)buf[6] << 8;
 	num |= (uint64_t)buf[7];
 	return num;
-#endif
 }
 
 
 static inline uint64_t
 read64le(const uint8_t *buf)
 {
-#if !defined(WORDS_BIGENDIAN) || defined(TUKLIB_FAST_UNALIGNED_ACCESS)
-	uint64_t num = read64ne(buf);
-	return conv64le(num);
-#else
 	uint64_t num = (uint64_t)buf[0];
 	num |= (uint64_t)buf[1] << 8;
 	num |= (uint64_t)buf[2] << 16;
@@ -379,28 +535,9 @@ read64le(const uint8_t *buf)
 	num |= (uint64_t)buf[6] << 48;
 	num |= (uint64_t)buf[7] << 56;
 	return num;
-#endif
 }
 
 
-// NOTE: Possible byte swapping must be done in a macro to allow the compiler
-// to optimize byte swapping of constants when using glibc's or *BSD's
-// byte swapping macros. The actual write is done in an inline function
-// to make type checking of the buf pointer possible.
-#if defined(WORDS_BIGENDIAN) || defined(TUKLIB_FAST_UNALIGNED_ACCESS)
-#	define write16be(buf, num) write16ne(buf, conv16be(num))
-#	define write32be(buf, num) write32ne(buf, conv32be(num))
-#	define write64be(buf, num) write64ne(buf, conv64be(num))
-#endif
-
-#if !defined(WORDS_BIGENDIAN) || defined(TUKLIB_FAST_UNALIGNED_ACCESS)
-#	define write16le(buf, num) write16ne(buf, conv16le(num))
-#	define write32le(buf, num) write32ne(buf, conv32le(num))
-#	define write64le(buf, num) write64ne(buf, conv64le(num))
-#endif
-
-
-#ifndef write16be
 static inline void
 write16be(uint8_t *buf, uint16_t num)
 {
@@ -408,10 +545,8 @@ write16be(uint8_t *buf, uint16_t num)
 	buf[1] = (uint8_t)num;
 	return;
 }
-#endif
 
 
-#ifndef write16le
 static inline void
 write16le(uint8_t *buf, uint16_t num)
 {
@@ -419,10 +554,8 @@ write16le(uint8_t *buf, uint16_t num)
 	buf[1] = (uint8_t)(num >> 8);
 	return;
 }
-#endif
 
 
-#ifndef write32be
 static inline void
 write32be(uint8_t *buf, uint32_t num)
 {
@@ -432,10 +565,8 @@ write32be(uint8_t *buf, uint32_t num)
 	buf[3] = (uint8_t)num;
 	return;
 }
-#endif
 
 
-#ifndef write32le
 static inline void
 write32le(uint8_t *buf, uint32_t num)
 {
@@ -445,6 +576,37 @@ write32le(uint8_t *buf, uint32_t num)
 	buf[3] = (uint8_t)(num >> 24);
 	return;
 }
+
+
+static inline void
+write64be(uint8_t *buf, uint64_t num)
+{
+	buf[0] = (uint8_t)(num >> 56);
+	buf[1] = (uint8_t)(num >> 48);
+	buf[2] = (uint8_t)(num >> 40);
+	buf[3] = (uint8_t)(num >> 32);
+	buf[4] = (uint8_t)(num >> 24);
+	buf[5] = (uint8_t)(num >> 16);
+	buf[6] = (uint8_t)(num >> 8);
+	buf[7] = (uint8_t)num;
+	return;
+}
+
+
+static inline void
+write64le(uint8_t *buf, uint64_t num)
+{
+	buf[0] = (uint8_t)num;
+	buf[1] = (uint8_t)(num >> 8);
+	buf[2] = (uint8_t)(num >> 16);
+	buf[3] = (uint8_t)(num >> 24);
+	buf[4] = (uint8_t)(num >> 32);
+	buf[5] = (uint8_t)(num >> 40);
+	buf[6] = (uint8_t)(num >> 48);
+	buf[7] = (uint8_t)(num >> 56);
+	return;
+}
+
 #endif
 
 
@@ -630,7 +792,7 @@ bsr32(uint32_t n)
 #if defined(__INTEL_COMPILER)
 	return _bit_scan_reverse(n);
 
-#elif TUKLIB_GNUC_REQ(3, 4) && UINT_MAX == UINT32_MAX
+#elif (TUKLIB_GNUC_REQ(3, 4) || defined(__clang__)) && UINT_MAX == UINT32_MAX
 	// GCC >= 3.4 has __builtin_clz(), which gives good results on
 	// multiple architectures. On x86, __builtin_clz() ^ 31U becomes
 	// either plain BSR (so the XOR gets optimized away) or LZCNT and
@@ -684,7 +846,7 @@ clz32(uint32_t n)
 #if defined(__INTEL_COMPILER)
 	return _bit_scan_reverse(n) ^ 31U;
 
-#elif TUKLIB_GNUC_REQ(3, 4) && UINT_MAX == UINT32_MAX
+#elif (TUKLIB_GNUC_REQ(3, 4) || defined(__clang__)) && UINT_MAX == UINT32_MAX
 	return (uint32_t)__builtin_clz(n);
 
 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
@@ -736,7 +898,7 @@ ctz32(uint32_t n)
 #if defined(__INTEL_COMPILER)
 	return _bit_scan_forward(n);
 
-#elif TUKLIB_GNUC_REQ(3, 4) && UINT_MAX >= UINT32_MAX
+#elif (TUKLIB_GNUC_REQ(3, 4) || defined(__clang__)) && UINT_MAX >= UINT32_MAX
 	return (uint32_t)__builtin_ctz(n);
 
 #elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))

+ 18 - 0
contrib/libs/lzma/common/tuklib_physmem.c

@@ -73,6 +73,17 @@
 #endif
 
 
+// With GCC >= 8.1 with -Wextra and Clang >= 13 with -Wcast-function-type
+// will warn about the Windows-specific code.
+#if defined(__has_warning)
+#	if __has_warning("-Wcast-function-type")
+#		define CAN_DISABLE_WCAST_FUNCTION_TYPE 1
+#	endif
+#elif TUKLIB_GNUC_REQ(8,1)
+#	define CAN_DISABLE_WCAST_FUNCTION_TYPE 1
+#endif
+
+
 extern uint64_t
 tuklib_physmem(void)
 {
@@ -87,8 +98,15 @@ tuklib_physmem(void)
 		HMODULE kernel32 = GetModuleHandle(TEXT("kernel32.dll"));
 		if (kernel32 != NULL) {
 			typedef BOOL (WINAPI *gmse_type)(LPMEMORYSTATUSEX);
+#ifdef CAN_DISABLE_WCAST_FUNCTION_TYPE
+#	pragma GCC diagnostic push
+#	pragma GCC diagnostic ignored "-Wcast-function-type"
+#endif
 			gmse_type gmse = (gmse_type)GetProcAddress(
 					kernel32, "GlobalMemoryStatusEx");
+#ifdef CAN_DISABLE_WCAST_FUNCTION_TYPE
+#	pragma GCC diagnostic pop
+#endif
 			if (gmse != NULL) {
 				MEMORYSTATUSEX meminfo;
 				meminfo.dwLength = sizeof(meminfo);

+ 9 - 8
contrib/libs/lzma/liblzma/api/lzma.h

@@ -1,22 +1,23 @@
 /**
  * \file        api/lzma.h
  * \brief       The public API of liblzma data compression library
+ * \mainpage
  *
  * liblzma is a public domain general-purpose data compression library with
  * a zlib-like API. The native file format is .xz, but also the old .lzma
  * format and raw (no headers) streams are supported. Multiple compression
  * algorithms (filters) are supported. Currently LZMA2 is the primary filter.
  *
- * liblzma is part of XZ Utils <http://tukaani.org/xz/>. XZ Utils includes
- * a gzip-like command line tool named xz and some other tools. XZ Utils
- * is developed and maintained by Lasse Collin.
+ * liblzma is part of XZ Utils <https://xz.tukaani.org/xz-utils/>. XZ Utils
+ * includes a gzip-like command line tool named xz and some other tools.
+ * XZ Utils is developed and maintained by Lasse Collin and Jia Tan.
  *
  * Major parts of liblzma are based on Igor Pavlov's public domain LZMA SDK
- * <http://7-zip.org/sdk.html>.
+ * <https://7-zip.org/sdk.html>.
  *
  * The SHA-256 implementation is based on the public domain code found from
- * 7-Zip <http://7-zip.org/>, which has a modified version of the public
- * domain SHA-256 code found from Crypto++ <http://www.cryptopp.com/>.
+ * 7-Zip <https://7-zip.org/>, which has a modified version of the public
+ * domain SHA-256 code found from Crypto++ <https://www.cryptopp.com/>.
  * The SHA-256 code in Crypto++ was written by Kevin Springle and Wei Dai.
  */
 
@@ -181,11 +182,11 @@
  * against static liblzma on them, don't worry about LZMA_API_STATIC. That
  * is, most developers will never need to use LZMA_API_STATIC.
  *
- * The GCC variants are a special case on Windows (Cygwin and MinGW).
+ * The GCC variants are a special case on Windows (Cygwin and MinGW-w64).
  * We rely on GCC doing the right thing with its auto-import feature,
  * and thus don't use __declspec(dllimport). This way developers don't
  * need to worry about LZMA_API_STATIC. Also the calling convention is
- * omitted on Cygwin but not on MinGW.
+ * omitted on Cygwin but not on MinGW-w64.
  */
 #ifndef LZMA_API_IMPORT
 #	if !defined(LZMA_API_STATIC) && defined(_WIN32) && !defined(__GNUC__)

Some files were not shown because too many files changed in this diff