Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions deps/zstd/lib/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ cxx_library(
srcs=glob(['decompress/zstd*.c']),
deps=[
':common',
':legacy',
],
)

Expand All @@ -47,6 +46,14 @@ cxx_library(
deps=[':common'],
)

# Decoders for formats older than v0.8. Not a dependency of :decompress,
# because ZSTD_LEGACY_SUPPORT is 0 (see .buckconfig), which makes them
# unreachable.
# Enabling legacy formats means two edits, which only make sense together :
# raise the level in .buckconfig, AND add ':legacy' to :decompress deps.
# Raising the level alone fails to link, which is easy to notice. Adding the
# dep alone is silent : these decoders get compiled back in, while
# ZSTD_isLegacy() remains compiled out, so legacy frames are still rejected.
cxx_library(
name='legacy',
header_namespace='',
Expand All @@ -56,9 +63,6 @@ cxx_library(
]),
srcs=glob(['legacy/*.c']),
deps=[':common'],
exported_preprocessor_flags=[
'-DZSTD_LEGACY_SUPPORT=4',
],
)

cxx_library(
Expand All @@ -79,6 +83,7 @@ cxx_library(
header_namespace='',
visibility=['PUBLIC'],
exported_headers=subdir_glob([
('common', 'bmi2.h'),
('common', 'compiler.h'),
]),
)
Expand Down Expand Up @@ -132,7 +137,7 @@ cxx_library(
exported_headers=[
'zstd_errors.h',
'common/error_private.h',
]
],
srcs=['common/error_private.c'],
)

Expand Down
18 changes: 9 additions & 9 deletions deps/zstd/lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ $(ZSTD_STATICLIB): $(ZSTD_STATICLIB_OBJ)
$(AR) $(ARFLAGS) $@ $^

libzstd.a: $(ZSTD_STATICLIB)
cp -f $< $@
$(CP) $< $@

endif

Expand Down Expand Up @@ -166,13 +166,13 @@ $(ZSTD_DYNLIB): $(ZSTD_DYNLIB_OBJ)
$(if $(filter -DZSTD_MULTITHREAD,$(CPPFLAGS)),\
@echo compiling multi-threaded dynamic library $(LIBVER),\
@echo compiling single-threaded dynamic library $(LIBVER))
$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
$(CC) $(FLAGS) $^ $(SONAME_FLAGS) -o $@
@echo creating versioned links
ln -sf $@ libzstd.$(SHARED_EXT_MAJOR)
ln -sf $@ libzstd.$(SHARED_EXT)
$(LN) -sf $@ libzstd.$(SHARED_EXT_MAJOR)
$(LN) -sf $@ libzstd.$(SHARED_EXT)

$(LIBZSTD): $(ZSTD_DYNLIB)
cp -f $< $@
$(CP) $< $@

endif # ifndef BUILD_DIR
endif # if windows
Expand Down Expand Up @@ -255,7 +255,7 @@ libzstd-nomt: $(ZSTD_NOMT_FILES)
echo "Error: Found zstdmt in list."; \
exit 1; \
fi
$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
$(CC) $(FLAGS) $^ $(SONAME_FLAGS) -o $@

.PHONY: clean
clean:
Expand All @@ -268,7 +268,7 @@ clean:
#-----------------------------------------------------------------------------
# make install is validated only for below listed environments
#-----------------------------------------------------------------------------
ifneq (,$(filter Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku AIX MSYS_NT% CYGWIN_NT%,$(UNAME)))
ifneq (,$(filter $(INSTALL_OS_LIST),$(UNAME)))

lib: libzstd.pc

Expand Down Expand Up @@ -363,8 +363,8 @@ install-shared:
[ -e $(DESTDIR)$(LIBDIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR)/
@echo Installing shared library
$(INSTALL_PROGRAM) $(LIBZSTD) $(DESTDIR)$(LIBDIR)
ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
$(LN) -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
$(LN) -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)

.PHONY: install-includes
install-includes:
Expand Down
30 changes: 25 additions & 5 deletions deps/zstd/lib/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,30 @@ in order to make it easier to select or exclude features.

#### Building

`Makefile` script is provided, supporting [Makefile conventions](https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html#Makefile-Conventions),
A `Makefile` script is provided, supporting [Makefile conventions](https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html#Makefile-Conventions),
including commands variables, staged install, directory variables and standard targets.
- `make` : generates both static and dynamic libraries
- `make install` : install libraries and headers in target system directories
- `make install` : install libraries, headers and pkg-config in local system directories

`libzstd` default scope is pretty large, including compression, decompression, dictionary builder,
and support for decoding legacy formats >= v0.5.0.
`libzstd` default scope includes compression, decompression, and dictionary builder.
Note: starting v1.6.0, support for decoding legacy formats is disabled by default.
See _modular build_ below to learn how to enable it.
The scope can be reduced on demand (see paragraph _modular build_).

#### Multiarch Support

For multiarch systems (like Debian/Ubuntu), libraries should be installed to architecture-specific directories.
When creating packages for such systems, use the `LIBDIR` variable to specify the correct multiarch path:

```bash
# For x86_64 systems on Ubuntu/Debian:
make install PREFIX=/usr LIBDIR=/usr/lib/x86_64-linux-gnu

# For ARM64 systems on Ubuntu/Debian:
make install PREFIX=/usr LIBDIR=/usr/lib/aarch64-linux-gnu
```

This will not only install the files in the correct directories, but also generate the correct paths for `pkg-config`.

#### Multithreading support

Expand Down Expand Up @@ -85,7 +100,7 @@ The file structure is designed to make this selection manually achievable for an
Specifying a number limits versions supported to that version onward.
For example, `ZSTD_LEGACY_SUPPORT=2` means : "support legacy formats >= v0.2.0".
Conversely, `ZSTD_LEGACY_SUPPORT=0` means "do __not__ support legacy formats".
By default, this build macro is set as `ZSTD_LEGACY_SUPPORT=5`.
By default, this build macro is set as `ZSTD_LEGACY_SUPPORT=0` (disabled).
Decoding supported legacy format is a transparent capability triggered within decompression functions.
It's also allowed to invoke legacy API directly, exposed in `lib/legacy/zstd_legacy.h`.
Each version does also provide its own set of advanced API.
Expand Down Expand Up @@ -193,6 +208,11 @@ The file structure is designed to make this selection manually achievable for an
and assembly decoding loops. You may want to use this macro if these loops are
slower on your platform.

- The macro `ZDICT_QSORT` can enforce selection of a specific sorting variant,
which is useful when autodetection fails, for example with older versions of `musl`.
For this scenario, it can be set as `ZDICT_QSORT=ZDICT_QSORT_C90`.
Other selectable suffixes are `_GNU`, `_APPLE`, `_MSVC` and `_C11`.

#### Windows : using MinGW+MSYS to create DLL

DLL can be created using MinGW+MSYS with the `make libzstd` command.
Expand Down
8 changes: 6 additions & 2 deletions deps/zstd/lib/common/allocations.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ MEM_STATIC void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
MEM_STATIC void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
{
if (customMem.customAlloc) {
/* calloc implemented as malloc+memset;
* not as efficient as calloc, but next best guess for custom malloc */
/* calloc implemented as malloc+memset */
void* const ptr = customMem.customAlloc(customMem.opaque, size);

if (ptr == NULL) {
return NULL;
}

ZSTD_memset(ptr, 0, size);
return ptr;
}
Expand Down
2 changes: 1 addition & 1 deletion deps/zstd/lib/common/bits.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ MEM_STATIC unsigned ZSTD_countTrailingZeros32_fallback(U32 val)
30, 22, 20, 15, 25, 17, 4, 8,
31, 27, 13, 23, 21, 19, 16, 7,
26, 12, 18, 6, 11, 5, 10, 9};
return DeBruijnBytePos[((U32) ((val & -(S32) val) * 0x077CB531U)) >> 27];
return DeBruijnBytePos[((U32) ((val & (0-val)) * 0x077CB531U)) >> 27];
}
}

Expand Down
6 changes: 3 additions & 3 deletions deps/zstd/lib/common/bitstream.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ typedef enum { BIT_DStream_unfinished = 0, /* fully refilled */
} BIT_DStream_status; /* result of BIT_reloadDStream() */

MEM_STATIC size_t BIT_initDStream(BIT_DStream_t* bitD, const void* srcBuffer, size_t srcSize);
MEM_STATIC BitContainerType BIT_readBits(BIT_DStream_t* bitD, unsigned nbBits);
MEM_STATIC BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD);
FORCE_INLINE_TEMPLATE BitContainerType BIT_readBits(BIT_DStream_t* bitD, unsigned nbBits);
FORCE_INLINE_TEMPLATE BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD);
MEM_STATIC unsigned BIT_endOfDStream(const BIT_DStream_t* bitD);


Expand Down Expand Up @@ -432,7 +432,7 @@ FORCE_INLINE_TEMPLATE BIT_DStream_status BIT_reloadDStream(BIT_DStream_t* bitD)
/* start < ptr < limitPtr => cautious update */
{ U32 nbBytes = bitD->bitsConsumed >> 3;
BIT_DStream_status result = BIT_DStream_unfinished;
if (bitD->ptr - nbBytes < bitD->start) {
if (nbBytes > (size_t)(bitD->ptr - bitD->start)) {
nbBytes = (U32)(bitD->ptr - bitD->start); /* ptr > start */
result = BIT_DStream_endOfBuffer;
}
Expand Down
40 changes: 40 additions & 0 deletions deps/zstd/lib/common/bmi2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
* All rights reserved.
*
* This source code is licensed under both the BSD-style license (found in the
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
* in the COPYING file in the root directory of this source tree).
* You may select, at your option, one of the above-listed licenses.
*/

#ifndef ZSTD_BMI2_H
#define ZSTD_BMI2_H

#include "portability_macros.h"

#if defined(ZSTD_USE_KERNEL_CPU_FEATURES)
# include <asm/cpufeature.h>
#endif

/*
* Select between the BMI2 and default implementations at the final dispatch
* site. Integrations may ignore the caller-provided hint and consult their own
* CPU-feature policy instead.
*
* ZSTD_USE_BMI2() may not evaluate its argument. ZSTD_SET_BMI2() may not
* evaluate its value argument, which avoids executing the userspace CPUID
* probe when the integration supplies the dispatch decision.
*/
#if !DYNAMIC_BMI2
# define ZSTD_USE_BMI2(bmi2) 0
# define ZSTD_SET_BMI2(state, value) do { } while (0)
#elif defined(ZSTD_USE_KERNEL_CPU_FEATURES)
# define ZSTD_USE_BMI2(bmi2) cpu_feature_enabled(X86_FEATURE_BMI2)
# define ZSTD_SET_BMI2(state, value) do { (state) = 0; } while (0)
#else
# define ZSTD_USE_BMI2(bmi2) (bmi2)
# define ZSTD_SET_BMI2(state, value) do { (state) = (value); } while (0)
#endif

#endif /* ZSTD_BMI2_H */
48 changes: 37 additions & 11 deletions deps/zstd/lib/common/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
#endif

/* UNUSED_ATTR tells the compiler it is okay if the function is unused. */
#if defined(__GNUC__) || defined(__IAR_SYSTEMS_ICC__)
#if defined(__GNUC__) || defined(__clang__) || defined(__IAR_SYSTEMS_ICC__) /* clang-cl defines __clang__ but not __GNUC__ */
# define UNUSED_ATTR __attribute__((unused))
#else
# define UNUSED_ATTR
Expand Down Expand Up @@ -98,9 +98,9 @@
#elif defined(__IAR_SYSTEMS_ICC__)
# define MEM_STATIC static inline UNUSED_ATTR
#elif defined (__cplusplus) || (defined (__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) /* C99 */)
# define MEM_STATIC static inline
# define MEM_STATIC static inline UNUSED_ATTR
#elif defined(_MSC_VER)
# define MEM_STATIC static __inline
# define MEM_STATIC static __inline UNUSED_ATTR
#else
# define MEM_STATIC static /* this version may generate warnings for unused static functions; disable the relevant warning */
#endif
Expand Down Expand Up @@ -132,6 +132,10 @@
#define BMI2_TARGET_ATTRIBUTE TARGET_ATTRIBUTE("lzcnt,bmi,bmi2")

/* prefetch
* PREFETCH_L1(ptr) / PREFETCH_L2(ptr) take a `const void*`.
* `ptr` is only used as an address hint: it may point anywhere,
* including invalid or out-of-bounds memory, and is never accessed.
* Each variant below must therefore accept a `const void*` argument.
* can be disabled, by declaring NO_PREFETCH build macro */
#if defined(NO_PREFETCH)
# define PREFETCH_L1(ptr) do { (void)(ptr); } while (0) /* disabled */
Expand All @@ -145,8 +149,12 @@
# define PREFETCH_L1(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 3 /* locality */)
# define PREFETCH_L2(ptr) __builtin_prefetch((ptr), 0 /* rw==read */, 2 /* locality */)
# elif defined(__aarch64__)
# define PREFETCH_L1(ptr) do { __asm__ __volatile__("prfm pldl1keep, %0" ::"Q"(*(ptr))); } while (0)
# define PREFETCH_L2(ptr) do { __asm__ __volatile__("prfm pldl2keep, %0" ::"Q"(*(ptr))); } while (0)
/* The "Q" operand needs an lvalue, so cast to `const char*` before
* dereferencing: dereferencing a `const void*` is ill-formed in C
* (-Wvoid-ptr-dereference). The `prfm` instruction is only a hint and
* never faults, whatever the address. */
# define PREFETCH_L1(ptr) do { __asm__ __volatile__("prfm pldl1keep, %0" ::"Q"(*(const char*)(ptr))); } while (0)
# define PREFETCH_L2(ptr) do { __asm__ __volatile__("prfm pldl2keep, %0" ::"Q"(*(const char*)(ptr))); } while (0)
# else
# define PREFETCH_L1(ptr) do { (void)(ptr); } while (0) /* disabled */
# define PREFETCH_L2(ptr) do { (void)(ptr); } while (0) /* disabled */
Expand Down Expand Up @@ -218,6 +226,18 @@
# if defined(__ARM_NEON) || defined(_M_ARM64)
# define ZSTD_ARCH_ARM_NEON
# endif
# if defined(__ARM_FEATURE_SVE)
# define ZSTD_ARCH_ARM_SVE
# endif
# if defined(__ARM_FEATURE_SVE2)
# define ZSTD_ARCH_ARM_SVE2
# endif
# if defined(__riscv) && defined(__riscv_vector)
# if ((defined(__GNUC__) && !defined(__clang__) && __GNUC__ >= 14) || \
(defined(__clang__) && __clang_major__ >= 19))
#define ZSTD_ARCH_RISCV_RVV
# endif
#endif
#
# if defined(ZSTD_ARCH_X86_AVX2)
# include <immintrin.h>
Expand All @@ -227,6 +247,12 @@
# elif defined(ZSTD_ARCH_ARM_NEON)
# include <arm_neon.h>
# endif
# if defined(ZSTD_ARCH_ARM_SVE) || defined(ZSTD_ARCH_ARM_SVE2)
# include <arm_sve.h>
# endif
# if defined(ZSTD_ARCH_RISCV_RVV)
# include <riscv_vector.h>
# endif
#endif

/* C-language Attributes are added in C23. */
Expand Down Expand Up @@ -357,9 +383,9 @@ ptrdiff_t ZSTD_wrappedPtrDiff(unsigned char const* lhs, unsigned char const* rhs
*/
MEM_STATIC
ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
unsigned char const* ZSTD_wrappedPtrAdd(unsigned char const* ptr, ptrdiff_t add)
const void* ZSTD_wrappedPtrAdd(const void* ptr, ptrdiff_t add)
{
return ptr + add;
return (const char*)ptr + add;
}

/**
Expand All @@ -370,9 +396,9 @@ unsigned char const* ZSTD_wrappedPtrAdd(unsigned char const* ptr, ptrdiff_t add)
*/
MEM_STATIC
ZSTD_ALLOW_POINTER_OVERFLOW_ATTR
unsigned char const* ZSTD_wrappedPtrSub(unsigned char const* ptr, ptrdiff_t sub)
const void* ZSTD_wrappedPtrSub(const void* ptr, ptrdiff_t sub)
{
return ptr - sub;
return (const char*)ptr - sub;
}

/**
Expand All @@ -382,9 +408,9 @@ unsigned char const* ZSTD_wrappedPtrSub(unsigned char const* ptr, ptrdiff_t sub)
* @returns `ptr + add` except it defines `NULL + 0 == NULL`.
*/
MEM_STATIC
unsigned char* ZSTD_maybeNullPtrAdd(unsigned char* ptr, ptrdiff_t add)
void* ZSTD_maybeNullPtrAdd(void* ptr, ptrdiff_t add)
{
return add > 0 ? ptr + add : ptr;
return add > 0 ? (char*)ptr + add : ptr;
}

/* Issue #3240 reports an ASAN failure on an llvm-mingw build. Out of an
Expand Down
Loading
Loading