diff --git a/configure.ac b/configure.ac index ef16f79e..b2597f8b 100644 --- a/configure.ac +++ b/configure.ac @@ -417,7 +417,7 @@ AC_SUBST([BZ2_LIB]) eu_ZIPLIB(lzma,LZMA,lzma,lzma_auto_decoder,[LZMA (xz)]) AS_IF([test "x$with_lzma" = xyes], [LIBLZMA="liblzma"], [LIBLZMA=""]) AC_SUBST([LIBLZMA]) -eu_ZIPLIB(zstd,ZSTD,zstd,ZSTD_compressStream2,[ZSTD (zst)]) +eu_ZIPLIB(zstd,ZSTD,zstd,ZSTD_decompress,[ZSTD (zst)]) AS_IF([test "x$with_zstd" = xyes], [LIBZSTD="libzstd"], [LIBLZSTD=""]) AC_SUBST([LIBZSTD]) zstd_LIBS="$LIBS" @@ -426,6 +426,16 @@ zip_LIBS="$LIBS" LIBS="$save_LIBS" AC_SUBST([zip_LIBS]) +dnl zstd compression support requires libzstd 1.4.0+ +AS_IF([test "x$with_zstd" = xyes], [ + PKG_PROG_PKG_CONFIG + PKG_CHECK_MODULES([ZSTD_COMPRESS],[libzstd >= 1.4.0], + [with_zstd_compress="yes"],[with_zstd_compress="no"])], + [with_zstd_compress="no"]) +AM_CONDITIONAL(USE_ZSTD_COMPRESS, test "x$with_zstd_compress" = "xyes") +AS_IF([test "x$with_zstd_compress" = "xyes"], + [AC_DEFINE([USE_ZSTD_COMPRESS], [1], [zstd compression support])]) + AC_CHECK_DECLS([memrchr, rawmemchr],[],[], [#define _GNU_SOURCE #include ]) @@ -831,6 +841,7 @@ AC_MSG_NOTICE([ bzip2 support : ${with_bzlib} lzma/xz support : ${with_lzma} zstd support : ${with_zstd} + zstd compression support : ${with_zstd_compress} libstdc++ demangle support : ${enable_demangler} File textrel check : ${enable_textrelcheck} Symbol versioning : ${enable_symbol_versioning} diff --git a/libelf/elf_compress.c b/libelf/elf_compress.c index deb585b7..5a9d3da1 100644 --- a/libelf/elf_compress.c +++ b/libelf/elf_compress.c @@ -170,7 +170,7 @@ __libelf_compress_zlib (Elf_Scn *scn, size_t hsize, int ei_data, return out_buf; } -#ifdef USE_ZSTD +#ifdef USE_ZSTD_COMPRESS /* Cleanup and return result. Don't leak memory. */ static void * do_zstd_cleanup (void *result, ZSTD_CCtx * const cctx, void *out_buf, @@ -333,7 +333,7 @@ __libelf_compress (Elf_Scn *scn, size_t hsize, int ei_data, if (use_zstd) { -#ifdef USE_ZSTD +#ifdef USE_ZSTD_COMPRESS return __libelf_compress_zstd (scn, hsize, ei_data, orig_size, orig_addralign, new_size, force, data, next_data, out_buf, out_size, @@ -406,8 +406,7 @@ __libelf_decompress_zlib (void *buf_in, size_t size_in, size_t size_out) } #ifdef USE_ZSTD -void * -internal_function +static void * __libelf_decompress_zstd (void *buf_in, size_t size_in, size_t size_out) { /* Malloc might return NULL when requesting zero size. This is highly @@ -425,7 +424,7 @@ __libelf_decompress_zstd (void *buf_in, size_t size_in, size_t size_out) if (ZSTD_isError (ret)) { free (buf_out); - __libelf_seterrno (ELF_E_UNKNOWN_COMPRESSION_TYPE); + __libelf_seterrno (ELF_E_DECOMPRESS_ERROR); return NULL; } else @@ -444,7 +443,7 @@ __libelf_decompress (int chtype, void *buf_in, size_t size_in, size_t size_out) #ifdef USE_ZSTD return __libelf_decompress_zstd (buf_in, size_in, size_out); #else - __libelf_seterrno (ELF_E_DECOMPRESS_ERROR); + __libelf_seterrno (ELF_E_UNKNOWN_COMPRESSION_TYPE); return NULL; #endif } diff --git a/src/elfcompress.c b/src/elfcompress.c index bfdac2b4..1f32331c 100644 --- a/src/elfcompress.c +++ b/src/elfcompress.c @@ -230,7 +230,8 @@ compress_section (Elf_Scn *scn, size_t orig_size, const char *name, res = elf_compress (scn, dchtype, flags); if (res < 0) - error (0, 0, "Couldn't decompress section [%zd] %s: %s", + error (0, 0, "Couldn't %s section [%zd] %s: %s", + compress ? "compress" : "decompress", ndx, name, elf_errmsg (-1)); else { diff --git a/tests/Makefile.am b/tests/Makefile.am index cb70229e..71b19601 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -218,6 +218,9 @@ endif if HAVE_ZSTD TESTS += run-readelf-compressed-zstd.sh +endif + +if USE_ZSTD_COMPRESS export ELFUTILS_ZSTD = 1 endif