Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH v2] configure: Support --with-zstd=PATH
@ 2026-09-28  5:30 Torbjörn SVENSSON
  2026-09-29  2:00 ` Simon Marchi
  0 siblings, 1 reply; 7+ messages in thread
From: Torbjörn SVENSSON @ 2026-09-28  5:30 UTC (permalink / raw)
  To: binutils, gdb-patches; +Cc: Torbjörn SVENSSON

Hi,

V1 can be found here:
https://sourceware.org/pipermail/binutils/2026-September/151687.html

Changes since v1:
- Added missed changes in binutils/Makefile.am and binutils/Makefile.in
- Added support for dynamic version of zstd in path


Ok for trunk?

Kind regards,
Torbjörn

--

Allow --with-zstd to specify an installation prefix.  Use the headers
and static library under that prefix, and reject it if it does not
provide zstd 1.4.0 or newer.

Regenerate the affected configure scripts.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
---
 bfd/configure        | 90 +++++++++++++++++++++++++++++++++++++++-----
 binutils/Makefile.am | 14 +++----
 binutils/Makefile.in | 16 ++++----
 binutils/configure   | 90 +++++++++++++++++++++++++++++++++++++++-----
 config/zstd.m4       | 63 ++++++++++++++++++++++++++-----
 gas/configure        | 90 +++++++++++++++++++++++++++++++++++++++-----
 gdb/configure        | 90 +++++++++++++++++++++++++++++++++++++++-----
 gold/configure       | 90 +++++++++++++++++++++++++++++++++++++++-----
 ld/configure         | 90 +++++++++++++++++++++++++++++++++++++++-----
 9 files changed, 555 insertions(+), 78 deletions(-)

diff --git a/bfd/configure b/bfd/configure
index a4326160c57..53ec433c0fb 100755
--- a/bfd/configure
+++ b/bfd/configure
@@ -1540,8 +1540,8 @@ Optional Packages:
   --without-libintl-prefix     don't search for libintl in includedir and libdir
   --with-libintl-type=TYPE     type of library to search for (auto/static/shared)
   --with-system-zlib      use installed libz
-  --with-zstd             support zstd compressed debug sections
-                          (default=auto)
+  --with-zstd[=PATH]      support zstd compressed debug sections, optionally
+                          using zstd installed under PATH (default=auto)
 
 Some influential environment variables:
   CC          C compiler command
@@ -15423,7 +15423,11 @@ else
 fi
 
 
-if test "$with_zstd" != no; then :
+case $with_zstd in #(
+  no) :
+     ;; #(
+  yes|auto) :
+
 
 pkg_failed=no
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libzstd >= 1.4.0" >&5
@@ -15508,17 +15512,21 @@ fi
 	echo "$ZSTD_PKG_ERRORS" >&5
 
 
-    if test "$with_zstd" = yes; then
-      as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
-    fi
+      if test "$with_zstd" = yes; then :
+
+        as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
+
+fi
 
 elif test $pkg_failed = untried; then
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 
-    if test "$with_zstd" = yes; then
-      as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
-    fi
+      if test "$with_zstd" = yes; then :
+
+        as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
+
+fi
 
 else
 	ZSTD_CFLAGS=$pkg_cv_ZSTD_CFLAGS
@@ -15531,8 +15539,72 @@ $as_echo "#define HAVE_ZSTD 1" >>confdefs.h
 
 
 fi
+   ;; #(
+  *) :
+
+    ZSTD_CFLAGS="-I$with_zstd/include"
+    ZSTD_LIBS="-L$with_zstd/lib -lzstd"
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for zstd >= 1.4.0 in $with_zstd" >&5
+$as_echo_n "checking for zstd >= 1.4.0 in $with_zstd... " >&6; }
+
+    zstd_save_CPPFLAGS=$CPPFLAGS
+    zstd_save_LIBS=$LIBS
+    CPPFLAGS="$CPPFLAGS $ZSTD_CFLAGS"
+    LIBS="$ZSTD_LIBS $LIBS"
+
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <zstd.h>
+#if ZSTD_VERSION_NUMBER < 10400
+# error zstd 1.4.0 or later is required
+#endif
+
+int
+main ()
+{
+
+          (void) ZSTD_compress(0, 0, 0, 0, 1);
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  have_zstd=yes
+else
+  have_zstd=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+
+    CPPFLAGS=$zstd_save_CPPFLAGS
+    LIBS=$zstd_save_LIBS
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_zstd" >&5
+$as_echo "$have_zstd" >&6; }
+
+    if test "$have_zstd" = yes; then :
+
+      pkg_cv_ZSTD_CFLAGS=$ZSTD_CFLAGS
+      pkg_cv_ZSTD_LIBS=$ZSTD_LIBS
+
+$as_echo "#define HAVE_ZSTD 1" >>confdefs.h
+
+
+else
+
+      as_fn_error $? "zstd >= 1.4.0 was not found under $with_zstd" "$LINENO" 5
 
 fi
+   ;; #(
+  *) :
+     ;;
+esac
+
+
+
 
 
 save_CFLAGS="$CFLAGS"
diff --git a/binutils/Makefile.am b/binutils/Makefile.am
index edcbc67bde4..0582d9fb826 100644
--- a/binutils/Makefile.am
+++ b/binutils/Makefile.am
@@ -251,7 +251,7 @@ dllwrap_DEPENDENCIES =   $(LIBINTL_DEP) $(LIBIBERTY)
 bfdtest1_DEPENDENCIES =  $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
 bfdtest2_DEPENDENCIES =  $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
 
-LDADD = $(BFDLIB) $(LIBIBERTY) $(LIBINTL)
+LDADD = $(BFDLIB) $(LIBIBERTY) $(LIBINTL) $(ZSTD_LIBS)
 
 size_SOURCES = size.c $(BULIBS)
 
@@ -271,7 +271,7 @@ nm_new_SOURCES = nm.c demanguse.c $(BULIBS)
 
 objdump_SOURCES = objdump.c dwarf.c prdbg.c demanguse.c $(DEBUG_SRCS) $(BULIBS) $(ELFLIBS)
 EXTRA_objdump_SOURCES = od-elf32_avr.c od-macho.c od-xcoff.c od-pe.c
-objdump_LDADD = $(OBJDUMP_PRIVATE_OFILES) $(OPCODES) $(LIBCTF) $(BFDLIB) $(LIBIBERTY) $(LIBINTL) $(DEBUGINFOD_LIBS) $(LIBSFRAME)
+objdump_LDADD = $(OBJDUMP_PRIVATE_OFILES) $(OPCODES) $(LIBCTF) $(BFDLIB) $(LIBIBERTY) $(LIBINTL) $(ZSTD_LIBS) $(DEBUGINFOD_LIBS) $(LIBSFRAME)
 
 objdump.@OBJEXT@:objdump.c
 if am__fastdepCC
@@ -290,11 +290,11 @@ cxxfilt_SOURCES = cxxfilt.c $(BULIBS)
 ar_SOURCES = arparse.y arlex.l not-ranlib.c arsup.c rename.c binemul.c \
 	emul_$(EMULATION).c $(BULIBS)
 EXTRA_ar_SOURCES = $(CFILES)
-ar_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL)
+ar_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(ZSTD_LIBS)
 
 ranlib_SOURCES = arparse.y arlex.l is-ranlib.c arsup.c rename.c binemul.c \
 	emul_$(EMULATION).c $(BULIBS)
-ranlib_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL)
+ranlib_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(ZSTD_LIBS)
 
 addr2line_SOURCES = addr2line.c $(BULIBS)
 
@@ -485,7 +485,7 @@ srconv_SOURCES = srconv.c coffgrok.c $(BULIBS)
 srconv.@OBJEXT@: sysroff.c
 
 dlltool_SOURCES = dlltool.c defparse.y deflex.l $(BULIBS)
-dlltool_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL)
+dlltool_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(ZSTD_LIBS)
 
 dlltool.@OBJEXT@:
 if am__fastdepCC
@@ -518,11 +518,11 @@ sysdump.@OBJEXT@: sysroff.c
 
 windres_SOURCES = windres.c resrc.c rescoff.c resbin.c rcparse.y rclex.c \
 	winduni.c resres.c $(BULIBS)
-windres_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(LIBICONV)
+windres_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(LIBICONV) $(ZSTD_LIBS)
 
 windmc_SOURCES = windmc.c mcparse.y mclex.c \
 	winduni.c $(BULIBS)
-windmc_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(LIBICONV)
+windmc_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(LIBICONV) $(ZSTD_LIBS)
 
 dllwrap_SOURCES = dllwrap.c version.c
 dllwrap_LDADD = $(LIBIBERTY) $(LIBINTL)
diff --git a/binutils/Makefile.in b/binutils/Makefile.in
index fff4565e302..69f6a1e128c 100644
--- a/binutils/Makefile.in
+++ b/binutils/Makefile.in
@@ -282,7 +282,7 @@ am__dirstamp = $(am__leading_dot)dirstamp
 testsuite_gentestdlls_OBJECTS = testsuite/gentestdlls.$(OBJEXT)
 testsuite_gentestdlls_LDADD = $(LDADD)
 testsuite_gentestdlls_DEPENDENCIES = $(BFDLIB) $(LIBIBERTY) \
-	$(am__DEPENDENCIES_1)
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
 am_windmc_OBJECTS = windmc.$(OBJEXT) mcparse.$(OBJEXT) mclex.$(OBJEXT) \
 	winduni.$(OBJEXT) $(am__objects_1)
 windmc_OBJECTS = $(am_windmc_OBJECTS)
@@ -794,7 +794,7 @@ elfedit_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY)
 dllwrap_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY)
 bfdtest1_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
 bfdtest2_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-LDADD = $(BFDLIB) $(LIBIBERTY) $(LIBINTL)
+LDADD = $(BFDLIB) $(LIBIBERTY) $(LIBINTL) $(ZSTD_LIBS)
 size_SOURCES = size.c $(BULIBS)
 objcopy_SOURCES = not-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS)
 strings_SOURCES = strings.c $(BULIBS)
@@ -806,31 +806,31 @@ strip_new_SOURCES = is-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS)
 nm_new_SOURCES = nm.c demanguse.c $(BULIBS)
 objdump_SOURCES = objdump.c dwarf.c prdbg.c demanguse.c $(DEBUG_SRCS) $(BULIBS) $(ELFLIBS)
 EXTRA_objdump_SOURCES = od-elf32_avr.c od-macho.c od-xcoff.c od-pe.c
-objdump_LDADD = $(OBJDUMP_PRIVATE_OFILES) $(OPCODES) $(LIBCTF) $(BFDLIB) $(LIBIBERTY) $(LIBINTL) $(DEBUGINFOD_LIBS) $(LIBSFRAME)
+objdump_LDADD = $(OBJDUMP_PRIVATE_OFILES) $(OPCODES) $(LIBCTF) $(BFDLIB) $(LIBIBERTY) $(LIBINTL) $(ZSTD_LIBS) $(DEBUGINFOD_LIBS) $(LIBSFRAME)
 cxxfilt_SOURCES = cxxfilt.c $(BULIBS)
 ar_SOURCES = arparse.y arlex.l not-ranlib.c arsup.c rename.c binemul.c \
 	emul_$(EMULATION).c $(BULIBS)
 
 EXTRA_ar_SOURCES = $(CFILES)
-ar_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL)
+ar_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(ZSTD_LIBS)
 ranlib_SOURCES = arparse.y arlex.l is-ranlib.c arsup.c rename.c binemul.c \
 	emul_$(EMULATION).c $(BULIBS)
 
-ranlib_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL)
+ranlib_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(ZSTD_LIBS)
 addr2line_SOURCES = addr2line.c $(BULIBS)
 srconv_SOURCES = srconv.c coffgrok.c $(BULIBS)
 dlltool_SOURCES = dlltool.c defparse.y deflex.l $(BULIBS)
-dlltool_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL)
+dlltool_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(ZSTD_LIBS)
 coffdump_SOURCES = coffdump.c coffgrok.c $(BULIBS)
 sysdump_SOURCES = sysdump.c $(BULIBS)
 windres_SOURCES = windres.c resrc.c rescoff.c resbin.c rcparse.y rclex.c \
 	winduni.c resres.c $(BULIBS)
 
-windres_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(LIBICONV)
+windres_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(LIBICONV) $(ZSTD_LIBS)
 windmc_SOURCES = windmc.c mcparse.y mclex.c \
 	winduni.c $(BULIBS)
 
-windmc_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(LIBICONV)
+windmc_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(LIBICONV) $(ZSTD_LIBS)
 dllwrap_SOURCES = dllwrap.c version.c
 dllwrap_LDADD = $(LIBIBERTY) $(LIBINTL)
 EXTRA_DIST = arparse.c arparse.h arlex.c sysinfo.c sysinfo.h \
diff --git a/binutils/configure b/binutils/configure
index ea19d09749f..14b28d0df20 100755
--- a/binutils/configure
+++ b/binutils/configure
@@ -1540,8 +1540,8 @@ Optional Packages:
   --without-libintl-prefix     don't search for libintl in includedir and libdir
   --with-libintl-type=TYPE     type of library to search for (auto/static/shared)
   --with-system-zlib      use installed libz
-  --with-zstd             support zstd compressed debug sections
-                          (default=auto)
+  --with-zstd[=PATH]      support zstd compressed debug sections, optionally
+                          using zstd installed under PATH (default=auto)
   --with-msgpack          Enable msgpack support (auto/yes/no)
 
 Some influential environment variables:
@@ -15873,7 +15873,11 @@ else
 fi
 
 
-if test "$with_zstd" != no; then :
+case $with_zstd in #(
+  no) :
+     ;; #(
+  yes|auto) :
+
 
 pkg_failed=no
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libzstd >= 1.4.0" >&5
@@ -15958,17 +15962,21 @@ fi
 	echo "$ZSTD_PKG_ERRORS" >&5
 
 
-    if test "$with_zstd" = yes; then
-      as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
-    fi
+      if test "$with_zstd" = yes; then :
+
+        as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
+
+fi
 
 elif test $pkg_failed = untried; then
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 
-    if test "$with_zstd" = yes; then
-      as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
-    fi
+      if test "$with_zstd" = yes; then :
+
+        as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
+
+fi
 
 else
 	ZSTD_CFLAGS=$pkg_cv_ZSTD_CFLAGS
@@ -15981,8 +15989,72 @@ $as_echo "#define HAVE_ZSTD 1" >>confdefs.h
 
 
 fi
+   ;; #(
+  *) :
+
+    ZSTD_CFLAGS="-I$with_zstd/include"
+    ZSTD_LIBS="-L$with_zstd/lib -lzstd"
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for zstd >= 1.4.0 in $with_zstd" >&5
+$as_echo_n "checking for zstd >= 1.4.0 in $with_zstd... " >&6; }
+
+    zstd_save_CPPFLAGS=$CPPFLAGS
+    zstd_save_LIBS=$LIBS
+    CPPFLAGS="$CPPFLAGS $ZSTD_CFLAGS"
+    LIBS="$ZSTD_LIBS $LIBS"
+
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <zstd.h>
+#if ZSTD_VERSION_NUMBER < 10400
+# error zstd 1.4.0 or later is required
+#endif
+
+int
+main ()
+{
+
+          (void) ZSTD_compress(0, 0, 0, 0, 1);
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  have_zstd=yes
+else
+  have_zstd=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+
+    CPPFLAGS=$zstd_save_CPPFLAGS
+    LIBS=$zstd_save_LIBS
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_zstd" >&5
+$as_echo "$have_zstd" >&6; }
+
+    if test "$have_zstd" = yes; then :
+
+      pkg_cv_ZSTD_CFLAGS=$ZSTD_CFLAGS
+      pkg_cv_ZSTD_LIBS=$ZSTD_LIBS
+
+$as_echo "#define HAVE_ZSTD 1" >>confdefs.h
+
+
+else
+
+      as_fn_error $? "zstd >= 1.4.0 was not found under $with_zstd" "$LINENO" 5
 
 fi
+   ;; #(
+  *) :
+     ;;
+esac
+
+
+
 
 
 
diff --git a/config/zstd.m4 b/config/zstd.m4
index eb34c0f36d7..49595283e81 100644
--- a/config/zstd.m4
+++ b/config/zstd.m4
@@ -8,16 +8,61 @@ dnl the same distribution terms as the rest of that program.
 dnl Enable features using the zstd library.
 AC_DEFUN([AC_ZSTD], [
 AC_ARG_WITH(zstd,
-  [AS_HELP_STRING([--with-zstd], [support zstd compressed debug sections (default=auto)])],
+  [AS_HELP_STRING([--with-zstd@<:@=PATH@:>@],
+    [support zstd compressed debug sections, optionally using zstd installed under PATH (default=auto)])],
   [], [with_zstd=auto])
 
-AS_IF([test "$with_zstd" != no],
-  [PKG_CHECK_MODULES(ZSTD, [libzstd >= 1.4.0], [
-    AC_DEFINE(HAVE_ZSTD, 1, [Define to 1 if zstd is enabled.])
-  ], [
-    if test "$with_zstd" = yes; then
-      AC_MSG_ERROR([--with-zstd was given, but pkgconfig/libzstd.pc is not found])
-    fi
-  ])
+AS_CASE([$with_zstd],
+  [no], [],
+  [yes|auto], [
+    PKG_CHECK_MODULES([ZSTD], [libzstd >= 1.4.0], [
+      AC_DEFINE(HAVE_ZSTD, 1, [Define to 1 if zstd is enabled.])
+    ], [
+      AS_IF([test "$with_zstd" = yes], [
+        AC_MSG_ERROR(
+          [--with-zstd was given, but pkgconfig/libzstd.pc is not found])
+      ])
+    ])
+  ],
+  [*], [
+    ZSTD_CFLAGS="-I$with_zstd/include"
+    ZSTD_LIBS="-L$with_zstd/lib -lzstd"
+
+    AC_MSG_CHECKING([for zstd >= 1.4.0 in $with_zstd])
+
+    zstd_save_CPPFLAGS=$CPPFLAGS
+    zstd_save_LIBS=$LIBS
+    CPPFLAGS="$CPPFLAGS $ZSTD_CFLAGS"
+    LIBS="$ZSTD_LIBS $LIBS"
+
+    AC_LINK_IFELSE(
+      [AC_LANG_PROGRAM(
+        [[
+#include <zstd.h>
+#if ZSTD_VERSION_NUMBER < 10400
+# error zstd 1.4.0 or later is required
+#endif
+        ]],
+        [[
+          (void) ZSTD_compress(0, 0, 0, 0, 1);
+        ]])],
+      [have_zstd=yes],
+      [have_zstd=no])
+
+    CPPFLAGS=$zstd_save_CPPFLAGS
+    LIBS=$zstd_save_LIBS
+
+    AC_MSG_RESULT([$have_zstd])
+
+    AS_IF([test "$have_zstd" = yes], [
+      pkg_cv_ZSTD_CFLAGS=$ZSTD_CFLAGS
+      pkg_cv_ZSTD_LIBS=$ZSTD_LIBS
+      AC_DEFINE(HAVE_ZSTD, 1, [Define to 1 if zstd is enabled.])
+    ], [
+      AC_MSG_ERROR([zstd >= 1.4.0 was not found under $with_zstd])
+    ])
   ])
+
+AC_SUBST([ZSTD_CFLAGS])
+AC_SUBST([ZSTD_LIBS])
 ])
diff --git a/gas/configure b/gas/configure
index 8afaf2729ed..d971e0c52a5 100755
--- a/gas/configure
+++ b/gas/configure
@@ -1531,8 +1531,8 @@ Optional Packages:
   --without-libintl-prefix     don't search for libintl in includedir and libdir
   --with-libintl-type=TYPE     type of library to search for (auto/static/shared)
   --with-system-zlib      use installed libz
-  --with-zstd             support zstd compressed debug sections
-                          (default=auto)
+  --with-zstd[=PATH]      support zstd compressed debug sections, optionally
+                          using zstd installed under PATH (default=auto)
 
 Some influential environment variables:
   CC          C compiler command
@@ -16150,7 +16150,11 @@ else
 fi
 
 
-if test "$with_zstd" != no; then :
+case $with_zstd in #(
+  no) :
+     ;; #(
+  yes|auto) :
+
 
 pkg_failed=no
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libzstd >= 1.4.0" >&5
@@ -16235,17 +16239,21 @@ fi
 	echo "$ZSTD_PKG_ERRORS" >&5
 
 
-    if test "$with_zstd" = yes; then
-      as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
-    fi
+      if test "$with_zstd" = yes; then :
+
+        as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
+
+fi
 
 elif test $pkg_failed = untried; then
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 
-    if test "$with_zstd" = yes; then
-      as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
-    fi
+      if test "$with_zstd" = yes; then :
+
+        as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
+
+fi
 
 else
 	ZSTD_CFLAGS=$pkg_cv_ZSTD_CFLAGS
@@ -16258,8 +16266,72 @@ $as_echo "#define HAVE_ZSTD 1" >>confdefs.h
 
 
 fi
+   ;; #(
+  *) :
+
+    ZSTD_CFLAGS="-I$with_zstd/include"
+    ZSTD_LIBS="-L$with_zstd/lib -lzstd"
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for zstd >= 1.4.0 in $with_zstd" >&5
+$as_echo_n "checking for zstd >= 1.4.0 in $with_zstd... " >&6; }
+
+    zstd_save_CPPFLAGS=$CPPFLAGS
+    zstd_save_LIBS=$LIBS
+    CPPFLAGS="$CPPFLAGS $ZSTD_CFLAGS"
+    LIBS="$ZSTD_LIBS $LIBS"
+
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <zstd.h>
+#if ZSTD_VERSION_NUMBER < 10400
+# error zstd 1.4.0 or later is required
+#endif
+
+int
+main ()
+{
+
+          (void) ZSTD_compress(0, 0, 0, 0, 1);
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  have_zstd=yes
+else
+  have_zstd=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+
+    CPPFLAGS=$zstd_save_CPPFLAGS
+    LIBS=$zstd_save_LIBS
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_zstd" >&5
+$as_echo "$have_zstd" >&6; }
+
+    if test "$have_zstd" = yes; then :
+
+      pkg_cv_ZSTD_CFLAGS=$ZSTD_CFLAGS
+      pkg_cv_ZSTD_LIBS=$ZSTD_LIBS
+
+$as_echo "#define HAVE_ZSTD 1" >>confdefs.h
+
+
+else
+
+      as_fn_error $? "zstd >= 1.4.0 was not found under $with_zstd" "$LINENO" 5
 
 fi
+   ;; #(
+  *) :
+     ;;
+esac
+
+
+
 
 
 # Support for VMS timestamps via cross compile
diff --git a/gdb/configure b/gdb/configure
index 810e9ed7a37..04f9e5d6209 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -1721,8 +1721,8 @@ Optional Packages:
   --with-pkgversion=PKG   Use PKG in the version string in place of "GDB"
   --with-bugurl=URL       Direct users to URL to report a bug
   --with-system-zlib      use installed libz
-  --with-zstd             support zstd compressed debug sections
-                          (default=auto)
+  --with-zstd[=PATH]      support zstd compressed debug sections, optionally
+                          using zstd installed under PATH (default=auto)
   --with-iconv-bin=PATH   specify where to find the iconv program
   --with-system-readline  use installed readline library
   --with-jit-reader-dir=PATH
@@ -26723,7 +26723,11 @@ else
 fi
 
 
-if test "$with_zstd" != no; then :
+case $with_zstd in #(
+  no) :
+     ;; #(
+  yes|auto) :
+
 
 pkg_failed=no
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libzstd >= 1.4.0" >&5
@@ -26808,17 +26812,21 @@ fi
 	echo "$ZSTD_PKG_ERRORS" >&5
 
 
-    if test "$with_zstd" = yes; then
-      as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
-    fi
+      if test "$with_zstd" = yes; then :
+
+        as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
+
+fi
 
 elif test $pkg_failed = untried; then
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 
-    if test "$with_zstd" = yes; then
-      as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
-    fi
+      if test "$with_zstd" = yes; then :
+
+        as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
+
+fi
 
 else
 	ZSTD_CFLAGS=$pkg_cv_ZSTD_CFLAGS
@@ -26831,8 +26839,72 @@ $as_echo "#define HAVE_ZSTD 1" >>confdefs.h
 
 
 fi
+   ;; #(
+  *) :
+
+    ZSTD_CFLAGS="-I$with_zstd/include"
+    ZSTD_LIBS="-L$with_zstd/lib -lzstd"
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for zstd >= 1.4.0 in $with_zstd" >&5
+$as_echo_n "checking for zstd >= 1.4.0 in $with_zstd... " >&6; }
+
+    zstd_save_CPPFLAGS=$CPPFLAGS
+    zstd_save_LIBS=$LIBS
+    CPPFLAGS="$CPPFLAGS $ZSTD_CFLAGS"
+    LIBS="$ZSTD_LIBS $LIBS"
+
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <zstd.h>
+#if ZSTD_VERSION_NUMBER < 10400
+# error zstd 1.4.0 or later is required
+#endif
+
+int
+main ()
+{
+
+          (void) ZSTD_compress(0, 0, 0, 0, 1);
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  have_zstd=yes
+else
+  have_zstd=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+
+    CPPFLAGS=$zstd_save_CPPFLAGS
+    LIBS=$zstd_save_LIBS
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_zstd" >&5
+$as_echo "$have_zstd" >&6; }
+
+    if test "$have_zstd" = yes; then :
+
+      pkg_cv_ZSTD_CFLAGS=$ZSTD_CFLAGS
+      pkg_cv_ZSTD_LIBS=$ZSTD_LIBS
+
+$as_echo "#define HAVE_ZSTD 1" >>confdefs.h
+
+
+else
+
+      as_fn_error $? "zstd >= 1.4.0 was not found under $with_zstd" "$LINENO" 5
 
 fi
+   ;; #(
+  *) :
+     ;;
+esac
+
+
+
 
 
 
diff --git a/gold/configure b/gold/configure
index a81a04f0531..fb21757c723 100755
--- a/gold/configure
+++ b/gold/configure
@@ -1555,8 +1555,8 @@ Optional Packages:
   --with-gold-ldflags=FLAGS  additional link flags for gold
   --with-gold-ldadd=LIBS     additional libraries for gold
   --with-system-zlib      use installed libz
-  --with-zstd             support zstd compressed debug sections
-                          (default=auto)
+  --with-zstd[=PATH]      support zstd compressed debug sections, optionally
+                          using zstd installed under PATH (default=auto)
 
 Some influential environment variables:
   CC          C compiler command
@@ -9997,7 +9997,11 @@ else
 fi
 
 
-if test "$with_zstd" != no; then :
+case $with_zstd in #(
+  no) :
+     ;; #(
+  yes|auto) :
+
 
 pkg_failed=no
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libzstd >= 1.4.0" >&5
@@ -10082,17 +10086,21 @@ fi
 	echo "$ZSTD_PKG_ERRORS" >&5
 
 
-    if test "$with_zstd" = yes; then
-      as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
-    fi
+      if test "$with_zstd" = yes; then :
+
+        as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
+
+fi
 
 elif test $pkg_failed = untried; then
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 
-    if test "$with_zstd" = yes; then
-      as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
-    fi
+      if test "$with_zstd" = yes; then :
+
+        as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
+
+fi
 
 else
 	ZSTD_CFLAGS=$pkg_cv_ZSTD_CFLAGS
@@ -10105,8 +10113,72 @@ $as_echo "#define HAVE_ZSTD 1" >>confdefs.h
 
 
 fi
+   ;; #(
+  *) :
+
+    ZSTD_CFLAGS="-I$with_zstd/include"
+    ZSTD_LIBS="-L$with_zstd/lib -lzstd"
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for zstd >= 1.4.0 in $with_zstd" >&5
+$as_echo_n "checking for zstd >= 1.4.0 in $with_zstd... " >&6; }
+
+    zstd_save_CPPFLAGS=$CPPFLAGS
+    zstd_save_LIBS=$LIBS
+    CPPFLAGS="$CPPFLAGS $ZSTD_CFLAGS"
+    LIBS="$ZSTD_LIBS $LIBS"
+
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <zstd.h>
+#if ZSTD_VERSION_NUMBER < 10400
+# error zstd 1.4.0 or later is required
+#endif
+
+int
+main ()
+{
+
+          (void) ZSTD_compress(0, 0, 0, 0, 1);
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  have_zstd=yes
+else
+  have_zstd=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+
+    CPPFLAGS=$zstd_save_CPPFLAGS
+    LIBS=$zstd_save_LIBS
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_zstd" >&5
+$as_echo "$have_zstd" >&6; }
+
+    if test "$have_zstd" = yes; then :
+
+      pkg_cv_ZSTD_CFLAGS=$ZSTD_CFLAGS
+      pkg_cv_ZSTD_LIBS=$ZSTD_LIBS
+
+$as_echo "#define HAVE_ZSTD 1" >>confdefs.h
+
+
+else
+
+      as_fn_error $? "zstd >= 1.4.0 was not found under $with_zstd" "$LINENO" 5
 
 fi
+   ;; #(
+  *) :
+     ;;
+esac
+
+
+
 
  if test "$pkg_cv_ZSTD_LIBS" != ""; then
   HAVE_ZSTD_TRUE=
diff --git a/ld/configure b/ld/configure
index 4d755384c41..10628a69b73 100755
--- a/ld/configure
+++ b/ld/configure
@@ -1598,8 +1598,8 @@ Optional Packages:
   --with-xxhash           use inlined libxxhash for hashing (faster)
                           (auto/yes/no)
   --with-system-zlib      use installed libz
-  --with-zstd             support zstd compressed debug sections
-                          (default=auto)
+  --with-zstd[=PATH]      support zstd compressed debug sections, optionally
+                          using zstd installed under PATH (default=auto)
 
 Some influential environment variables:
   CC          C compiler command
@@ -19088,7 +19088,11 @@ else
 fi
 
 
-if test "$with_zstd" != no; then :
+case $with_zstd in #(
+  no) :
+     ;; #(
+  yes|auto) :
+
 
 pkg_failed=no
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libzstd >= 1.4.0" >&5
@@ -19173,17 +19177,21 @@ fi
 	echo "$ZSTD_PKG_ERRORS" >&5
 
 
-    if test "$with_zstd" = yes; then
-      as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
-    fi
+      if test "$with_zstd" = yes; then :
+
+        as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
+
+fi
 
 elif test $pkg_failed = untried; then
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
 
-    if test "$with_zstd" = yes; then
-      as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
-    fi
+      if test "$with_zstd" = yes; then :
+
+        as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
+
+fi
 
 else
 	ZSTD_CFLAGS=$pkg_cv_ZSTD_CFLAGS
@@ -19196,8 +19204,72 @@ $as_echo "#define HAVE_ZSTD 1" >>confdefs.h
 
 
 fi
+   ;; #(
+  *) :
+
+    ZSTD_CFLAGS="-I$with_zstd/include"
+    ZSTD_LIBS="-L$with_zstd/lib -lzstd"
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for zstd >= 1.4.0 in $with_zstd" >&5
+$as_echo_n "checking for zstd >= 1.4.0 in $with_zstd... " >&6; }
+
+    zstd_save_CPPFLAGS=$CPPFLAGS
+    zstd_save_LIBS=$LIBS
+    CPPFLAGS="$CPPFLAGS $ZSTD_CFLAGS"
+    LIBS="$ZSTD_LIBS $LIBS"
+
+    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#include <zstd.h>
+#if ZSTD_VERSION_NUMBER < 10400
+# error zstd 1.4.0 or later is required
+#endif
+
+int
+main ()
+{
+
+          (void) ZSTD_compress(0, 0, 0, 0, 1);
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+  have_zstd=yes
+else
+  have_zstd=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext conftest.$ac_ext
+
+    CPPFLAGS=$zstd_save_CPPFLAGS
+    LIBS=$zstd_save_LIBS
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: result: $have_zstd" >&5
+$as_echo "$have_zstd" >&6; }
+
+    if test "$have_zstd" = yes; then :
+
+      pkg_cv_ZSTD_CFLAGS=$ZSTD_CFLAGS
+      pkg_cv_ZSTD_LIBS=$ZSTD_LIBS
+
+$as_echo "#define HAVE_ZSTD 1" >>confdefs.h
+
+
+else
+
+      as_fn_error $? "zstd >= 1.4.0 was not found under $with_zstd" "$LINENO" 5
 
 fi
+   ;; #(
+  *) :
+     ;;
+esac
+
+
+
 
 
 # target-specific stuff:
-- 
2.43.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] configure: Support --with-zstd=PATH
  2026-09-28  5:30 [PATCH v2] configure: Support --with-zstd=PATH Torbjörn SVENSSON
@ 2026-09-29  2:00 ` Simon Marchi
  2026-10-20 17:40   ` [PATCH v3] configure: Sync zstd detection with GCC Torbjörn SVENSSON
  0 siblings, 1 reply; 7+ messages in thread
From: Simon Marchi @ 2026-09-29  2:00 UTC (permalink / raw)
  To: Torbjörn SVENSSON, binutils, gdb-patches



On 2026-09-28 01:30, Torbjörn SVENSSON wrote:
> Hi,
> 
> V1 can be found here:
> https://sourceware.org/pipermail/binutils/2026-September/151687.html
> 
> Changes since v1:
> - Added missed changes in binutils/Makefile.am and binutils/Makefile.in
> - Added support for dynamic version of zstd in path
> 
> 
> Ok for trunk?
> 
> Kind regards,
> Torbjörn
> 
> --
> 
> Allow --with-zstd to specify an installation prefix.  Use the headers
> and static library under that prefix, and reject it if it does not
> provide zstd 1.4.0 or newer.
> 
> Regenerate the affected configure scripts.
> 
> Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>

Can you explain why using pkg-config wouldn't work for your use case?

In your other message, you mentioned that gcc also accepted a
--with-zstd=path, but it actually accepts more:

  --with-zstd=PATH        specify prefix directory for installed zstd library.
                          Equivalent to --with-zstd-include=PATH/include plus
                          --with-zstd-lib=PATH/lib
  --with-zstd-include=PATH
                          specify directory for installed zstd include files
  --with-zstd-lib=PATH    specify directory for the installed zstd library

This is open-coded in gcc/configure.ac:

  # Look for the ZSTD package.
  ZSTD_INCLUDE=
  ZSTD_LIB=
  AC_SUBST(ZSTD_INCLUDE)
  AC_SUBST(ZSTD_LIB)
  ZSTD_CPPFLAGS=
  ZSTD_LDFLAGS=
  AC_SUBST(ZSTD_CPPFLAGS)
  AC_SUBST(ZSTD_LDFLAGS)
  AC_ARG_WITH(zstd,
          [AS_HELP_STRING([--with-zstd=PATH],
                  [specify prefix directory for installed zstd library.
                   Equivalent to --with-zstd-include=PATH/include
                   plus --with-zstd-lib=PATH/lib])])
  AC_ARG_WITH(zstd-include,
          [AS_HELP_STRING([--with-zstd-include=PATH],
                  [specify directory for installed zstd include files])])
  AC_ARG_WITH(zstd-lib,
          [AS_HELP_STRING([--with-zstd-lib=PATH],
                  [specify directory for the installed zstd library])])

For consistency across the toolchain, would you consider moving this gcc
code to gcc/config/zstd.m4, and then sync gcc's zstd.m4 over to
binutils-gdb?

Simon

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v3] configure: Sync zstd detection with GCC
  2026-09-29  2:00 ` Simon Marchi
@ 2026-10-20 17:40   ` Torbjörn SVENSSON
  2026-10-21  6:56     ` Alan Modra
  0 siblings, 1 reply; 7+ messages in thread
From: Torbjörn SVENSSON @ 2026-10-20 17:40 UTC (permalink / raw)
  To: binutils, gdb-patches; +Cc: simark, Torbjörn SVENSSON

Hi,

I've now update the GCC version of zstd.m4 to contain a unified
implementation to detect zstd support.

Please let me know if there is something I've missed.

V1 can be found here:
https://sourceware.org/pipermail/binutils/2026-September/151687.html

V2 can be found here:
https://sourceware.org/pipermail/binutils/2026-September/151690.html

Changes since v1:
- Added missed changes in binutils/Makefile.am and binutils/Makefile.in
- Added support for dynamic version of zstd in path

Changes since v2:
- Updated the GCC version of config/zstd.m4 and synced back those
  changes to this tree.
- Fixed gold/configure.ac to use $zstd_enabled.

Ok for trunk?

Kind regards,
Torbjörn

--

Sync config/zstd.m4 with GCC to support compiler-based detection and
configurable zstd search paths.

Add ZSTD_LIBS to binutils link commands for tools using zstd through
BFD.  Base gold's zstd test conditional on the final detection result
rather than pkg-config flags.

Regenerate the affected configure scripts and binutils Makefile.in.

Signed-off-by: Torbjörn SVENSSON <torbjorn.svensson@foss.st.com>
---
 bfd/configure        | 240 +++++++++++++++++++++++++++++++++++++++----
 binutils/Makefile.am |  14 +--
 binutils/Makefile.in |  16 +--
 binutils/configure   | 236 +++++++++++++++++++++++++++++++++++++++---
 config/zstd.m4       | 134 +++++++++++++++++++++---
 gas/configure        | 240 +++++++++++++++++++++++++++++++++++++++----
 gdb/configure        | 236 +++++++++++++++++++++++++++++++++++++++---
 gold/configure       | 238 ++++++++++++++++++++++++++++++++++++++----
 gold/configure.ac    |   2 +-
 ld/configure         | 236 +++++++++++++++++++++++++++++++++++++++---
 10 files changed, 1457 insertions(+), 135 deletions(-)

diff --git a/bfd/configure b/bfd/configure
index a4326160c57..fd8db630cf6 100755
--- a/bfd/configure
+++ b/bfd/configure
@@ -653,11 +653,11 @@ TDEFINES
 SHARED_LIBADD
 SHARED_LDFLAGS
 LIBM
-ZSTD_LIBS
-ZSTD_CFLAGS
 PKG_CONFIG_LIBDIR
 PKG_CONFIG_PATH
 PKG_CONFIG
+ZSTD_LIBS
+ZSTD_CFLAGS
 zlibinc
 zlibdir
 EXEEXT_FOR_BUILD
@@ -855,6 +855,8 @@ with_libintl_prefix
 with_libintl_type
 with_system_zlib
 with_zstd
+with_zstd_include
+with_zstd_lib
 '
       ac_precious_vars='build_alias
 host_alias
@@ -1540,8 +1542,15 @@ Optional Packages:
   --without-libintl-prefix     don't search for libintl in includedir and libdir
   --with-libintl-type=TYPE     type of library to search for (auto/static/shared)
   --with-system-zlib      use installed libz
-  --with-zstd             support zstd compressed debug sections
-                          (default=auto)
+  --with-zstd=VALUE       VALUE may be 'auto' (try pkg-config, then compiler
+                          search; default), 'yes' (require zstd), 'no'
+                          (disable it), or a PATH for the installation prefix.
+                          When VALUE is a PATH, this is equivalent to
+                          --with-zstd-include=PATH/include and
+                          --with-zstd-lib=PATH/lib
+  --with-zstd-include=PATH
+                          specify directory for installed zstd include files
+  --with-zstd-lib=PATH    specify directory for the installed zstd library
 
 Some influential environment variables:
   CC          C compiler command
@@ -11527,7 +11536,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11530 "configure"
+#line 11539 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11633,7 +11642,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11636 "configure"
+#line 11645 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -15415,15 +15424,47 @@ $as_echo "no" >&6; }
 fi
 
 
+
+
 # Check whether --with-zstd was given.
 if test "${with_zstd+set}" = set; then :
-  withval=$with_zstd;
+  withval=$with_zstd; with_zstd=$withval
 else
   with_zstd=auto
 fi
 
 
-if test "$with_zstd" != no; then :
+# Check whether --with-zstd-include was given.
+if test "${with_zstd_include+set}" = set; then :
+  withval=$with_zstd_include;
+fi
+
+
+# Check whether --with-zstd-lib was given.
+if test "${with_zstd_lib+set}" = set; then :
+  withval=$with_zstd_lib;
+fi
+
+zstd_enabled=no
+zstd_pkg_config=no
+zstd_use_pkg_config=no
+zstd_include_dir=
+zstd_library_dir=
+case "x$with_zstd" in
+  xno)
+    ;;
+  xyes|xauto)
+    zstd_enabled=yes
+    zstd_use_pkg_config=yes
+    ;;
+  *)
+    zstd_enabled=yes
+    zstd_include_dir=$with_zstd/include
+    zstd_library_dir=$with_zstd/lib
+    ;;
+esac
+
+if test "$zstd_use_pkg_config" = yes; then
 
 pkg_failed=no
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libzstd >= 1.4.0" >&5
@@ -15507,31 +15548,192 @@ fi
 	# Put the nasty error message in config.log where it belongs
 	echo "$ZSTD_PKG_ERRORS" >&5
 
-
-    if test "$with_zstd" = yes; then
-      as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
-    fi
-
+	:
 elif test $pkg_failed = untried; then
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
-
-    if test "$with_zstd" = yes; then
-      as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
-    fi
-
+	:
 else
 	ZSTD_CFLAGS=$pkg_cv_ZSTD_CFLAGS
 	ZSTD_LIBS=$pkg_cv_ZSTD_LIBS
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 
+    zstd_pkg_config=yes
 
-$as_echo "#define HAVE_ZSTD 1" >>confdefs.h
+fi
+fi
 
+if test "$zstd_enabled" = yes; then
+  saved_CFLAGS="$CFLAGS"
+  save_LIBS="$LIBS"
+  ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+  while :; do
+    if test "x$with_zstd_include" != x; then
+      if test "$zstd_pkg_config" = yes; then
+	ZSTD_CFLAGS="-I$with_zstd_include $ZSTD_CFLAGS"
+      else
+	zstd_include_dir=$with_zstd_include
+      fi
+    fi
+    if test "x$with_zstd_lib" != x; then
+      zstd_library_dir=$with_zstd_lib
+    fi
+    if test "$zstd_pkg_config" != yes; then
+      ZSTD_CFLAGS=
+      ZSTD_LIBS=
+      if test "x$zstd_include_dir" != x \
+	 && test "x$zstd_include_dir" != xno; then
+	ZSTD_CFLAGS=-I$zstd_include_dir
+      fi
+    fi
+    if test "x$zstd_library_dir" != x \
+       && test "x$zstd_library_dir" != xno; then
+      ZSTD_LIBS="-L$zstd_library_dir $ZSTD_LIBS"
+    fi
+
+    CFLAGS="$saved_CFLAGS $ZSTD_CFLAGS"
 
+    # Check for a usable zstd library and header.  Ignore cached results
+    # that may have been obtained with different search flags.
+    unset ac_cv_search_ZSTD_compress ac_cv_zstd_h
+    zstd_lib_usable=no
+    LIBS="$ZSTD_LIBS $save_LIBS"
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing ZSTD_compress" >&5
+$as_echo_n "checking for library containing ZSTD_compress... " >&6; }
+if ${ac_cv_search_ZSTD_compress+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char ZSTD_compress ();
+int
+main ()
+{
+return ZSTD_compress ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' zstd; do
+  if test -z "$ac_lib"; then
+    ac_res="none required"
+  else
+    ac_res=-l$ac_lib
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_search_ZSTD_compress=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext
+  if ${ac_cv_search_ZSTD_compress+:} false; then :
+  break
+fi
+done
+if ${ac_cv_search_ZSTD_compress+:} false; then :
+
+else
+  ac_cv_search_ZSTD_compress=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_ZSTD_compress" >&5
+$as_echo "$ac_cv_search_ZSTD_compress" >&6; }
+ac_res=$ac_cv_search_ZSTD_compress
+if test "$ac_res" != no; then :
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+  zstd_lib_usable=yes
+else
+  zstd_lib_usable=no
+fi
+
+    if test "$zstd_lib_usable" = yes \
+       && test "$ac_cv_search_ZSTD_compress" != "none required"; then
+      # Add the library only if AC_SEARCH_LIBS needed additional flags.
+      ZSTD_LIBS="$ac_cv_search_ZSTD_compress $ZSTD_LIBS"
+    fi
+    LIBS="$save_LIBS"
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for zstd.h" >&5
+$as_echo_n "checking for zstd.h... " >&6; }
+if ${ac_cv_zstd_h+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+	#include <zstd.h>
+	#if ZSTD_VERSION_NUMBER < 10400
+	#error "need zstd 1.4.0 or better"
+	#endif
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_zstd_h=yes
+else
+  ac_cv_zstd_h=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_zstd_h" >&5
+$as_echo "$ac_cv_zstd_h" >&6; }
+    if test "$zstd_pkg_config" = yes \
+       && { test "$zstd_lib_usable" != yes || test "$ac_cv_zstd_h" != yes; }; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: pkg-config zstd is unusable; trying compiler search" >&5
+$as_echo "$as_me: pkg-config zstd is unusable; trying compiler search" >&6;}
+      zstd_pkg_config=no
+      ZSTD_CFLAGS=
+      ZSTD_LIBS=
+    else
+      break
+    fi
+  done
+  ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
+  if test "$zstd_lib_usable" = yes && test "$ac_cv_zstd_h" = yes; then
+
+$as_echo "#define HAVE_ZSTD 1" >>confdefs.h
+
+  elif test "$with_zstd" != auto; then
+    as_fn_error $? "Unable to find a usable zstd library and zstd.h.  See
+      config.log for details." "$LINENO" 5
+  else
+    # In auto mode, an unusable installation simply disables zstd.
+    zstd_enabled=no
+  fi
+
+  CFLAGS="$saved_CFLAGS"
+fi
+if test "$zstd_enabled" != yes; then
+  ZSTD_CFLAGS=
+  ZSTD_LIBS=
 fi
 
 
diff --git a/binutils/Makefile.am b/binutils/Makefile.am
index edcbc67bde4..0582d9fb826 100644
--- a/binutils/Makefile.am
+++ b/binutils/Makefile.am
@@ -251,7 +251,7 @@ dllwrap_DEPENDENCIES =   $(LIBINTL_DEP) $(LIBIBERTY)
 bfdtest1_DEPENDENCIES =  $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
 bfdtest2_DEPENDENCIES =  $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
 
-LDADD = $(BFDLIB) $(LIBIBERTY) $(LIBINTL)
+LDADD = $(BFDLIB) $(LIBIBERTY) $(LIBINTL) $(ZSTD_LIBS)
 
 size_SOURCES = size.c $(BULIBS)
 
@@ -271,7 +271,7 @@ nm_new_SOURCES = nm.c demanguse.c $(BULIBS)
 
 objdump_SOURCES = objdump.c dwarf.c prdbg.c demanguse.c $(DEBUG_SRCS) $(BULIBS) $(ELFLIBS)
 EXTRA_objdump_SOURCES = od-elf32_avr.c od-macho.c od-xcoff.c od-pe.c
-objdump_LDADD = $(OBJDUMP_PRIVATE_OFILES) $(OPCODES) $(LIBCTF) $(BFDLIB) $(LIBIBERTY) $(LIBINTL) $(DEBUGINFOD_LIBS) $(LIBSFRAME)
+objdump_LDADD = $(OBJDUMP_PRIVATE_OFILES) $(OPCODES) $(LIBCTF) $(BFDLIB) $(LIBIBERTY) $(LIBINTL) $(ZSTD_LIBS) $(DEBUGINFOD_LIBS) $(LIBSFRAME)
 
 objdump.@OBJEXT@:objdump.c
 if am__fastdepCC
@@ -290,11 +290,11 @@ cxxfilt_SOURCES = cxxfilt.c $(BULIBS)
 ar_SOURCES = arparse.y arlex.l not-ranlib.c arsup.c rename.c binemul.c \
 	emul_$(EMULATION).c $(BULIBS)
 EXTRA_ar_SOURCES = $(CFILES)
-ar_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL)
+ar_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(ZSTD_LIBS)
 
 ranlib_SOURCES = arparse.y arlex.l is-ranlib.c arsup.c rename.c binemul.c \
 	emul_$(EMULATION).c $(BULIBS)
-ranlib_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL)
+ranlib_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(ZSTD_LIBS)
 
 addr2line_SOURCES = addr2line.c $(BULIBS)
 
@@ -485,7 +485,7 @@ srconv_SOURCES = srconv.c coffgrok.c $(BULIBS)
 srconv.@OBJEXT@: sysroff.c
 
 dlltool_SOURCES = dlltool.c defparse.y deflex.l $(BULIBS)
-dlltool_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL)
+dlltool_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(ZSTD_LIBS)
 
 dlltool.@OBJEXT@:
 if am__fastdepCC
@@ -518,11 +518,11 @@ sysdump.@OBJEXT@: sysroff.c
 
 windres_SOURCES = windres.c resrc.c rescoff.c resbin.c rcparse.y rclex.c \
 	winduni.c resres.c $(BULIBS)
-windres_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(LIBICONV)
+windres_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(LIBICONV) $(ZSTD_LIBS)
 
 windmc_SOURCES = windmc.c mcparse.y mclex.c \
 	winduni.c $(BULIBS)
-windmc_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(LIBICONV)
+windmc_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(LIBICONV) $(ZSTD_LIBS)
 
 dllwrap_SOURCES = dllwrap.c version.c
 dllwrap_LDADD = $(LIBIBERTY) $(LIBINTL)
diff --git a/binutils/Makefile.in b/binutils/Makefile.in
index fff4565e302..69f6a1e128c 100644
--- a/binutils/Makefile.in
+++ b/binutils/Makefile.in
@@ -282,7 +282,7 @@ am__dirstamp = $(am__leading_dot)dirstamp
 testsuite_gentestdlls_OBJECTS = testsuite/gentestdlls.$(OBJEXT)
 testsuite_gentestdlls_LDADD = $(LDADD)
 testsuite_gentestdlls_DEPENDENCIES = $(BFDLIB) $(LIBIBERTY) \
-	$(am__DEPENDENCIES_1)
+	$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
 am_windmc_OBJECTS = windmc.$(OBJEXT) mcparse.$(OBJEXT) mclex.$(OBJEXT) \
 	winduni.$(OBJEXT) $(am__objects_1)
 windmc_OBJECTS = $(am_windmc_OBJECTS)
@@ -794,7 +794,7 @@ elfedit_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY)
 dllwrap_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY)
 bfdtest1_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
 bfdtest2_DEPENDENCIES = $(LIBINTL_DEP) $(LIBIBERTY) $(BFDLIB)
-LDADD = $(BFDLIB) $(LIBIBERTY) $(LIBINTL)
+LDADD = $(BFDLIB) $(LIBIBERTY) $(LIBINTL) $(ZSTD_LIBS)
 size_SOURCES = size.c $(BULIBS)
 objcopy_SOURCES = not-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS)
 strings_SOURCES = strings.c $(BULIBS)
@@ -806,31 +806,31 @@ strip_new_SOURCES = is-strip.c rename.c $(WRITE_DEBUG_SRCS) $(BULIBS)
 nm_new_SOURCES = nm.c demanguse.c $(BULIBS)
 objdump_SOURCES = objdump.c dwarf.c prdbg.c demanguse.c $(DEBUG_SRCS) $(BULIBS) $(ELFLIBS)
 EXTRA_objdump_SOURCES = od-elf32_avr.c od-macho.c od-xcoff.c od-pe.c
-objdump_LDADD = $(OBJDUMP_PRIVATE_OFILES) $(OPCODES) $(LIBCTF) $(BFDLIB) $(LIBIBERTY) $(LIBINTL) $(DEBUGINFOD_LIBS) $(LIBSFRAME)
+objdump_LDADD = $(OBJDUMP_PRIVATE_OFILES) $(OPCODES) $(LIBCTF) $(BFDLIB) $(LIBIBERTY) $(LIBINTL) $(ZSTD_LIBS) $(DEBUGINFOD_LIBS) $(LIBSFRAME)
 cxxfilt_SOURCES = cxxfilt.c $(BULIBS)
 ar_SOURCES = arparse.y arlex.l not-ranlib.c arsup.c rename.c binemul.c \
 	emul_$(EMULATION).c $(BULIBS)
 
 EXTRA_ar_SOURCES = $(CFILES)
-ar_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL)
+ar_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(ZSTD_LIBS)
 ranlib_SOURCES = arparse.y arlex.l is-ranlib.c arsup.c rename.c binemul.c \
 	emul_$(EMULATION).c $(BULIBS)
 
-ranlib_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL)
+ranlib_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(ZSTD_LIBS)
 addr2line_SOURCES = addr2line.c $(BULIBS)
 srconv_SOURCES = srconv.c coffgrok.c $(BULIBS)
 dlltool_SOURCES = dlltool.c defparse.y deflex.l $(BULIBS)
-dlltool_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL)
+dlltool_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(ZSTD_LIBS)
 coffdump_SOURCES = coffdump.c coffgrok.c $(BULIBS)
 sysdump_SOURCES = sysdump.c $(BULIBS)
 windres_SOURCES = windres.c resrc.c rescoff.c resbin.c rcparse.y rclex.c \
 	winduni.c resres.c $(BULIBS)
 
-windres_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(LIBICONV)
+windres_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(LIBICONV) $(ZSTD_LIBS)
 windmc_SOURCES = windmc.c mcparse.y mclex.c \
 	winduni.c $(BULIBS)
 
-windmc_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(LIBICONV)
+windmc_LDADD = $(BFDLIB) $(LIBIBERTY) $(LEXLIB) $(LIBINTL) $(LIBICONV) $(ZSTD_LIBS)
 dllwrap_SOURCES = dllwrap.c version.c
 dllwrap_LDADD = $(LIBIBERTY) $(LIBINTL)
 EXTRA_DIST = arparse.c arparse.h arlex.c sysinfo.c sysinfo.h \
diff --git a/binutils/configure b/binutils/configure
index ea19d09749f..853bf8e7fd2 100755
--- a/binutils/configure
+++ b/binutils/configure
@@ -846,6 +846,8 @@ with_libintl_type
 enable_maintainer_mode
 with_system_zlib
 with_zstd
+with_zstd_include
+with_zstd_lib
 with_msgpack
 '
       ac_precious_vars='build_alias
@@ -1540,8 +1542,15 @@ Optional Packages:
   --without-libintl-prefix     don't search for libintl in includedir and libdir
   --with-libintl-type=TYPE     type of library to search for (auto/static/shared)
   --with-system-zlib      use installed libz
-  --with-zstd             support zstd compressed debug sections
-                          (default=auto)
+  --with-zstd=VALUE       VALUE may be 'auto' (try pkg-config, then compiler
+                          search; default), 'yes' (require zstd), 'no'
+                          (disable it), or a PATH for the installation prefix.
+                          When VALUE is a PATH, this is equivalent to
+                          --with-zstd-include=PATH/include and
+                          --with-zstd-lib=PATH/lib
+  --with-zstd-include=PATH
+                          specify directory for installed zstd include files
+  --with-zstd-lib=PATH    specify directory for the installed zstd library
   --with-msgpack          Enable msgpack support (auto/yes/no)
 
 Some influential environment variables:
@@ -11455,7 +11464,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11458 "configure"
+#line 11467 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11561,7 +11570,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11564 "configure"
+#line 11573 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -15865,15 +15874,47 @@ fi
 
 
 
+
+
 # Check whether --with-zstd was given.
 if test "${with_zstd+set}" = set; then :
-  withval=$with_zstd;
+  withval=$with_zstd; with_zstd=$withval
 else
   with_zstd=auto
 fi
 
 
-if test "$with_zstd" != no; then :
+# Check whether --with-zstd-include was given.
+if test "${with_zstd_include+set}" = set; then :
+  withval=$with_zstd_include;
+fi
+
+
+# Check whether --with-zstd-lib was given.
+if test "${with_zstd_lib+set}" = set; then :
+  withval=$with_zstd_lib;
+fi
+
+zstd_enabled=no
+zstd_pkg_config=no
+zstd_use_pkg_config=no
+zstd_include_dir=
+zstd_library_dir=
+case "x$with_zstd" in
+  xno)
+    ;;
+  xyes|xauto)
+    zstd_enabled=yes
+    zstd_use_pkg_config=yes
+    ;;
+  *)
+    zstd_enabled=yes
+    zstd_include_dir=$with_zstd/include
+    zstd_library_dir=$with_zstd/lib
+    ;;
+esac
+
+if test "$zstd_use_pkg_config" = yes; then
 
 pkg_failed=no
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libzstd >= 1.4.0" >&5
@@ -15957,31 +15998,192 @@ fi
 	# Put the nasty error message in config.log where it belongs
 	echo "$ZSTD_PKG_ERRORS" >&5
 
-
-    if test "$with_zstd" = yes; then
-      as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
-    fi
-
+	:
 elif test $pkg_failed = untried; then
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
-
-    if test "$with_zstd" = yes; then
-      as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
-    fi
-
+	:
 else
 	ZSTD_CFLAGS=$pkg_cv_ZSTD_CFLAGS
 	ZSTD_LIBS=$pkg_cv_ZSTD_LIBS
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 
+    zstd_pkg_config=yes
 
-$as_echo "#define HAVE_ZSTD 1" >>confdefs.h
+fi
+fi
 
+if test "$zstd_enabled" = yes; then
+  saved_CFLAGS="$CFLAGS"
+  save_LIBS="$LIBS"
+  ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
+  while :; do
+    if test "x$with_zstd_include" != x; then
+      if test "$zstd_pkg_config" = yes; then
+	ZSTD_CFLAGS="-I$with_zstd_include $ZSTD_CFLAGS"
+      else
+	zstd_include_dir=$with_zstd_include
+      fi
+    fi
+    if test "x$with_zstd_lib" != x; then
+      zstd_library_dir=$with_zstd_lib
+    fi
+    if test "$zstd_pkg_config" != yes; then
+      ZSTD_CFLAGS=
+      ZSTD_LIBS=
+      if test "x$zstd_include_dir" != x \
+	 && test "x$zstd_include_dir" != xno; then
+	ZSTD_CFLAGS=-I$zstd_include_dir
+      fi
+    fi
+    if test "x$zstd_library_dir" != x \
+       && test "x$zstd_library_dir" != xno; then
+      ZSTD_LIBS="-L$zstd_library_dir $ZSTD_LIBS"
+    fi
+
+    CFLAGS="$saved_CFLAGS $ZSTD_CFLAGS"
+
+    # Check for a usable zstd library and header.  Ignore cached results
+    # that may have been obtained with different search flags.
+    unset ac_cv_search_ZSTD_compress ac_cv_zstd_h
+    zstd_lib_usable=no
+    LIBS="$ZSTD_LIBS $save_LIBS"
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing ZSTD_compress" >&5
+$as_echo_n "checking for library containing ZSTD_compress... " >&6; }
+if ${ac_cv_search_ZSTD_compress+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char ZSTD_compress ();
+int
+main ()
+{
+return ZSTD_compress ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' zstd; do
+  if test -z "$ac_lib"; then
+    ac_res="none required"
+  else
+    ac_res=-l$ac_lib
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_search_ZSTD_compress=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext
+  if ${ac_cv_search_ZSTD_compress+:} false; then :
+  break
+fi
+done
+if ${ac_cv_search_ZSTD_compress+:} false; then :
+
+else
+  ac_cv_search_ZSTD_compress=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_ZSTD_compress" >&5
+$as_echo "$ac_cv_search_ZSTD_compress" >&6; }
+ac_res=$ac_cv_search_ZSTD_compress
+if test "$ac_res" != no; then :
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+  zstd_lib_usable=yes
+else
+  zstd_lib_usable=no
+fi
+
+    if test "$zstd_lib_usable" = yes \
+       && test "$ac_cv_search_ZSTD_compress" != "none required"; then
+      # Add the library only if AC_SEARCH_LIBS needed additional flags.
+      ZSTD_LIBS="$ac_cv_search_ZSTD_compress $ZSTD_LIBS"
+    fi
+    LIBS="$save_LIBS"
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for zstd.h" >&5
+$as_echo_n "checking for zstd.h... " >&6; }
+if ${ac_cv_zstd_h+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+	#include <zstd.h>
+	#if ZSTD_VERSION_NUMBER < 10400
+	#error "need zstd 1.4.0 or better"
+	#endif
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_zstd_h=yes
+else
+  ac_cv_zstd_h=no
 fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_zstd_h" >&5
+$as_echo "$ac_cv_zstd_h" >&6; }
+    if test "$zstd_pkg_config" = yes \
+       && { test "$zstd_lib_usable" != yes || test "$ac_cv_zstd_h" != yes; }; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: pkg-config zstd is unusable; trying compiler search" >&5
+$as_echo "$as_me: pkg-config zstd is unusable; trying compiler search" >&6;}
+      zstd_pkg_config=no
+      ZSTD_CFLAGS=
+      ZSTD_LIBS=
+    else
+      break
+    fi
+  done
+  ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
+  if test "$zstd_lib_usable" = yes && test "$ac_cv_zstd_h" = yes; then
+
+$as_echo "#define HAVE_ZSTD 1" >>confdefs.h
+
+  elif test "$with_zstd" != auto; then
+    as_fn_error $? "Unable to find a usable zstd library and zstd.h.  See
+      config.log for details." "$LINENO" 5
+  else
+    # In auto mode, an unusable installation simply disables zstd.
+    zstd_enabled=no
+  fi
+
+  CFLAGS="$saved_CFLAGS"
+fi
+if test "$zstd_enabled" != yes; then
+  ZSTD_CFLAGS=
+  ZSTD_LIBS=
 fi
 
 
diff --git a/config/zstd.m4 b/config/zstd.m4
index eb34c0f36d7..28788782d3b 100644
--- a/config/zstd.m4
+++ b/config/zstd.m4
@@ -5,19 +5,129 @@ dnl Public License, this file may be distributed as part of a program
 dnl that contains a configuration script generated by Autoconf, under
 dnl the same distribution terms as the rest of that program.
 
-dnl Enable features using the zstd library.
+dnl Set up and check zstd support.
 AC_DEFUN([AC_ZSTD], [
+AC_SUBST(ZSTD_CFLAGS)
+AC_SUBST(ZSTD_LIBS)
 AC_ARG_WITH(zstd,
-  [AS_HELP_STRING([--with-zstd], [support zstd compressed debug sections (default=auto)])],
-  [], [with_zstd=auto])
-
-AS_IF([test "$with_zstd" != no],
-  [PKG_CHECK_MODULES(ZSTD, [libzstd >= 1.4.0], [
-    AC_DEFINE(HAVE_ZSTD, 1, [Define to 1 if zstd is enabled.])
-  ], [
-    if test "$with_zstd" = yes; then
-      AC_MSG_ERROR([--with-zstd was given, but pkgconfig/libzstd.pc is not found])
+  [AS_HELP_STRING([--with-zstd=VALUE],
+    [VALUE may be 'auto' (try pkg-config, then compiler search; default),
+      'yes' (require zstd), 'no' (disable it), or a PATH for the
+      installation prefix.  When VALUE is a PATH, this is equivalent to
+      --with-zstd-include=PATH/include and
+      --with-zstd-lib=PATH/lib])],
+  [with_zstd=$withval], [with_zstd=auto])
+AC_ARG_WITH(zstd-include,
+  [AS_HELP_STRING([--with-zstd-include=PATH],
+    [specify directory for installed zstd include files])])
+AC_ARG_WITH(zstd-lib,
+  [AS_HELP_STRING([--with-zstd-lib=PATH],
+    [specify directory for the installed zstd library])])
+zstd_enabled=no
+zstd_pkg_config=no
+zstd_use_pkg_config=no
+zstd_include_dir=
+zstd_library_dir=
+case "x$with_zstd" in
+  xno)
+    ;;
+  xyes|xauto)
+    zstd_enabled=yes
+    zstd_use_pkg_config=yes
+    ;;
+  *)
+    zstd_enabled=yes
+    zstd_include_dir=$with_zstd/include
+    zstd_library_dir=$with_zstd/lib
+    ;;
+esac
+
+if test "$zstd_use_pkg_config" = yes; then
+  PKG_CHECK_MODULES([ZSTD], [libzstd >= 1.4.0], [
+    zstd_pkg_config=yes
+  ], [:])
+fi
+
+if test "$zstd_enabled" = yes; then
+  saved_CFLAGS="$CFLAGS"
+  save_LIBS="$LIBS"
+  AC_LANG_PUSH([C])
+  while :; do
+    if test "x$with_zstd_include" != x; then
+      if test "$zstd_pkg_config" = yes; then
+	ZSTD_CFLAGS="-I$with_zstd_include $ZSTD_CFLAGS"
+      else
+	zstd_include_dir=$with_zstd_include
+      fi
+    fi
+    if test "x$with_zstd_lib" != x; then
+      zstd_library_dir=$with_zstd_lib
+    fi
+    if test "$zstd_pkg_config" != yes; then
+      ZSTD_CFLAGS=
+      ZSTD_LIBS=
+      if test "x$zstd_include_dir" != x \
+	 && test "x$zstd_include_dir" != xno; then
+	ZSTD_CFLAGS=-I$zstd_include_dir
+      fi
+    fi
+    if test "x$zstd_library_dir" != x \
+       && test "x$zstd_library_dir" != xno; then
+      ZSTD_LIBS="-L$zstd_library_dir $ZSTD_LIBS"
+    fi
+
+    CFLAGS="$saved_CFLAGS $ZSTD_CFLAGS"
+
+    # Check for a usable zstd library and header.  Ignore cached results
+    # that may have been obtained with different search flags.
+    unset ac_cv_search_ZSTD_compress ac_cv_zstd_h
+    zstd_lib_usable=no
+    LIBS="$ZSTD_LIBS $save_LIBS"
+
+    AC_SEARCH_LIBS([ZSTD_compress], [zstd],
+      [zstd_lib_usable=yes],
+      [zstd_lib_usable=no])
+    if test "$zstd_lib_usable" = yes \
+       && test "$ac_cv_search_ZSTD_compress" != "none required"; then
+      # Add the library only if AC_SEARCH_LIBS needed additional flags.
+      ZSTD_LIBS="$ac_cv_search_ZSTD_compress $ZSTD_LIBS"
     fi
-  ])
-  ])
+    LIBS="$save_LIBS"
+
+    AC_CACHE_CHECK([for zstd.h], [ac_cv_zstd_h],
+      [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+	#include <zstd.h>
+	#if ZSTD_VERSION_NUMBER < 10400
+	#error "need zstd 1.4.0 or better"
+	#endif
+      ]], [[]])],
+	[ac_cv_zstd_h=yes],
+	[ac_cv_zstd_h=no])])
+    if test "$zstd_pkg_config" = yes \
+       && { test "$zstd_lib_usable" != yes || test "$ac_cv_zstd_h" != yes; }; then
+      AC_MSG_NOTICE([pkg-config zstd is unusable; trying compiler search])
+      zstd_pkg_config=no
+      ZSTD_CFLAGS=
+      ZSTD_LIBS=
+    else
+      break
+    fi
+  done
+  AC_LANG_POP([C])
+  if test "$zstd_lib_usable" = yes && test "$ac_cv_zstd_h" = yes; then
+    AC_DEFINE(HAVE_ZSTD, 1, [Define if zstd is available.])
+  elif test "$with_zstd" != auto; then
+    AC_MSG_ERROR([Unable to find a usable zstd library and zstd.h.  See
+      config.log for details.])
+  else
+    # In auto mode, an unusable installation simply disables zstd.
+    zstd_enabled=no
+  fi
+
+  CFLAGS="$saved_CFLAGS"
+fi
+if test "$zstd_enabled" != yes; then
+  ZSTD_CFLAGS=
+  ZSTD_LIBS=
+fi
 ])
diff --git a/gas/configure b/gas/configure
index 8afaf2729ed..0edbdd4ec04 100755
--- a/gas/configure
+++ b/gas/configure
@@ -634,11 +634,11 @@ ac_subst_vars='am__EXEEXT_FALSE
 am__EXEEXT_TRUE
 LTLIBOBJS
 LIBOBJS
-ZSTD_LIBS
-ZSTD_CFLAGS
 PKG_CONFIG_LIBDIR
 PKG_CONFIG_PATH
 PKG_CONFIG
+ZSTD_LIBS
+ZSTD_CFLAGS
 zlibinc
 zlibdir
 LIBM
@@ -838,6 +838,8 @@ with_libintl_type
 enable_maintainer_mode
 with_system_zlib
 with_zstd
+with_zstd_include
+with_zstd_lib
 '
       ac_precious_vars='build_alias
 host_alias
@@ -1531,8 +1533,15 @@ Optional Packages:
   --without-libintl-prefix     don't search for libintl in includedir and libdir
   --with-libintl-type=TYPE     type of library to search for (auto/static/shared)
   --with-system-zlib      use installed libz
-  --with-zstd             support zstd compressed debug sections
-                          (default=auto)
+  --with-zstd=VALUE       VALUE may be 'auto' (try pkg-config, then compiler
+                          search; default), 'yes' (require zstd), 'no'
+                          (disable it), or a PATH for the installation prefix.
+                          When VALUE is a PATH, this is equivalent to
+                          --with-zstd-include=PATH/include and
+                          --with-zstd-lib=PATH/lib
+  --with-zstd-include=PATH
+                          specify directory for installed zstd include files
+  --with-zstd-lib=PATH    specify directory for the installed zstd library
 
 Some influential environment variables:
   CC          C compiler command
@@ -11152,7 +11161,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11155 "configure"
+#line 11164 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11258,7 +11267,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11261 "configure"
+#line 11270 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -16142,15 +16151,47 @@ $as_echo "no" >&6; }
 fi
 
 
+
+
 # Check whether --with-zstd was given.
 if test "${with_zstd+set}" = set; then :
-  withval=$with_zstd;
+  withval=$with_zstd; with_zstd=$withval
 else
   with_zstd=auto
 fi
 
 
-if test "$with_zstd" != no; then :
+# Check whether --with-zstd-include was given.
+if test "${with_zstd_include+set}" = set; then :
+  withval=$with_zstd_include;
+fi
+
+
+# Check whether --with-zstd-lib was given.
+if test "${with_zstd_lib+set}" = set; then :
+  withval=$with_zstd_lib;
+fi
+
+zstd_enabled=no
+zstd_pkg_config=no
+zstd_use_pkg_config=no
+zstd_include_dir=
+zstd_library_dir=
+case "x$with_zstd" in
+  xno)
+    ;;
+  xyes|xauto)
+    zstd_enabled=yes
+    zstd_use_pkg_config=yes
+    ;;
+  *)
+    zstd_enabled=yes
+    zstd_include_dir=$with_zstd/include
+    zstd_library_dir=$with_zstd/lib
+    ;;
+esac
+
+if test "$zstd_use_pkg_config" = yes; then
 
 pkg_failed=no
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libzstd >= 1.4.0" >&5
@@ -16234,31 +16275,192 @@ fi
 	# Put the nasty error message in config.log where it belongs
 	echo "$ZSTD_PKG_ERRORS" >&5
 
-
-    if test "$with_zstd" = yes; then
-      as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
-    fi
-
+	:
 elif test $pkg_failed = untried; then
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
-
-    if test "$with_zstd" = yes; then
-      as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
-    fi
-
+	:
 else
 	ZSTD_CFLAGS=$pkg_cv_ZSTD_CFLAGS
 	ZSTD_LIBS=$pkg_cv_ZSTD_LIBS
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 
+    zstd_pkg_config=yes
 
-$as_echo "#define HAVE_ZSTD 1" >>confdefs.h
+fi
+fi
 
+if test "$zstd_enabled" = yes; then
+  saved_CFLAGS="$CFLAGS"
+  save_LIBS="$LIBS"
+  ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+  while :; do
+    if test "x$with_zstd_include" != x; then
+      if test "$zstd_pkg_config" = yes; then
+	ZSTD_CFLAGS="-I$with_zstd_include $ZSTD_CFLAGS"
+      else
+	zstd_include_dir=$with_zstd_include
+      fi
+    fi
+    if test "x$with_zstd_lib" != x; then
+      zstd_library_dir=$with_zstd_lib
+    fi
+    if test "$zstd_pkg_config" != yes; then
+      ZSTD_CFLAGS=
+      ZSTD_LIBS=
+      if test "x$zstd_include_dir" != x \
+	 && test "x$zstd_include_dir" != xno; then
+	ZSTD_CFLAGS=-I$zstd_include_dir
+      fi
+    fi
+    if test "x$zstd_library_dir" != x \
+       && test "x$zstd_library_dir" != xno; then
+      ZSTD_LIBS="-L$zstd_library_dir $ZSTD_LIBS"
+    fi
+
+    CFLAGS="$saved_CFLAGS $ZSTD_CFLAGS"
 
+    # Check for a usable zstd library and header.  Ignore cached results
+    # that may have been obtained with different search flags.
+    unset ac_cv_search_ZSTD_compress ac_cv_zstd_h
+    zstd_lib_usable=no
+    LIBS="$ZSTD_LIBS $save_LIBS"
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing ZSTD_compress" >&5
+$as_echo_n "checking for library containing ZSTD_compress... " >&6; }
+if ${ac_cv_search_ZSTD_compress+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char ZSTD_compress ();
+int
+main ()
+{
+return ZSTD_compress ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' zstd; do
+  if test -z "$ac_lib"; then
+    ac_res="none required"
+  else
+    ac_res=-l$ac_lib
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_search_ZSTD_compress=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext
+  if ${ac_cv_search_ZSTD_compress+:} false; then :
+  break
+fi
+done
+if ${ac_cv_search_ZSTD_compress+:} false; then :
+
+else
+  ac_cv_search_ZSTD_compress=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_ZSTD_compress" >&5
+$as_echo "$ac_cv_search_ZSTD_compress" >&6; }
+ac_res=$ac_cv_search_ZSTD_compress
+if test "$ac_res" != no; then :
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+  zstd_lib_usable=yes
+else
+  zstd_lib_usable=no
+fi
+
+    if test "$zstd_lib_usable" = yes \
+       && test "$ac_cv_search_ZSTD_compress" != "none required"; then
+      # Add the library only if AC_SEARCH_LIBS needed additional flags.
+      ZSTD_LIBS="$ac_cv_search_ZSTD_compress $ZSTD_LIBS"
+    fi
+    LIBS="$save_LIBS"
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for zstd.h" >&5
+$as_echo_n "checking for zstd.h... " >&6; }
+if ${ac_cv_zstd_h+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+	#include <zstd.h>
+	#if ZSTD_VERSION_NUMBER < 10400
+	#error "need zstd 1.4.0 or better"
+	#endif
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_zstd_h=yes
+else
+  ac_cv_zstd_h=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
 fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_zstd_h" >&5
+$as_echo "$ac_cv_zstd_h" >&6; }
+    if test "$zstd_pkg_config" = yes \
+       && { test "$zstd_lib_usable" != yes || test "$ac_cv_zstd_h" != yes; }; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: pkg-config zstd is unusable; trying compiler search" >&5
+$as_echo "$as_me: pkg-config zstd is unusable; trying compiler search" >&6;}
+      zstd_pkg_config=no
+      ZSTD_CFLAGS=
+      ZSTD_LIBS=
+    else
+      break
+    fi
+  done
+  ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
+  if test "$zstd_lib_usable" = yes && test "$ac_cv_zstd_h" = yes; then
+
+$as_echo "#define HAVE_ZSTD 1" >>confdefs.h
+
+  elif test "$with_zstd" != auto; then
+    as_fn_error $? "Unable to find a usable zstd library and zstd.h.  See
+      config.log for details." "$LINENO" 5
+  else
+    # In auto mode, an unusable installation simply disables zstd.
+    zstd_enabled=no
+  fi
+
+  CFLAGS="$saved_CFLAGS"
+fi
+if test "$zstd_enabled" != yes; then
+  ZSTD_CFLAGS=
+  ZSTD_LIBS=
 fi
 
 
diff --git a/gdb/configure b/gdb/configure
index 810e9ed7a37..78b79b7c3b2 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -946,6 +946,8 @@ with_pkgversion
 with_bugurl
 with_system_zlib
 with_zstd
+with_zstd_include
+with_zstd_lib
 with_iconv_bin
 with_system_readline
 with_jit_reader_dir
@@ -1721,8 +1723,15 @@ Optional Packages:
   --with-pkgversion=PKG   Use PKG in the version string in place of "GDB"
   --with-bugurl=URL       Direct users to URL to report a bug
   --with-system-zlib      use installed libz
-  --with-zstd             support zstd compressed debug sections
-                          (default=auto)
+  --with-zstd=VALUE       VALUE may be 'auto' (try pkg-config, then compiler
+                          search; default), 'yes' (require zstd), 'no'
+                          (disable it), or a PATH for the installation prefix.
+                          When VALUE is a PATH, this is equivalent to
+                          --with-zstd-include=PATH/include and
+                          --with-zstd-lib=PATH/lib
+  --with-zstd-include=PATH
+                          specify directory for installed zstd include files
+  --with-zstd-lib=PATH    specify directory for the installed zstd library
   --with-iconv-bin=PATH   specify where to find the iconv program
   --with-system-readline  use installed readline library
   --with-jit-reader-dir=PATH
@@ -11877,7 +11886,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11880 "configure"
+#line 11889 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -11983,7 +11992,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11986 "configure"
+#line 11995 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -26715,15 +26724,47 @@ fi
 
 
 
+
+
 # Check whether --with-zstd was given.
 if test "${with_zstd+set}" = set; then :
-  withval=$with_zstd;
+  withval=$with_zstd; with_zstd=$withval
 else
   with_zstd=auto
 fi
 
 
-if test "$with_zstd" != no; then :
+# Check whether --with-zstd-include was given.
+if test "${with_zstd_include+set}" = set; then :
+  withval=$with_zstd_include;
+fi
+
+
+# Check whether --with-zstd-lib was given.
+if test "${with_zstd_lib+set}" = set; then :
+  withval=$with_zstd_lib;
+fi
+
+zstd_enabled=no
+zstd_pkg_config=no
+zstd_use_pkg_config=no
+zstd_include_dir=
+zstd_library_dir=
+case "x$with_zstd" in
+  xno)
+    ;;
+  xyes|xauto)
+    zstd_enabled=yes
+    zstd_use_pkg_config=yes
+    ;;
+  *)
+    zstd_enabled=yes
+    zstd_include_dir=$with_zstd/include
+    zstd_library_dir=$with_zstd/lib
+    ;;
+esac
+
+if test "$zstd_use_pkg_config" = yes; then
 
 pkg_failed=no
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libzstd >= 1.4.0" >&5
@@ -26807,31 +26848,192 @@ fi
 	# Put the nasty error message in config.log where it belongs
 	echo "$ZSTD_PKG_ERRORS" >&5
 
-
-    if test "$with_zstd" = yes; then
-      as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
-    fi
-
+	:
 elif test $pkg_failed = untried; then
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
-
-    if test "$with_zstd" = yes; then
-      as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
-    fi
-
+	:
 else
 	ZSTD_CFLAGS=$pkg_cv_ZSTD_CFLAGS
 	ZSTD_LIBS=$pkg_cv_ZSTD_LIBS
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 
+    zstd_pkg_config=yes
 
-$as_echo "#define HAVE_ZSTD 1" >>confdefs.h
+fi
+fi
+
+if test "$zstd_enabled" = yes; then
+  saved_CFLAGS="$CFLAGS"
+  save_LIBS="$LIBS"
+  ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+  while :; do
+    if test "x$with_zstd_include" != x; then
+      if test "$zstd_pkg_config" = yes; then
+	ZSTD_CFLAGS="-I$with_zstd_include $ZSTD_CFLAGS"
+      else
+	zstd_include_dir=$with_zstd_include
+      fi
+    fi
+    if test "x$with_zstd_lib" != x; then
+      zstd_library_dir=$with_zstd_lib
+    fi
+    if test "$zstd_pkg_config" != yes; then
+      ZSTD_CFLAGS=
+      ZSTD_LIBS=
+      if test "x$zstd_include_dir" != x \
+	 && test "x$zstd_include_dir" != xno; then
+	ZSTD_CFLAGS=-I$zstd_include_dir
+      fi
+    fi
+    if test "x$zstd_library_dir" != x \
+       && test "x$zstd_library_dir" != xno; then
+      ZSTD_LIBS="-L$zstd_library_dir $ZSTD_LIBS"
+    fi
+
+    CFLAGS="$saved_CFLAGS $ZSTD_CFLAGS"
+
+    # Check for a usable zstd library and header.  Ignore cached results
+    # that may have been obtained with different search flags.
+    unset ac_cv_search_ZSTD_compress ac_cv_zstd_h
+    zstd_lib_usable=no
+    LIBS="$ZSTD_LIBS $save_LIBS"
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing ZSTD_compress" >&5
+$as_echo_n "checking for library containing ZSTD_compress... " >&6; }
+if ${ac_cv_search_ZSTD_compress+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char ZSTD_compress ();
+int
+main ()
+{
+return ZSTD_compress ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' zstd; do
+  if test -z "$ac_lib"; then
+    ac_res="none required"
+  else
+    ac_res=-l$ac_lib
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_search_ZSTD_compress=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext
+  if ${ac_cv_search_ZSTD_compress+:} false; then :
+  break
+fi
+done
+if ${ac_cv_search_ZSTD_compress+:} false; then :
 
+else
+  ac_cv_search_ZSTD_compress=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_ZSTD_compress" >&5
+$as_echo "$ac_cv_search_ZSTD_compress" >&6; }
+ac_res=$ac_cv_search_ZSTD_compress
+if test "$ac_res" != no; then :
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+  zstd_lib_usable=yes
+else
+  zstd_lib_usable=no
+fi
 
+    if test "$zstd_lib_usable" = yes \
+       && test "$ac_cv_search_ZSTD_compress" != "none required"; then
+      # Add the library only if AC_SEARCH_LIBS needed additional flags.
+      ZSTD_LIBS="$ac_cv_search_ZSTD_compress $ZSTD_LIBS"
+    fi
+    LIBS="$save_LIBS"
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for zstd.h" >&5
+$as_echo_n "checking for zstd.h... " >&6; }
+if ${ac_cv_zstd_h+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+	#include <zstd.h>
+	#if ZSTD_VERSION_NUMBER < 10400
+	#error "need zstd 1.4.0 or better"
+	#endif
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_zstd_h=yes
+else
+  ac_cv_zstd_h=no
 fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_zstd_h" >&5
+$as_echo "$ac_cv_zstd_h" >&6; }
+    if test "$zstd_pkg_config" = yes \
+       && { test "$zstd_lib_usable" != yes || test "$ac_cv_zstd_h" != yes; }; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: pkg-config zstd is unusable; trying compiler search" >&5
+$as_echo "$as_me: pkg-config zstd is unusable; trying compiler search" >&6;}
+      zstd_pkg_config=no
+      ZSTD_CFLAGS=
+      ZSTD_LIBS=
+    else
+      break
+    fi
+  done
+  ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
+  if test "$zstd_lib_usable" = yes && test "$ac_cv_zstd_h" = yes; then
+
+$as_echo "#define HAVE_ZSTD 1" >>confdefs.h
+
+  elif test "$with_zstd" != auto; then
+    as_fn_error $? "Unable to find a usable zstd library and zstd.h.  See
+      config.log for details." "$LINENO" 5
+  else
+    # In auto mode, an unusable installation simply disables zstd.
+    zstd_enabled=no
+  fi
+
+  CFLAGS="$saved_CFLAGS"
+fi
+if test "$zstd_enabled" != yes; then
+  ZSTD_CFLAGS=
+  ZSTD_LIBS=
 fi
 
 
diff --git a/gold/configure b/gold/configure
index a81a04f0531..e159551e389 100755
--- a/gold/configure
+++ b/gold/configure
@@ -644,11 +644,11 @@ ax_pthread_config
 SED
 HAVE_ZSTD_FALSE
 HAVE_ZSTD_TRUE
-ZSTD_LIBS
-ZSTD_CFLAGS
 PKG_CONFIG_LIBDIR
 PKG_CONFIG_PATH
 PKG_CONFIG
+ZSTD_LIBS
+ZSTD_CFLAGS
 zlibinc
 zlibdir
 LIBOBJS
@@ -873,6 +873,8 @@ with_gold_ldflags
 with_gold_ldadd
 with_system_zlib
 with_zstd
+with_zstd_include
+with_zstd_lib
 enable_threads
 enable_jansson
 enable_maintainer_mode
@@ -1555,8 +1557,15 @@ Optional Packages:
   --with-gold-ldflags=FLAGS  additional link flags for gold
   --with-gold-ldadd=LIBS     additional libraries for gold
   --with-system-zlib      use installed libz
-  --with-zstd             support zstd compressed debug sections
-                          (default=auto)
+  --with-zstd=VALUE       VALUE may be 'auto' (try pkg-config, then compiler
+                          search; default), 'yes' (require zstd), 'no'
+                          (disable it), or a PATH for the installation prefix.
+                          When VALUE is a PATH, this is equivalent to
+                          --with-zstd-include=PATH/include and
+                          --with-zstd-lib=PATH/lib
+  --with-zstd-include=PATH
+                          specify directory for installed zstd include files
+  --with-zstd-lib=PATH    specify directory for the installed zstd library
 
 Some influential environment variables:
   CC          C compiler command
@@ -9989,15 +9998,47 @@ $as_echo "no" >&6; }
 fi
 
 
+
+
 # Check whether --with-zstd was given.
 if test "${with_zstd+set}" = set; then :
-  withval=$with_zstd;
+  withval=$with_zstd; with_zstd=$withval
 else
   with_zstd=auto
 fi
 
 
-if test "$with_zstd" != no; then :
+# Check whether --with-zstd-include was given.
+if test "${with_zstd_include+set}" = set; then :
+  withval=$with_zstd_include;
+fi
+
+
+# Check whether --with-zstd-lib was given.
+if test "${with_zstd_lib+set}" = set; then :
+  withval=$with_zstd_lib;
+fi
+
+zstd_enabled=no
+zstd_pkg_config=no
+zstd_use_pkg_config=no
+zstd_include_dir=
+zstd_library_dir=
+case "x$with_zstd" in
+  xno)
+    ;;
+  xyes|xauto)
+    zstd_enabled=yes
+    zstd_use_pkg_config=yes
+    ;;
+  *)
+    zstd_enabled=yes
+    zstd_include_dir=$with_zstd/include
+    zstd_library_dir=$with_zstd/lib
+    ;;
+esac
+
+if test "$zstd_use_pkg_config" = yes; then
 
 pkg_failed=no
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libzstd >= 1.4.0" >&5
@@ -10081,34 +10122,195 @@ fi
 	# Put the nasty error message in config.log where it belongs
 	echo "$ZSTD_PKG_ERRORS" >&5
 
-
-    if test "$with_zstd" = yes; then
-      as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
-    fi
-
+	:
 elif test $pkg_failed = untried; then
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
-
-    if test "$with_zstd" = yes; then
-      as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
-    fi
-
+	:
 else
 	ZSTD_CFLAGS=$pkg_cv_ZSTD_CFLAGS
 	ZSTD_LIBS=$pkg_cv_ZSTD_LIBS
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 
+    zstd_pkg_config=yes
 
-$as_echo "#define HAVE_ZSTD 1" >>confdefs.h
+fi
+fi
+
+if test "$zstd_enabled" = yes; then
+  saved_CFLAGS="$CFLAGS"
+  save_LIBS="$LIBS"
+  ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
+  while :; do
+    if test "x$with_zstd_include" != x; then
+      if test "$zstd_pkg_config" = yes; then
+	ZSTD_CFLAGS="-I$with_zstd_include $ZSTD_CFLAGS"
+      else
+	zstd_include_dir=$with_zstd_include
+      fi
+    fi
+    if test "x$with_zstd_lib" != x; then
+      zstd_library_dir=$with_zstd_lib
+    fi
+    if test "$zstd_pkg_config" != yes; then
+      ZSTD_CFLAGS=
+      ZSTD_LIBS=
+      if test "x$zstd_include_dir" != x \
+	 && test "x$zstd_include_dir" != xno; then
+	ZSTD_CFLAGS=-I$zstd_include_dir
+      fi
+    fi
+    if test "x$zstd_library_dir" != x \
+       && test "x$zstd_library_dir" != xno; then
+      ZSTD_LIBS="-L$zstd_library_dir $ZSTD_LIBS"
+    fi
+
+    CFLAGS="$saved_CFLAGS $ZSTD_CFLAGS"
+
+    # Check for a usable zstd library and header.  Ignore cached results
+    # that may have been obtained with different search flags.
+    unset ac_cv_search_ZSTD_compress ac_cv_zstd_h
+    zstd_lib_usable=no
+    LIBS="$ZSTD_LIBS $save_LIBS"
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing ZSTD_compress" >&5
+$as_echo_n "checking for library containing ZSTD_compress... " >&6; }
+if ${ac_cv_search_ZSTD_compress+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
 
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char ZSTD_compress ();
+int
+main ()
+{
+return ZSTD_compress ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' zstd; do
+  if test -z "$ac_lib"; then
+    ac_res="none required"
+  else
+    ac_res=-l$ac_lib
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_search_ZSTD_compress=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext
+  if ${ac_cv_search_ZSTD_compress+:} false; then :
+  break
+fi
+done
+if ${ac_cv_search_ZSTD_compress+:} false; then :
+
+else
+  ac_cv_search_ZSTD_compress=no
 fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_ZSTD_compress" >&5
+$as_echo "$ac_cv_search_ZSTD_compress" >&6; }
+ac_res=$ac_cv_search_ZSTD_compress
+if test "$ac_res" != no; then :
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+  zstd_lib_usable=yes
+else
+  zstd_lib_usable=no
+fi
+
+    if test "$zstd_lib_usable" = yes \
+       && test "$ac_cv_search_ZSTD_compress" != "none required"; then
+      # Add the library only if AC_SEARCH_LIBS needed additional flags.
+      ZSTD_LIBS="$ac_cv_search_ZSTD_compress $ZSTD_LIBS"
+    fi
+    LIBS="$save_LIBS"
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for zstd.h" >&5
+$as_echo_n "checking for zstd.h... " >&6; }
+if ${ac_cv_zstd_h+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+	#include <zstd.h>
+	#if ZSTD_VERSION_NUMBER < 10400
+	#error "need zstd 1.4.0 or better"
+	#endif
 
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_zstd_h=yes
+else
+  ac_cv_zstd_h=no
+fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_zstd_h" >&5
+$as_echo "$ac_cv_zstd_h" >&6; }
+    if test "$zstd_pkg_config" = yes \
+       && { test "$zstd_lib_usable" != yes || test "$ac_cv_zstd_h" != yes; }; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: pkg-config zstd is unusable; trying compiler search" >&5
+$as_echo "$as_me: pkg-config zstd is unusable; trying compiler search" >&6;}
+      zstd_pkg_config=no
+      ZSTD_CFLAGS=
+      ZSTD_LIBS=
+    else
+      break
+    fi
+  done
+  ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
+
+  if test "$zstd_lib_usable" = yes && test "$ac_cv_zstd_h" = yes; then
+
+$as_echo "#define HAVE_ZSTD 1" >>confdefs.h
+
+  elif test "$with_zstd" != auto; then
+    as_fn_error $? "Unable to find a usable zstd library and zstd.h.  See
+      config.log for details." "$LINENO" 5
+  else
+    # In auto mode, an unusable installation simply disables zstd.
+    zstd_enabled=no
+  fi
+
+  CFLAGS="$saved_CFLAGS"
+fi
+if test "$zstd_enabled" != yes; then
+  ZSTD_CFLAGS=
+  ZSTD_LIBS=
 fi
 
- if test "$pkg_cv_ZSTD_LIBS" != ""; then
+ if test "$zstd_enabled" = yes; then
   HAVE_ZSTD_TRUE=
   HAVE_ZSTD_FALSE='#'
 else
diff --git a/gold/configure.ac b/gold/configure.ac
index fe6ace01693..89348b660be 100644
--- a/gold/configure.ac
+++ b/gold/configure.ac
@@ -566,7 +566,7 @@ fi
 # Link in zlib/zstd if we can.  This allows us to write compressed sections.
 AM_ZLIB
 AC_ZSTD
-AM_CONDITIONAL(HAVE_ZSTD, test "$pkg_cv_ZSTD_LIBS" != "")
+AM_CONDITIONAL(HAVE_ZSTD, test "$zstd_enabled" = yes)
 
 AC_ARG_ENABLE([threads],
 [[  --enable-threads[=ARG]  multi-threaded linking [ARG={auto,yes,no}]]],
diff --git a/ld/configure b/ld/configure
index 4d755384c41..5f5c8d311dc 100755
--- a/ld/configure
+++ b/ld/configure
@@ -877,6 +877,8 @@ with_libintl_type
 with_xxhash
 with_system_zlib
 with_zstd
+with_zstd_include
+with_zstd_lib
 '
       ac_precious_vars='build_alias
 host_alias
@@ -1598,8 +1600,15 @@ Optional Packages:
   --with-xxhash           use inlined libxxhash for hashing (faster)
                           (auto/yes/no)
   --with-system-zlib      use installed libz
-  --with-zstd             support zstd compressed debug sections
-                          (default=auto)
+  --with-zstd=VALUE       VALUE may be 'auto' (try pkg-config, then compiler
+                          search; default), 'yes' (require zstd), 'no'
+                          (disable it), or a PATH for the installation prefix.
+                          When VALUE is a PATH, this is equivalent to
+                          --with-zstd-include=PATH/include and
+                          --with-zstd-lib=PATH/lib
+  --with-zstd-include=PATH
+                          specify directory for installed zstd include files
+  --with-zstd-lib=PATH    specify directory for the installed zstd library
 
 Some influential environment variables:
   CC          C compiler command
@@ -11894,7 +11903,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 11897 "configure"
+#line 11906 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12000,7 +12009,7 @@ else
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<_LT_EOF
-#line 12003 "configure"
+#line 12012 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -19080,15 +19089,47 @@ fi
 
 
 
+
+
 # Check whether --with-zstd was given.
 if test "${with_zstd+set}" = set; then :
-  withval=$with_zstd;
+  withval=$with_zstd; with_zstd=$withval
 else
   with_zstd=auto
 fi
 
 
-if test "$with_zstd" != no; then :
+# Check whether --with-zstd-include was given.
+if test "${with_zstd_include+set}" = set; then :
+  withval=$with_zstd_include;
+fi
+
+
+# Check whether --with-zstd-lib was given.
+if test "${with_zstd_lib+set}" = set; then :
+  withval=$with_zstd_lib;
+fi
+
+zstd_enabled=no
+zstd_pkg_config=no
+zstd_use_pkg_config=no
+zstd_include_dir=
+zstd_library_dir=
+case "x$with_zstd" in
+  xno)
+    ;;
+  xyes|xauto)
+    zstd_enabled=yes
+    zstd_use_pkg_config=yes
+    ;;
+  *)
+    zstd_enabled=yes
+    zstd_include_dir=$with_zstd/include
+    zstd_library_dir=$with_zstd/lib
+    ;;
+esac
+
+if test "$zstd_use_pkg_config" = yes; then
 
 pkg_failed=no
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for libzstd >= 1.4.0" >&5
@@ -19172,31 +19213,192 @@ fi
 	# Put the nasty error message in config.log where it belongs
 	echo "$ZSTD_PKG_ERRORS" >&5
 
-
-    if test "$with_zstd" = yes; then
-      as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
-    fi
-
+	:
 elif test $pkg_failed = untried; then
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
 $as_echo "no" >&6; }
-
-    if test "$with_zstd" = yes; then
-      as_fn_error $? "--with-zstd was given, but pkgconfig/libzstd.pc is not found" "$LINENO" 5
-    fi
-
+	:
 else
 	ZSTD_CFLAGS=$pkg_cv_ZSTD_CFLAGS
 	ZSTD_LIBS=$pkg_cv_ZSTD_LIBS
         { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
 $as_echo "yes" >&6; }
 
+    zstd_pkg_config=yes
 
-$as_echo "#define HAVE_ZSTD 1" >>confdefs.h
+fi
+fi
 
+if test "$zstd_enabled" = yes; then
+  saved_CFLAGS="$CFLAGS"
+  save_LIBS="$LIBS"
+  ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
+  while :; do
+    if test "x$with_zstd_include" != x; then
+      if test "$zstd_pkg_config" = yes; then
+	ZSTD_CFLAGS="-I$with_zstd_include $ZSTD_CFLAGS"
+      else
+	zstd_include_dir=$with_zstd_include
+      fi
+    fi
+    if test "x$with_zstd_lib" != x; then
+      zstd_library_dir=$with_zstd_lib
+    fi
+    if test "$zstd_pkg_config" != yes; then
+      ZSTD_CFLAGS=
+      ZSTD_LIBS=
+      if test "x$zstd_include_dir" != x \
+	 && test "x$zstd_include_dir" != xno; then
+	ZSTD_CFLAGS=-I$zstd_include_dir
+      fi
+    fi
+    if test "x$zstd_library_dir" != x \
+       && test "x$zstd_library_dir" != xno; then
+      ZSTD_LIBS="-L$zstd_library_dir $ZSTD_LIBS"
+    fi
+
+    CFLAGS="$saved_CFLAGS $ZSTD_CFLAGS"
+
+    # Check for a usable zstd library and header.  Ignore cached results
+    # that may have been obtained with different search flags.
+    unset ac_cv_search_ZSTD_compress ac_cv_zstd_h
+    zstd_lib_usable=no
+    LIBS="$ZSTD_LIBS $save_LIBS"
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing ZSTD_compress" >&5
+$as_echo_n "checking for library containing ZSTD_compress... " >&6; }
+if ${ac_cv_search_ZSTD_compress+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char ZSTD_compress ();
+int
+main ()
+{
+return ZSTD_compress ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' zstd; do
+  if test -z "$ac_lib"; then
+    ac_res="none required"
+  else
+    ac_res=-l$ac_lib
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  if ac_fn_c_try_link "$LINENO"; then :
+  ac_cv_search_ZSTD_compress=$ac_res
+fi
+rm -f core conftest.err conftest.$ac_objext \
+    conftest$ac_exeext
+  if ${ac_cv_search_ZSTD_compress+:} false; then :
+  break
+fi
+done
+if ${ac_cv_search_ZSTD_compress+:} false; then :
+
+else
+  ac_cv_search_ZSTD_compress=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_ZSTD_compress" >&5
+$as_echo "$ac_cv_search_ZSTD_compress" >&6; }
+ac_res=$ac_cv_search_ZSTD_compress
+if test "$ac_res" != no; then :
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+  zstd_lib_usable=yes
+else
+  zstd_lib_usable=no
+fi
+
+    if test "$zstd_lib_usable" = yes \
+       && test "$ac_cv_search_ZSTD_compress" != "none required"; then
+      # Add the library only if AC_SEARCH_LIBS needed additional flags.
+      ZSTD_LIBS="$ac_cv_search_ZSTD_compress $ZSTD_LIBS"
+    fi
+    LIBS="$save_LIBS"
+
+    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for zstd.h" >&5
+$as_echo_n "checking for zstd.h... " >&6; }
+if ${ac_cv_zstd_h+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+	#include <zstd.h>
+	#if ZSTD_VERSION_NUMBER < 10400
+	#error "need zstd 1.4.0 or better"
+	#endif
+
+int
+main ()
+{
+
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_compile "$LINENO"; then :
+  ac_cv_zstd_h=yes
+else
+  ac_cv_zstd_h=no
 fi
+rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_zstd_h" >&5
+$as_echo "$ac_cv_zstd_h" >&6; }
+    if test "$zstd_pkg_config" = yes \
+       && { test "$zstd_lib_usable" != yes || test "$ac_cv_zstd_h" != yes; }; then
+      { $as_echo "$as_me:${as_lineno-$LINENO}: pkg-config zstd is unusable; trying compiler search" >&5
+$as_echo "$as_me: pkg-config zstd is unusable; trying compiler search" >&6;}
+      zstd_pkg_config=no
+      ZSTD_CFLAGS=
+      ZSTD_LIBS=
+    else
+      break
+    fi
+  done
+  ac_ext=c
+ac_cpp='$CPP $CPPFLAGS'
+ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
+  if test "$zstd_lib_usable" = yes && test "$ac_cv_zstd_h" = yes; then
+
+$as_echo "#define HAVE_ZSTD 1" >>confdefs.h
+
+  elif test "$with_zstd" != auto; then
+    as_fn_error $? "Unable to find a usable zstd library and zstd.h.  See
+      config.log for details." "$LINENO" 5
+  else
+    # In auto mode, an unusable installation simply disables zstd.
+    zstd_enabled=no
+  fi
+
+  CFLAGS="$saved_CFLAGS"
+fi
+if test "$zstd_enabled" != yes; then
+  ZSTD_CFLAGS=
+  ZSTD_LIBS=
 fi
 
 
-- 
2.43.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3] configure: Sync zstd detection with GCC
  2026-10-20 17:40   ` [PATCH v3] configure: Sync zstd detection with GCC Torbjörn SVENSSON
@ 2026-10-21  6:56     ` Alan Modra
  2026-10-21  8:13       ` Torbjorn SVENSSON
  0 siblings, 1 reply; 7+ messages in thread
From: Alan Modra @ 2026-10-21  6:56 UTC (permalink / raw)
  To: Torbjörn SVENSSON; +Cc: binutils, gdb-patches, simark

On Tue, Oct 20, 2026 at 07:40:58PM +0200, Torbjörn SVENSSON wrote:
> Sync config/zstd.m4 with GCC to support compiler-based detection and
> configurable zstd search paths.
> 
> Add ZSTD_LIBS to binutils link commands for tools using zstd through
> BFD.  Base gold's zstd test conditional on the final detection result
> rather than pkg-config flags.
> 
> Regenerate the affected configure scripts and binutils Makefile.in.

The regen missed some files, and didn't apply cleanly.  I've taken the
substance of your patch, ie. binutils/Makefile.am, config/zstd.m4 and
gold/configure.ac changes, and regenerated the rest.

binutils/Makefile.in testsuite_gentestdlls_DEPENDENCIES looks odd but
harmless.  I don't intend to go down that rabbit hole trying to
figure out why.

-- 
Alan Modra

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3] configure: Sync zstd detection with GCC
  2026-10-21  6:56     ` Alan Modra
@ 2026-10-21  8:13       ` Torbjorn SVENSSON
  2026-10-21 11:23         ` Alan Modra
  0 siblings, 1 reply; 7+ messages in thread
From: Torbjorn SVENSSON @ 2026-10-21  8:13 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils, gdb-patches, simark



On 2026-10-21 08:56, Alan Modra wrote:
> On Tue, Oct 20, 2026 at 07:40:58PM +0200, Torbjörn SVENSSON wrote:
>> Sync config/zstd.m4 with GCC to support compiler-based detection and
>> configurable zstd search paths.
>>
>> Add ZSTD_LIBS to binutils link commands for tools using zstd through
>> BFD.  Base gold's zstd test conditional on the final detection result
>> rather than pkg-config flags.
>>
>> Regenerate the affected configure scripts and binutils Makefile.in.
> 
> The regen missed some files, and didn't apply cleanly.  I've taken the
> substance of your patch, ie. binutils/Makefile.am, config/zstd.m4 and
> gold/configure.ac changes, and regenerated the rest.

Thank you Alan for fixing. For next time, what command did you run to
generate all the resources that were missed?

Kind regards,
Torbjörn

> 
> binutils/Makefile.in testsuite_gentestdlls_DEPENDENCIES looks odd but
> harmless.  I don't intend to go down that rabbit hole trying to
> figure out why.
> 


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3] configure: Sync zstd detection with GCC
  2026-10-21  8:13       ` Torbjorn SVENSSON
@ 2026-10-21 11:23         ` Alan Modra
  2026-10-21 11:24           ` Torbjorn SVENSSON
  0 siblings, 1 reply; 7+ messages in thread
From: Alan Modra @ 2026-10-21 11:23 UTC (permalink / raw)
  To: Torbjorn SVENSSON; +Cc: binutils, gdb-patches, simark

On Wed, Oct 21, 2026 at 10:13:16AM +0200, Torbjorn SVENSSON wrote:
> Thank you Alan for fixing. For next time, what command did you run to
> generate all the resources that were missed?

I configure with --enable-maintainer-mode.

-- 
Alan Modra

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v3] configure: Sync zstd detection with GCC
  2026-10-21 11:23         ` Alan Modra
@ 2026-10-21 11:24           ` Torbjorn SVENSSON
  0 siblings, 0 replies; 7+ messages in thread
From: Torbjorn SVENSSON @ 2026-10-21 11:24 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils, gdb-patches, simark



On 2026-10-21 13:23, Alan Modra wrote:
> On Wed, Oct 21, 2026 at 10:13:16AM +0200, Torbjorn SVENSSON wrote:
>> Thank you Alan for fixing. For next time, what command did you run to
>> generate all the resources that were missed?
> 
> I configure with --enable-maintainer-mode.
> 

Okay. I'll try to remember to do that next time.

Kind regards,
Torbjörn


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-10-21 11:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-28  5:30 [PATCH v2] configure: Support --with-zstd=PATH Torbjörn SVENSSON
2026-09-29  2:00 ` Simon Marchi
2026-10-20 17:40   ` [PATCH v3] configure: Sync zstd detection with GCC Torbjörn SVENSSON
2026-10-21  6:56     ` Alan Modra
2026-10-21  8:13       ` Torbjorn SVENSSON
2026-10-21 11:23         ` Alan Modra
2026-10-21 11:24           ` Torbjorn SVENSSON

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox