From 8ff47f3df0cdc79af358912eee4c96b863a5054b Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 21 Feb 2025 09:57:55 -0800 Subject: [PATCH 1/3] added musl compilation test in CI --- .github/workflows/dev-short-tests.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/dev-short-tests.yml b/.github/workflows/dev-short-tests.yml index 7df105532..56a46a744 100644 --- a/.github/workflows/dev-short-tests.yml +++ b/.github/workflows/dev-short-tests.yml @@ -684,6 +684,17 @@ jobs: make -C programs zstd-pgo ./programs/zstd -b + musl-build: + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # tag=v4.1.1 + - name: Install musl-tools + run: | + sudo apt install -y musl-tools + - name: Compile the project with musl-gcc + run: | + CC=musl-gcc make -j V=1 zstd + intel-cet-compatibility: runs-on: ubuntu-latest steps: From ebfa660b8297170fb0742ac8959aa64940292853 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 21 Feb 2025 11:36:30 -0800 Subject: [PATCH 2/3] introduce ZSTD_USE_C90_QSORT --- .github/workflows/dev-short-tests.yml | 2 +- lib/dictBuilder/cover.c | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/dev-short-tests.yml b/.github/workflows/dev-short-tests.yml index 56a46a744..56401db0a 100644 --- a/.github/workflows/dev-short-tests.yml +++ b/.github/workflows/dev-short-tests.yml @@ -693,7 +693,7 @@ jobs: sudo apt install -y musl-tools - name: Compile the project with musl-gcc run: | - CC=musl-gcc make -j V=1 zstd + CC=musl-gcc CPPFLAGS=-DZSTD_USE_C90_QSORT make -j V=1 zstd intel-cet-compatibility: runs-on: ubuntu-latest diff --git a/lib/dictBuilder/cover.c b/lib/dictBuilder/cover.c index 2ef33c73e..29820d7e1 100644 --- a/lib/dictBuilder/cover.c +++ b/lib/dictBuilder/cover.c @@ -24,9 +24,9 @@ /* qsort_r is an extension. */ #if defined(__linux) || defined(__linux__) || defined(linux) || defined(__gnu_linux__) || \ defined(__CYGWIN__) || defined(__MSYS__) -#if !defined(_GNU_SOURCE) && !defined(__ANDROID__) /* NDK doesn't ship qsort_r(). */ -#define _GNU_SOURCE -#endif +# if !defined(_GNU_SOURCE) && !defined(__ANDROID__) /* NDK doesn't ship qsort_r(). */ +# define _GNU_SOURCE +# endif #endif #include /* fprintf */ @@ -241,8 +241,9 @@ typedef struct { unsigned d; } COVER_ctx_t; -#if !defined(_GNU_SOURCE) && !defined(__APPLE__) && !defined(_MSC_VER) -/* C90 only offers qsort() that needs a global context. */ +#if defined(ZSTD_USE_C90_QSORT) \ + || (!defined(_GNU_SOURCE) && !defined(__APPLE__) && !defined(_MSC_VER)) +/* Use global context for non-reentrant sort functions */ static COVER_ctx_t *g_coverCtx = NULL; #endif @@ -328,7 +329,7 @@ static void stableSort(COVER_ctx_t *ctx) { qsort_r(ctx->suffix, ctx->suffixSize, sizeof(U32), ctx, (ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp)); -#elif defined(_GNU_SOURCE) +#elif defined(_GNU_SOURCE) && !defined(ZSTD_USE_C90_QSORT) qsort_r(ctx->suffix, ctx->suffixSize, sizeof(U32), (ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp), ctx); @@ -342,7 +343,7 @@ static void stableSort(COVER_ctx_t *ctx) { (ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp)); #else /* C90 fallback.*/ g_coverCtx = ctx; - /* TODO(cavalcanti): implement a reentrant qsort() when is not available. */ + /* TODO(cavalcanti): implement a reentrant qsort() when _r is not available. */ qsort(ctx->suffix, ctx->suffixSize, sizeof(U32), (ctx->d <= 8 ? &COVER_strict_cmp8 : &COVER_strict_cmp)); #endif From fd5498a1793f26b3a6995009449e1216a8c90dd0 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 21 Feb 2025 12:48:26 -0800 Subject: [PATCH 3/3] document ZSTD_USE_C90_QSORT --- lib/README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/README.md b/lib/README.md index b37f5fc4f..9df516c5a 100644 --- a/lib/README.md +++ b/lib/README.md @@ -193,6 +193,10 @@ 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 `ZSTD_USE_C90_QSORT` forces usage of C90's `qsort()`, + for situations where the code cannot determine that `qsort_r()` is not supported, + such as, for example, older versions of `musl`. + #### Windows : using MinGW+MSYS to create DLL DLL can be created using MinGW+MSYS with the `make libzstd` command.