public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: "Martin Liška" <mliska@suse.cz>
Cc: elfutils-devel@sourceware.org
Subject: Re: ☠ Buildbot (GNU Toolchain): elfutils-try-debian-armhf - failed compile (failure) (users/marxin/try-zstd-support-v2)
Date: Thu, 22 Dec 2022 19:17:34 +0100	[thread overview]
Message-ID: <020b98b2e8b5b4e8d1c2cb9e44cf6edd5edfb94f.camel@klomp.org> (raw)
In-Reply-To: <57b03cfc-a50a-026d-bbaf-fd05b85fa1f8@suse.cz>

[-- Attachment #1: Type: text/plain, Size: 1554 bytes --]

On Thu, 2022-12-22 at 10:09 +0100, Martin Liška wrote:
> On 12/22/22 00:38, Mark Wielaard wrote:
> > Hi Martin,
> > 
> > On Wed, Dec 21, 2022 at 07:29:19PM +0100, Martin Liška wrote:
> > > > What goes wrong is that this debian old stable arm setup has
> > > > libzstd
> > > > containing a ZSTD_compressStream2 symbol...
> > > > 
> > > >     40: 0000d349   264 FUNC    GLOBAL DEFAULT   11
> > > > ZSTD_compressStream2
> > > > 
> > > > But the zstd.h header doesn't expose it...
> > > 
> > > Yeah, that's their way of how to move an API from "staging" into
> > > a stable state.
> > > It was changed in:
> > > https://github.com/facebook/zstd/commit/d7d89513d6a21
> > > 
> > > and so it's present in zstd since 1.4.0. Can we somehow specify
> > > library version
> > > in configure.ac?
> 
> Hi Mark.
> 
> > It isn't as nice, but since there seems to be a pkgconfig
> > libzstd.pc
> > you could use PKG_CHECK_MODULES. See for example how we check for
> > libcurl.
> 
> I can see it, however, it not easily addable to eu_ZIPLIB function :/
> I must confess,
> this autoconf machinery is always something that makes me crazy :)
> 
> Do you have an elegant way how to handle it?

Maybe we should simply split it from the "decompress" support. Trying
to make eu_ZIPLIB handle it means we also suddenly require a newer
libzstd for the simpler dwfl zstd file decompression support.

So lets keep the "normal" zstd detection in place and add something
like the attached (on top of your latest patch).

Cheers,

Mark

[-- Attachment #2: Type: text/x-patch, Size: 4132 bytes --]

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 <string.h>])
@@ -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
 

      reply	other threads:[~2022-12-22 18:17 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20221221111547.74C4C385B50B@sourceware.org>
2022-12-21 14:20 ` Martin Liška
2022-12-21 14:42   ` Mark Wielaard
2022-12-21 14:54     ` Frank Ch. Eigler
2022-12-21 15:21     ` Mark Wielaard
2022-12-21 18:29       ` Martin Liška
2022-12-21 23:38         ` Mark Wielaard
2022-12-22  9:09           ` Martin Liška
2022-12-22 18:17             ` Mark Wielaard [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=020b98b2e8b5b4e8d1c2cb9e44cf6edd5edfb94f.camel@klomp.org \
    --to=mark@klomp.org \
    --cc=elfutils-devel@sourceware.org \
    --cc=mliska@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).