Skip to content

Commit d615358

Browse files
committed
Merge zstd support from upstream
1 parent 2495b1c commit d615358

8 files changed

Lines changed: 3705 additions & 326 deletions

File tree

Makefile.am

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ check_DATA += allocfail.dSYM
250250
endif USE_DSYMUTIL
251251

252252
if HAVE_ELF
253+
if HAVE_BUILDID
253254
if HAVE_OBJCOPY_DEBUGLINK
254255

255256
b2test_SOURCES = $(btest_SOURCES)
@@ -273,6 +274,7 @@ MAKETESTS += b3test_dwz_buildid
273274
endif HAVE_DWZ
274275

275276
endif HAVE_OBJCOPY_DEBUGLINK
277+
endif HAVE_BUILDID
276278
endif HAVE_ELF
277279

278280
btest_SOURCES = btest.c testlib.c
@@ -374,6 +376,25 @@ ztest_alloc_CFLAGS = $(ztest_CFLAGS)
374376

375377
BUILDTESTS += ztest_alloc
376378

379+
zstdtest_SOURCES = zstdtest.c testlib.c
380+
zstdtest_CFLAGS = $(libbacktrace_TEST_CFLAGS) -DSRCDIR=\"$(srcdir)\"
381+
zstdtest_LDADD = libbacktrace.la
382+
zstdtest_alloc_LDADD = libbacktrace_alloc.la
383+
384+
if HAVE_ZSTD
385+
zstdtest_LDADD += -lzstd
386+
zstdtest_alloc_LDADD += -lzstd
387+
endif
388+
zstdtest_LDADD += $(CLOCK_GETTIME_LINK)
389+
zstdtest_alloc_LDADD += $(CLOCK_GETTIME_LINK)
390+
391+
BUILDTESTS += zstdtest
392+
393+
zstdtest_alloc_SOURCES = $(zstdtest_SOURCES)
394+
zstdtest_alloc_CFLAGS = $(zstdtest_CFLAGS)
395+
396+
BUILDTESTS += zstdtest_alloc
397+
377398
endif HAVE_ELF
378399

379400
edtest_SOURCES = edtest.c edtest2_build.c testlib.c
@@ -458,6 +479,17 @@ ctesta_LDADD = libbacktrace.la
458479

459480
BUILDTESTS += ctestg ctesta
460481

482+
if HAVE_COMPRESSED_DEBUG_ZSTD
483+
484+
ctestzstd_SOURCES = btest.c testlib.c
485+
ctestzstd_CFLAGS = $(libbacktrace_TEST_CFLAGS)
486+
ctestzstd_LDFLAGS = -Wl,--compress-debug-sections=zstd
487+
ctestzstd_LDADD = libbacktrace.la
488+
489+
BUILDTESTS += ctestzstd
490+
491+
endif
492+
461493
ctestg_alloc_SOURCES = $(ctestg_SOURCES)
462494
ctestg_alloc_CFLAGS = $(ctestg_CFLAGS)
463495
ctestg_alloc_LDFLAGS = $(ctestg_LDFLAGS)

Makefile.in

Lines changed: 178 additions & 56 deletions
Large diffs are not rendered by default.

config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@
103103
/* Define if -lz is available. */
104104
#undef HAVE_ZLIB
105105

106+
/* Define if -lzstd is available. */
107+
#undef HAVE_ZSTD
108+
106109
/* Define to the sub-directory in which libtool stores uninstalled libraries.
107110
*/
108111
#undef LT_OBJDIR

configure

Lines changed: 147 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,14 @@ HAVE_OBJCOPY_DEBUGLINK_FALSE
651651
HAVE_OBJCOPY_DEBUGLINK_TRUE
652652
READELF
653653
OBJCOPY
654+
HAVE_COMPRESSED_DEBUG_ZSTD_FALSE
655+
HAVE_COMPRESSED_DEBUG_ZSTD_TRUE
656+
HAVE_ZSTD_FALSE
657+
HAVE_ZSTD_TRUE
654658
HAVE_COMPRESSED_DEBUG_FALSE
655659
HAVE_COMPRESSED_DEBUG_TRUE
660+
HAVE_BUILDID_FALSE
661+
HAVE_BUILDID_TRUE
656662
HAVE_ZLIB_FALSE
657663
HAVE_ZLIB_TRUE
658664
HAVE_DWARF5_FALSE
@@ -11272,7 +11278,7 @@ else
1127211278
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
1127311279
lt_status=$lt_dlunknown
1127411280
cat > conftest.$ac_ext <<_LT_EOF
11275-
#line 11275 "configure"
11281+
#line 11281 "configure"
1127611282
#include "confdefs.h"
1127711283
1127811284
#if HAVE_DLFCN_H
@@ -11378,7 +11384,7 @@ else
1137811384
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
1137911385
lt_status=$lt_dlunknown
1138011386
cat > conftest.$ac_ext <<_LT_EOF
11381-
#line 11381 "configure"
11387+
#line 11387 "configure"
1138211388
#include "confdefs.h"
1138311389
1138411390
#if HAVE_DLFCN_H
@@ -12770,6 +12776,44 @@ else
1277012776
fi
1277112777
1277212778
12779+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether --build-id is supported" >&5
12780+
$as_echo_n "checking whether --build-id is supported... " >&6; }
12781+
if ${libbacktrace_cv_ld_buildid+:} false; then :
12782+
$as_echo_n "(cached) " >&6
12783+
else
12784+
LDFLAGS_hold=$LDFLAGS
12785+
LDFLAGS="$LDFLAGS -Wl,--build-id"
12786+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
12787+
/* end confdefs.h. */
12788+
12789+
int
12790+
main ()
12791+
{
12792+
12793+
;
12794+
return 0;
12795+
}
12796+
_ACEOF
12797+
if ac_fn_c_try_link "$LINENO"; then :
12798+
libbacktrace_cv_ld_buildid=yes
12799+
else
12800+
libbacktrace_cv_ld_buildid=no
12801+
fi
12802+
rm -f core conftest.err conftest.$ac_objext \
12803+
conftest$ac_exeext conftest.$ac_ext
12804+
LDFLAGS=$LDFLAGS_hold
12805+
fi
12806+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libbacktrace_cv_ld_buildid" >&5
12807+
$as_echo "$libbacktrace_cv_ld_buildid" >&6; }
12808+
if test "$libbacktrace_cv_ld_buildid" = yes; then
12809+
HAVE_BUILDID_TRUE=
12810+
HAVE_BUILDID_FALSE='#'
12811+
else
12812+
HAVE_BUILDID_TRUE='#'
12813+
HAVE_BUILDID_FALSE=
12814+
fi
12815+
12816+
1277312817
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether --compress-debug-sections is supported" >&5
1277412818
$as_echo_n "checking whether --compress-debug-sections is supported... " >&6; }
1277512819
if ${libgo_cv_ld_compress+:} false; then :
@@ -12808,6 +12852,95 @@ else
1280812852
fi
1280912853
1281012854
12855+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ZSTD_compress in -lzstd" >&5
12856+
$as_echo_n "checking for ZSTD_compress in -lzstd... " >&6; }
12857+
if ${ac_cv_lib_zstd_ZSTD_compress+:} false; then :
12858+
$as_echo_n "(cached) " >&6
12859+
else
12860+
ac_check_lib_save_LIBS=$LIBS
12861+
LIBS="-lzstd $LIBS"
12862+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
12863+
/* end confdefs.h. */
12864+
12865+
/* Override any GCC internal prototype to avoid an error.
12866+
Use char because int might match the return type of a GCC
12867+
builtin and then its argument prototype would still apply. */
12868+
#ifdef __cplusplus
12869+
extern "C"
12870+
#endif
12871+
char ZSTD_compress ();
12872+
int
12873+
main ()
12874+
{
12875+
return ZSTD_compress ();
12876+
;
12877+
return 0;
12878+
}
12879+
_ACEOF
12880+
if ac_fn_c_try_link "$LINENO"; then :
12881+
ac_cv_lib_zstd_ZSTD_compress=yes
12882+
else
12883+
ac_cv_lib_zstd_ZSTD_compress=no
12884+
fi
12885+
rm -f core conftest.err conftest.$ac_objext \
12886+
conftest$ac_exeext conftest.$ac_ext
12887+
LIBS=$ac_check_lib_save_LIBS
12888+
fi
12889+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_zstd_ZSTD_compress" >&5
12890+
$as_echo "$ac_cv_lib_zstd_ZSTD_compress" >&6; }
12891+
if test "x$ac_cv_lib_zstd_ZSTD_compress" = xyes; then :
12892+
12893+
$as_echo "#define HAVE_ZSTD 1" >>confdefs.h
12894+
12895+
fi
12896+
12897+
if test "$ac_cv_lib_zstd_ZSTD_compress" = yes; then
12898+
HAVE_ZSTD_TRUE=
12899+
HAVE_ZSTD_FALSE='#'
12900+
else
12901+
HAVE_ZSTD_TRUE='#'
12902+
HAVE_ZSTD_FALSE=
12903+
fi
12904+
12905+
12906+
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether --compress-debug-sections=zstd is supported" >&5
12907+
$as_echo_n "checking whether --compress-debug-sections=zstd is supported... " >&6; }
12908+
if ${libgo_cv_ld_compress_zstd+:} false; then :
12909+
$as_echo_n "(cached) " >&6
12910+
else
12911+
LDFLAGS_hold=$LDFLAGS
12912+
LDFLAGS="$LDFLAGS -Wl,--compress-debug-sections=zstd"
12913+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
12914+
/* end confdefs.h. */
12915+
12916+
int
12917+
main ()
12918+
{
12919+
12920+
;
12921+
return 0;
12922+
}
12923+
_ACEOF
12924+
if ac_fn_c_try_link "$LINENO"; then :
12925+
libgo_cv_ld_compress_zstd=yes
12926+
else
12927+
libgo_cv_ld_compress_zstd=no
12928+
fi
12929+
rm -f core conftest.err conftest.$ac_objext \
12930+
conftest$ac_exeext conftest.$ac_ext
12931+
LDFLAGS=$LDFLAGS_hold
12932+
fi
12933+
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libgo_cv_ld_compress_zstd" >&5
12934+
$as_echo "$libgo_cv_ld_compress_zstd" >&6; }
12935+
if test "$libgo_cv_ld_compress_zstd" = yes; then
12936+
HAVE_COMPRESSED_DEBUG_ZSTD_TRUE=
12937+
HAVE_COMPRESSED_DEBUG_ZSTD_FALSE='#'
12938+
else
12939+
HAVE_COMPRESSED_DEBUG_ZSTD_TRUE='#'
12940+
HAVE_COMPRESSED_DEBUG_ZSTD_FALSE=
12941+
fi
12942+
12943+
1281112944
1281212945
# Extract the first word of "objcopy", so it can be a program name with args.
1281312946
set dummy objcopy; ac_word=$2
@@ -13350,10 +13483,22 @@ if test -z "${HAVE_ZLIB_TRUE}" && test -z "${HAVE_ZLIB_FALSE}"; then
1335013483
as_fn_error $? "conditional \"HAVE_ZLIB\" was never defined.
1335113484
Usually this means the macro was only invoked conditionally." "$LINENO" 5
1335213485
fi
13486+
if test -z "${HAVE_BUILDID_TRUE}" && test -z "${HAVE_BUILDID_FALSE}"; then
13487+
as_fn_error $? "conditional \"HAVE_BUILDID\" was never defined.
13488+
Usually this means the macro was only invoked conditionally." "$LINENO" 5
13489+
fi
1335313490
if test -z "${HAVE_COMPRESSED_DEBUG_TRUE}" && test -z "${HAVE_COMPRESSED_DEBUG_FALSE}"; then
1335413491
as_fn_error $? "conditional \"HAVE_COMPRESSED_DEBUG\" was never defined.
1335513492
Usually this means the macro was only invoked conditionally." "$LINENO" 5
1335613493
fi
13494+
if test -z "${HAVE_ZSTD_TRUE}" && test -z "${HAVE_ZSTD_FALSE}"; then
13495+
as_fn_error $? "conditional \"HAVE_ZSTD\" was never defined.
13496+
Usually this means the macro was only invoked conditionally." "$LINENO" 5
13497+
fi
13498+
if test -z "${HAVE_COMPRESSED_DEBUG_ZSTD_TRUE}" && test -z "${HAVE_COMPRESSED_DEBUG_ZSTD_FALSE}"; then
13499+
as_fn_error $? "conditional \"HAVE_COMPRESSED_DEBUG_ZSTD\" was never defined.
13500+
Usually this means the macro was only invoked conditionally." "$LINENO" 5
13501+
fi
1335713502
if test -z "${HAVE_OBJCOPY_DEBUGLINK_TRUE}" && test -z "${HAVE_OBJCOPY_DEBUGLINK_FALSE}"; then
1335813503
as_fn_error $? "conditional \"HAVE_OBJCOPY_DEBUGLINK\" was never defined.
1335913504
Usually this means the macro was only invoked conditionally." "$LINENO" 5

configure.ac

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,18 @@ AC_CHECK_LIB([z], [compress],
481481
[AC_DEFINE(HAVE_ZLIB, 1, [Define if -lz is available.])])
482482
AM_CONDITIONAL(HAVE_ZLIB, test "$ac_cv_lib_z_compress" = yes)
483483

484-
dnl Test whether the linker supports the --compress_debug_sections option.
484+
dnl Test whether the linker supports the --build-id option.
485+
AC_CACHE_CHECK([whether --build-id is supported],
486+
[libbacktrace_cv_ld_buildid],
487+
[LDFLAGS_hold=$LDFLAGS
488+
LDFLAGS="$LDFLAGS -Wl,--build-id"
489+
AC_LINK_IFELSE([AC_LANG_PROGRAM(,)],
490+
[libbacktrace_cv_ld_buildid=yes],
491+
[libbacktrace_cv_ld_buildid=no])
492+
LDFLAGS=$LDFLAGS_hold])
493+
AM_CONDITIONAL(HAVE_BUILDID, test "$libbacktrace_cv_ld_buildid" = yes)
494+
495+
dnl Test whether the linker supports the --compress-debug-sections option.
485496
AC_CACHE_CHECK([whether --compress-debug-sections is supported],
486497
[libgo_cv_ld_compress],
487498
[LDFLAGS_hold=$LDFLAGS
@@ -492,6 +503,21 @@ AC_LINK_IFELSE([AC_LANG_PROGRAM(,)],
492503
LDFLAGS=$LDFLAGS_hold])
493504
AM_CONDITIONAL(HAVE_COMPRESSED_DEBUG, test "$libgo_cv_ld_compress" = yes)
494505

506+
AC_CHECK_LIB([zstd], [ZSTD_compress],
507+
[AC_DEFINE(HAVE_ZSTD, 1, [Define if -lzstd is available.])])
508+
AM_CONDITIONAL(HAVE_ZSTD, test "$ac_cv_lib_zstd_ZSTD_compress" = yes)
509+
510+
dnl Test whether the linker supports --compress-debug-sections=zstd option.
511+
AC_CACHE_CHECK([whether --compress-debug-sections=zstd is supported],
512+
[libgo_cv_ld_compress_zstd],
513+
[LDFLAGS_hold=$LDFLAGS
514+
LDFLAGS="$LDFLAGS -Wl,--compress-debug-sections=zstd"
515+
AC_LINK_IFELSE([AC_LANG_PROGRAM(,)],
516+
[libgo_cv_ld_compress_zstd=yes],
517+
[libgo_cv_ld_compress_zstd=no])
518+
LDFLAGS=$LDFLAGS_hold])
519+
AM_CONDITIONAL(HAVE_COMPRESSED_DEBUG_ZSTD, test "$libgo_cv_ld_compress_zstd" = yes)
520+
495521
AC_ARG_VAR(OBJCOPY, [location of objcopy])
496522
AC_CHECK_PROG(OBJCOPY, objcopy, objcopy,)
497523
AC_CHECK_PROG(READELF, readelf, readelf)

0 commit comments

Comments
 (0)