Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zlib-ng 2025-02-10 (860e4cff) #5261

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
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
10 changes: 7 additions & 3 deletions Modules/ThirdParty/ZLIB/src/itkzlib-ng/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ if(NOT WITH_RUNTIME_CPU_DETECTION)
message(STATUS "WARNING: Microsoft Visual Studio does not support compile time detection of CPU features for \"/arch\" before \"AVX\"")
# Workaround for MSVC. By default MSVC does not define the __SSE*__ macros.
# Fix it if AVX is enabled.
set(CMAKE_REQUIRED_FLAGS "${NATIVEFLAG}")
set(CMAKE_REQUIRED_FLAGS "${NATIVEFLAG} ${ZNOLTOFLAG}")
check_c_source_compiles(
"#ifndef __AVX__
# error \"AVX is not enabled.\"
Expand Down Expand Up @@ -491,6 +491,7 @@ endif()
#
# Check for __builtin_assume_aligned(x,n) support in the compiler
#
set(CMAKE_REQUIRED_FLAGS ${ZNOLTOFLAG})
check_c_source_compiles(
"char *test(char *buffer) {
char *abuffer = __builtin_assume_aligned(buffer,64);
Expand All @@ -503,10 +504,12 @@ check_c_source_compiles(
if(HAVE_BUILTIN_ASSUME_ALIGNED)
add_definitions(-DHAVE_BUILTIN_ASSUME_ALIGNED)
endif()
set(CMAKE_REQUIRED_FLAGS)

#
# check for __builtin_ctz() support in the compiler
#
set(CMAKE_REQUIRED_FLAGS ${ZNOLTOFLAG})
check_c_source_compiles(
"int main(void) {
unsigned int zero = 0;
Expand All @@ -519,10 +522,12 @@ check_c_source_compiles(
if(HAVE_BUILTIN_CTZ)
add_definitions(-DHAVE_BUILTIN_CTZ)
endif()
set(CMAKE_REQUIRED_FLAGS)

#
# check for __builtin_ctzll() support in the compiler
#
set(CMAKE_REQUIRED_FLAGS ${ZNOLTOFLAG})
check_c_source_compiles(
"int main(void) {
unsigned int zero = 0;
Expand All @@ -535,6 +540,7 @@ check_c_source_compiles(
if(HAVE_BUILTIN_CTZLL)
add_definitions(-DHAVE_BUILTIN_CTZLL)
endif()
set(CMAKE_REQUIRED_FLAGS)

#
# check for ptrdiff_t support
Expand Down Expand Up @@ -1192,8 +1198,6 @@ foreach(ZLIB_INSTALL_LIBRARY ${ZLIB_INSTALL_LIBRARIES})
target_include_directories(${ZLIB_INSTALL_LIBRARY} PUBLIC
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}$<SEMICOLON>${CMAKE_CURRENT_SOURCE_DIR}>"
"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>")
target_include_directories(${ZLIB_INSTALL_LIBRARY} PRIVATE "${ARCHDIR}")
target_include_directories(${ZLIB_INSTALL_LIBRARY} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/arch/generic")
endforeach()

if(FALSE) # ITK change: don't give custom name to the library
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
#include "crc32_constants.h"
#include "crc32_braid_tbl.h"

#if defined (__clang__)
#include "fallback_builtins.h"
#endif
#include "power_intrins.h"

#define MAX_SIZE 32768
#define VMX_ALIGN 16
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
* For conditions of distribution and use, see copyright notice in zlib.h
*/

#ifndef POWER_BUILTINS_H
#define POWER_BUILTINS_H
#ifndef POWER_INTRINS_H
#define POWER_INTRINS_H

#if defined (__clang__)
/*
* These stubs fix clang incompatibilities with GCC builtins.
*/
Expand All @@ -29,3 +30,5 @@ vec_ld(int __a, const __vector unsigned long long* __b) {
}

#endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int Z_INTERNAL is_kernel_version_greater_or_equal_to_6_5() {
return 0;
}

if (major > 6 || major == 6 && minor >= 5)
if (major > 6 || (major == 6 && minor >= 5))
return 1;
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@

#ifdef S390_CRC32_VX
uint32_t crc32_s390_vx(uint32_t crc, const uint8_t *buf, size_t len);

#ifdef __clang__
# if ((__clang_major__ == 18) || (__clang_major__ == 19 && (__clang_minor__ < 1 || (__clang_minor__ == 1 && __clang_patchlevel__ < 2))))
# error CRC32-VX optimizations are broken due to compiler bug in Clang versions: 18.0.0 <= clang_version < 19.1.2. \
Either disable the zlib-ng CRC32-VX optimization, or switch to another compiler/compiler version.
# endif
#endif

#endif

#ifdef DISABLE_RUNTIME_CPU_DETECTION
# if defined(S390_CRC32_VX) && defined(__zarch__) && __ARCH__ >= 11 && defined(__VX__)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ if [ $REG_TOKEN = "null" ]; then
fi

# (Re-)register the runner.
./config.sh remove --token "$REG_TOKEN" || true
set -x
./config.sh \
--url "https://github.com/$REPO" \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,43 +1,54 @@
#!/usr/bin/bash
set -ex

if [ ! -f /etc/actions-runner ]; then
echo "Error: /etc/actions-runner env file not found"
exit 1
fi
TMPDIR="$(mktemp -d)"

# Use local file if run interactively, otherwise wget the current one.
if [ -t 0 ] ; then
if [ ! -f actions-runner.Dockerfile ]; then
echo "Error: actions-runner.Dockerfile not found"
exit 1
fi
DOCKERFILE=actions-runner.Dockerfile
if [ -f actions-runner.Dockerfile ]; then
MODE=1
cp actions-runner.Dockerfile actions-runner entrypoint $TMPDIR
cd $TMPDIR
else
DOCKERFILE="$(mktemp)"
wget https://raw.githubusercontent.com/zlib-ng/zlib-ng/refs/heads/develop/arch/s390/self-hosted-builder/actions-runner.Dockerfile -O $DOCKERFILE
MODE=2
cd $TMPDIR
wget https://raw.githubusercontent.com/zlib-ng/zlib-ng/refs/heads/develop/arch/s390/self-hosted-builder/actions-runner.Dockerfile
wget https://raw.githubusercontent.com/zlib-ng/zlib-ng/refs/heads/develop/arch/s390/self-hosted-builder/actions-runner
wget https://raw.githubusercontent.com/zlib-ng/zlib-ng/refs/heads/develop/arch/s390/self-hosted-builder/entrypoint
fi

# Copy rpms needed to workaround VX compiler bug, ref #1852
mkdir clang
cp /clang-19/*.rpm clang/

# Stop service
systemctl stop actions-runner
systemctl stop actions-runner || true

# Delete container
podman container rm gaplib-actions-runner
# Delete old container
podman container rm gaplib-actions-runner || true

# Delete image
podman image rm localhost/zlib-ng/actions-runner
# Delete old image
podman image rm localhost/zlib-ng/actions-runner || true

# Build image
podman build --squash -f $DOCKERFILE --tag zlib-ng/actions-runner .
# Build new image
podman build --squash -f actions-runner.Dockerfile --tag zlib-ng/actions-runner . 2>&1 | tee /var/log/actions-runner-build.log

# Create container
podman create --replace --name=gaplib-actions-runner --env-file=/etc/actions-runner --init --volume=actions-runner-temp:/home/actions-runner zlib-ng/actions-runner
# Create new container
podman create --replace --name=gaplib-actions-runner --env-file=/etc/actions-runner --init \
--volume=actions-runner-temp:/home/actions-runner zlib-ng/actions-runner 2>&1 | tee -a /var/log/actions-runner-build.log

# Start service
systemctl start actions-runner
systemctl start actions-runner || true

# Cleanup
podman image prune -af || true

# Clean up tempfile
if [ ! -t 0 ] ; then
rm $DOCKERFILE
echo "Deleted dockerfile $DOCKERFILE"
if [ "$MODE" == "2" ] ; then
cd $TMPDIR
rm actions-runner.Dockerfile
rm actions-runner
rm entrypoint
rm -rf clang
cd ..
rmdir $TMPDIR
echo "Deleted tempfiles."
fi
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,23 @@ RUN tar -xf /tmp/runner/_package/*.tar.gz -C /home/actions-runner && \

#VOLUME /home/actions-runner

# Workaround: Install custom clang version to avoid compiler bug, ref #1852
RUN mkdir /tmp/clang

COPY clang/*.rpm /tmp/clang

RUN dnf -y upgrade /tmp/clang/*.rpm && \
rm -rf /tmp/clang

# Cleanup
RUN rm -rf /tmp/runner /var/cache/dnf/* /tmp/runner.patch /tmp/global.json && \
dnf clean all

USER actions-runner

# Scripts.
COPY entrypoint /usr/bin/
COPY actions-runner /usr/bin/
COPY --chmod=555 entrypoint /usr/bin/
COPY --chmod=555 actions-runner /usr/bin/
WORKDIR /home/actions-runner
ENTRYPOINT ["/usr/bin/entrypoint"]
CMD ["/usr/bin/actions-runner"]
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ static inline void chunkmemset_8(uint8_t *from, chunk_t *chunk) {
}

static inline void chunkmemset_16(uint8_t *from, chunk_t *chunk) {
/* See explanation in chunkset_avx512.c */
#if defined(_MSC_VER) && _MSC_VER <= 1900
halfchunk_t half = _mm_loadu_si128((__m128i*)from);
*chunk = _mm256_inserti128_si256(_mm256_castsi128_si256(half), half, 1);
#else
*chunk = _mm256_broadcastsi128_si256(_mm_loadu_si128((__m128i*)from));
#endif
}

static inline void loadchunk(uint8_t const *s, chunk_t *chunk) {
Expand Down
10 changes: 10 additions & 0 deletions Modules/ThirdParty/ZLIB/src/itkzlib-ng/arch/x86/chunkset_avx512.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,17 @@ static inline void chunkmemset_8(uint8_t *from, chunk_t *chunk) {
}

static inline void chunkmemset_16(uint8_t *from, chunk_t *chunk) {
/* Unfortunately there seems to be a compiler bug in Visual Studio 2015 where
* the load is dumped to the stack with an aligned move for this memory-register
* broadcast. The vbroadcasti128 instruction is 2 fewer cycles and this dump to
* stack doesn't exist if compiled with optimizations. For the sake of working
* properly in a debugger, let's take the 2 cycle penalty */
#if defined(_MSC_VER) && _MSC_VER <= 1900
halfchunk_t half = _mm_loadu_si128((__m128i*)from);
*chunk = _mm256_inserti128_si256(_mm256_castsi128_si256(half), half, 1);
#else
*chunk = _mm256_broadcastsi128_si256(_mm_loadu_si128((__m128i*)from));
#endif
}

static inline void loadchunk(uint8_t const *s, chunk_t *chunk) {
Expand Down
4 changes: 2 additions & 2 deletions Modules/ThirdParty/ZLIB/src/itkzlib-ng/infback.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ int32_t Z_EXPORT PREFIX(inflateBackInit_)(PREFIX3(stream) *strm, int32_t windowB
do { \
PULL(); \
have--; \
hold += ((unsigned)(*next++) << bits); \
hold += ((uint64_t)(*next++) << bits); \
bits += 8; \
} while (0)

Expand Down Expand Up @@ -154,7 +154,7 @@ int32_t Z_EXPORT PREFIX(inflateBack)(PREFIX3(stream) *strm, in_func in, void *in
z_const unsigned char *next; /* next input */
unsigned char *put; /* next output */
unsigned have, left; /* available input and output */
uint32_t hold; /* bit buffer */
uint64_t hold; /* bit buffer */
unsigned bits; /* bits in bit buffer */
unsigned copy; /* number of stored or match bytes to copy */
unsigned char *from; /* where to copy match bytes from */
Expand Down
12 changes: 6 additions & 6 deletions Modules/ThirdParty/ZLIB/src/itkzlib-ng/inflate.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ int32_t Z_EXPORT PREFIX(inflatePrime)(PREFIX3(stream) *strm, int32_t bits, int32
if (bits > 16 || state->bits + (unsigned int)bits > 32)
return Z_STREAM_ERROR;
value &= (1L << bits) - 1;
state->hold += (unsigned)value << state->bits;
state->hold += (uint64_t)value << state->bits;
state->bits += (unsigned int)bits;
return Z_OK;
}
Expand Down Expand Up @@ -387,7 +387,7 @@ static void updatewindow(PREFIX3(stream) *strm, const uint8_t *end, uint32_t len
do { \
if (have == 0) goto inf_leave; \
have--; \
hold += ((unsigned)(*next++) << bits); \
hold += ((uint64_t)(*next++) << bits); \
bits += 8; \
} while (0)

Expand Down Expand Up @@ -479,7 +479,7 @@ int32_t Z_EXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int32_t flush) {
unsigned char *put; /* next output */
unsigned char *from; /* where to copy match bytes from */
unsigned have, left; /* available input and output */
uint32_t hold; /* bit buffer */
uint64_t hold; /* bit buffer */
unsigned bits; /* bits in bit buffer */
uint32_t in, out; /* save starting available input and output */
unsigned copy; /* number of stored or match bytes to copy */
Expand Down Expand Up @@ -577,7 +577,7 @@ int32_t Z_EXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int32_t flush) {
case TIME:
NEEDBITS(32);
if (state->head != NULL)
state->head->time = hold;
state->head->time = (unsigned)(hold);
if ((state->flags & 0x0200) && (state->wrap & 4))
CRC4(state->check, hold);
INITBITS();
Expand Down Expand Up @@ -704,7 +704,7 @@ int32_t Z_EXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int32_t flush) {
#endif
case DICTID:
NEEDBITS(32);
strm->adler = state->check = ZSWAP32(hold);
strm->adler = state->check = ZSWAP32((unsigned)hold);
INITBITS();
state->mode = DICT;
Z_FALLTHROUGH;
Expand Down Expand Up @@ -1128,7 +1128,7 @@ int32_t Z_EXPORT PREFIX(inflate)(PREFIX3(stream) *strm, int32_t flush) {
#ifdef GUNZIP
state->flags ? hold :
#endif
ZSWAP32(hold)) != state->check) {
ZSWAP32((unsigned)hold)) != state->check) {
SET_BAD("incorrect data check");
break;
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/ThirdParty/ZLIB/src/itkzlib-ng/inflate.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ struct ALIGNED_(64) inflate_state {
uint32_t chunksize; /* size of memory copying chunk */

/* bit accumulator */
uint32_t hold; /* input bit accumulator */
uint64_t hold; /* input bit accumulator */
unsigned bits; /* number of bits in "in" */
/* fixed and dynamic code tables */
unsigned lenbits; /* index bits for lencode */
Expand All @@ -141,7 +141,7 @@ struct ALIGNED_(64) inflate_state {
code *next; /* next available space in codes[] */

#if defined(_M_IX86) || defined(_M_ARM)
uint32_t padding[2];
uint32_t padding[1];
#endif
struct crc32_fold_s ALIGNED_(16) crc_fold;

Expand Down
8 changes: 6 additions & 2 deletions Modules/ThirdParty/ZLIB/src/itkzlib-ng/trees_emit.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,21 @@ extern Z_INTERNAL const int base_dist[D_CODES];
/* If not enough room in bi_buf, use (valid) bits from bi_buf and
* (64 - bi_valid) bits from value, leaving (width - (64-bi_valid))
* unused bits in value.
*
* NOTE: Static analyzers can't evaluate value of total_bits, so we
* also need to make sure bi_valid is within acceptable range,
* otherwise the shifts will overflow.
*/
#define send_bits(s, t_val, t_len, bi_buf, bi_valid) {\
uint64_t val = (uint64_t)t_val;\
uint32_t len = (uint32_t)t_len;\
uint32_t total_bits = bi_valid + len;\
send_bits_trace(s, val, len);\
sent_bits_add(s, len);\
if (total_bits < BIT_BUF_SIZE) {\
if (total_bits < BIT_BUF_SIZE && bi_valid < BIT_BUF_SIZE) {\
bi_buf |= val << bi_valid;\
bi_valid = total_bits;\
} else if (bi_valid == BIT_BUF_SIZE) {\
} else if (bi_valid >= BIT_BUF_SIZE) {\
put_uint64(s, bi_buf);\
bi_buf = val;\
bi_valid = len;\
Expand Down
6 changes: 3 additions & 3 deletions Modules/ThirdParty/ZLIB/src/itkzlib-ng/zlib.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
extern "C" {
#endif

#define ZLIBNG_VERSION "2.2.3"
#define ZLIBNG_VERNUM 0x020203F0L /* MMNNRRSM: major minor revision status modified */
#define ZLIBNG_VERSION "2.2.4"
#define ZLIBNG_VERNUM 0x020204F0L /* MMNNRRSM: major minor revision status modified */
#define ZLIBNG_VER_MAJOR 2
#define ZLIBNG_VER_MINOR 2
#define ZLIBNG_VER_REVISION 3
#define ZLIBNG_VER_REVISION 4
#define ZLIBNG_VER_STATUS F /* 0=devel, 1-E=beta, F=Release (DEPRECATED) */
#define ZLIBNG_VER_STATUSH 0xF /* Hex values: 0=devel, 1-E=beta, F=Release */
#define ZLIBNG_VER_MODIFIED 0 /* non-zero if modified externally from zlib-ng */
Expand Down
2 changes: 1 addition & 1 deletion Modules/ThirdParty/ZLIB/src/itkzlib-ng/zutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ z_const char * const PREFIX(z_errmsg)[10] = {
};

const char PREFIX3(vstring)[] =
" zlib-ng 2.2.3";
" zlib-ng 2.2.4";

#ifdef ZLIB_COMPAT
const char * Z_EXPORT zlibVersion(void) {
Expand Down