mirror of
https://github.com/gcc-mirror/gcc.git
synced 2024-11-21 13:40:47 +00:00
re PR other/67165 (please enable libbacktrace to work with compressed debug sections)
PR other/67165 * elf.c (__builtin_prefetch): Define if not __GNUC__. (unlikely): Define. (SHF_UNCOMPRESSED, ELFCOMPRESS_ZLIB): Define. (b_elf_chdr): Define type. (enum debug_section): Add ZDEBUG_xxx values. (debug_section_names): Add names for new sections. (struct debug_section_info): Add compressed field. (elf_zlib_failed, elf_zlib_fetch): New static functions. (HUFFMAN_TABLE_SIZE, HUFFMAN_VALUE_MASK): Define. (HUFFMAN_BITS_SHIFT, HUFFMAN_BITS_MASK): Define. (HUFFMAN_SECONDARY_SHIFT): Define. (ZDEBUG_TABLE_SIZE): Define. (ZDEBUG_TABLE_CODELEN_OFFSET, ZDEBUG_TABLE_WORK_OFFSET): Define. (final_next_secondary): New static variable if BACKTRACE_GENERATE_FIXED_HUFFMAN_TABLE. (elf_zlib_inflate_table): New static function. (BACKTRACE_GENERATE_FIXED_HUFFMAN_TABLE): If define, define main function to produce fixed Huffman table. (elf_zlib_default_table): New static variable. (elf_zlib_inflate): New static function. (elf_zlib_verify_checksum): Likewise. (elf_zlib_inflate_and_verify): Likewise. (elf_uncompress_zdebug): Likewise. (elf_uncompress_chdr): Likewise. (backtrace_uncompress_zdebug): New extern function. (elf_add): Look for .zdebug sections and SHF_COMPRESSED debug sections, and uncompress them. * internal.h (backtrace_compress_zdebug): Declare. * ztest.c: New file. * configure.ac: Check for -lz and check whether the linker supports --compress-debug-sections. * Makefile.am (ztest_SOURCES): New variable. (ztest_CFLAGS, ztest_LDADD): New variables. (check_PROGRAMS): Add ztest. (ctestg_SOURCES): New variable. (ctestg_CFLAGS, ctestg_LDFLAGS, ctestg_LDADD): New variables. (ctesta_SOURCES): New variable. (ctesta_CFLAGS, ctesta_LDFLAGS, ctesta_LDADD): New variables. (check_PROGRAMS): Add ctestg and ctesta. * configure, config.h.in, Makefile.in: Rebuild. From-SVN: r253275
This commit is contained in:
parent
ddda3741f8
commit
8da872d9ca
@ -1,3 +1,47 @@
|
||||
2017-09-28 Ian Lance Taylor <iant@golang.org>
|
||||
|
||||
PR other/67165
|
||||
* elf.c (__builtin_prefetch): Define if not __GNUC__.
|
||||
(unlikely): Define.
|
||||
(SHF_UNCOMPRESSED, ELFCOMPRESS_ZLIB): Define.
|
||||
(b_elf_chdr): Define type.
|
||||
(enum debug_section): Add ZDEBUG_xxx values.
|
||||
(debug_section_names): Add names for new sections.
|
||||
(struct debug_section_info): Add compressed field.
|
||||
(elf_zlib_failed, elf_zlib_fetch): New static functions.
|
||||
(HUFFMAN_TABLE_SIZE, HUFFMAN_VALUE_MASK): Define.
|
||||
(HUFFMAN_BITS_SHIFT, HUFFMAN_BITS_MASK): Define.
|
||||
(HUFFMAN_SECONDARY_SHIFT): Define.
|
||||
(ZDEBUG_TABLE_SIZE): Define.
|
||||
(ZDEBUG_TABLE_CODELEN_OFFSET, ZDEBUG_TABLE_WORK_OFFSET): Define.
|
||||
(final_next_secondary): New static variable if
|
||||
BACKTRACE_GENERATE_FIXED_HUFFMAN_TABLE.
|
||||
(elf_zlib_inflate_table): New static function.
|
||||
(BACKTRACE_GENERATE_FIXED_HUFFMAN_TABLE): If define, define main
|
||||
function to produce fixed Huffman table.
|
||||
(elf_zlib_default_table): New static variable.
|
||||
(elf_zlib_inflate): New static function.
|
||||
(elf_zlib_verify_checksum): Likewise.
|
||||
(elf_zlib_inflate_and_verify): Likewise.
|
||||
(elf_uncompress_zdebug): Likewise.
|
||||
(elf_uncompress_chdr): Likewise.
|
||||
(backtrace_uncompress_zdebug): New extern function.
|
||||
(elf_add): Look for .zdebug sections and SHF_COMPRESSED debug
|
||||
sections, and uncompress them.
|
||||
* internal.h (backtrace_compress_zdebug): Declare.
|
||||
* ztest.c: New file.
|
||||
* configure.ac: Check for -lz and check whether the linker
|
||||
supports --compress-debug-sections.
|
||||
* Makefile.am (ztest_SOURCES): New variable.
|
||||
(ztest_CFLAGS, ztest_LDADD): New variables.
|
||||
(check_PROGRAMS): Add ztest.
|
||||
(ctestg_SOURCES): New variable.
|
||||
(ctestg_CFLAGS, ctestg_LDFLAGS, ctestg_LDADD): New variables.
|
||||
(ctesta_SOURCES): New variable.
|
||||
(ctesta_CFLAGS, ctesta_LDFLAGS, ctesta_LDADD): New variables.
|
||||
(check_PROGRAMS): Add ctestg and ctesta.
|
||||
* configure, config.h.in, Makefile.in: Rebuild.
|
||||
|
||||
2017-09-22 Ian Lance Taylor <iant@golang.org>
|
||||
|
||||
PR sanitizer/77631
|
||||
|
@ -101,6 +101,16 @@ stest_LDADD = libbacktrace.la
|
||||
|
||||
check_PROGRAMS += stest
|
||||
|
||||
ztest_SOURCES = ztest.c testlib.c
|
||||
ztest_CFLAGS = -DSRCDIR=\"$(srcdir)\"
|
||||
ztest_LDADD = libbacktrace.la
|
||||
|
||||
if HAVE_ZLIB
|
||||
ztest_LDADD += -lz
|
||||
endif
|
||||
|
||||
check_PROGRAMS += ztest
|
||||
|
||||
edtest_SOURCES = edtest.c edtest2_build.c testlib.c
|
||||
edtest_LDADD = libbacktrace.la
|
||||
|
||||
@ -132,6 +142,22 @@ dtest: btest
|
||||
|
||||
endif HAVE_OBJCOPY_DEBUGLINK
|
||||
|
||||
if HAVE_COMPRESSED_DEBUG
|
||||
|
||||
ctestg_SOURCES = btest.c testlib.c
|
||||
ctestg_CFLAGS = $(AM_CFLAGS) -g
|
||||
ctestg_LDFLAGS = -Wl,--compress-debug-sections=zlib-gnu
|
||||
ctestg_LDADD = libbacktrace.la
|
||||
|
||||
ctesta_SOURCES = btest.c testlib.c
|
||||
ctesta_CFLAGS = $(AM_CFLAGS) -g
|
||||
ctesta_LDFLAGS = -Wl,--compress-debug-sections=zlib-gabi
|
||||
ctesta_LDADD = libbacktrace.la
|
||||
|
||||
check_PROGRAMS += ctestg ctesta
|
||||
|
||||
endif
|
||||
|
||||
endif NATIVE
|
||||
|
||||
# We can't use automake's automatic dependency tracking, because it
|
||||
|
@ -83,10 +83,12 @@ POST_UNINSTALL = :
|
||||
build_triplet = @build@
|
||||
host_triplet = @host@
|
||||
target_triplet = @target@
|
||||
check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2)
|
||||
@NATIVE_TRUE@am__append_1 = btest stest edtest
|
||||
@HAVE_PTHREAD_TRUE@@NATIVE_TRUE@am__append_2 = ttest
|
||||
@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@am__append_3 = dtest
|
||||
check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3)
|
||||
@NATIVE_TRUE@am__append_1 = btest stest ztest edtest
|
||||
@HAVE_ZLIB_TRUE@@NATIVE_TRUE@am__append_2 = -lz
|
||||
@HAVE_PTHREAD_TRUE@@NATIVE_TRUE@am__append_3 = ttest
|
||||
@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@am__append_4 = dtest
|
||||
@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@am__append_5 = ctestg ctesta
|
||||
subdir = .
|
||||
DIST_COMMON = README ChangeLog $(srcdir)/Makefile.in \
|
||||
$(srcdir)/Makefile.am $(top_srcdir)/configure \
|
||||
@ -116,8 +118,11 @@ am_libbacktrace_la_OBJECTS = atomic.lo dwarf.lo fileline.lo posix.lo \
|
||||
print.lo sort.lo state.lo
|
||||
libbacktrace_la_OBJECTS = $(am_libbacktrace_la_OBJECTS)
|
||||
@NATIVE_TRUE@am__EXEEXT_1 = btest$(EXEEXT) stest$(EXEEXT) \
|
||||
@NATIVE_TRUE@ edtest$(EXEEXT)
|
||||
@NATIVE_TRUE@ ztest$(EXEEXT) edtest$(EXEEXT)
|
||||
@HAVE_PTHREAD_TRUE@@NATIVE_TRUE@am__EXEEXT_2 = ttest$(EXEEXT)
|
||||
@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@am__EXEEXT_3 = \
|
||||
@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@ ctestg$(EXEEXT) \
|
||||
@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@ ctesta$(EXEEXT)
|
||||
@NATIVE_TRUE@am_btest_OBJECTS = btest-btest.$(OBJEXT) \
|
||||
@NATIVE_TRUE@ btest-testlib.$(OBJEXT)
|
||||
btest_OBJECTS = $(am_btest_OBJECTS)
|
||||
@ -125,6 +130,22 @@ btest_OBJECTS = $(am_btest_OBJECTS)
|
||||
btest_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=link $(CCLD) $(btest_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
|
||||
$(LDFLAGS) -o $@
|
||||
@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@am_ctesta_OBJECTS = ctesta-btest.$(OBJEXT) \
|
||||
@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@ ctesta-testlib.$(OBJEXT)
|
||||
ctesta_OBJECTS = $(am_ctesta_OBJECTS)
|
||||
@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@ctesta_DEPENDENCIES = \
|
||||
@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@ libbacktrace.la
|
||||
ctesta_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=link $(CCLD) $(ctesta_CFLAGS) $(CFLAGS) \
|
||||
$(ctesta_LDFLAGS) $(LDFLAGS) -o $@
|
||||
@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@am_ctestg_OBJECTS = ctestg-btest.$(OBJEXT) \
|
||||
@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@ ctestg-testlib.$(OBJEXT)
|
||||
ctestg_OBJECTS = $(am_ctestg_OBJECTS)
|
||||
@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@ctestg_DEPENDENCIES = \
|
||||
@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@ libbacktrace.la
|
||||
ctestg_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=link $(CCLD) $(ctestg_CFLAGS) $(CFLAGS) \
|
||||
$(ctestg_LDFLAGS) $(LDFLAGS) -o $@
|
||||
@NATIVE_TRUE@am_edtest_OBJECTS = edtest.$(OBJEXT) \
|
||||
@NATIVE_TRUE@ edtest2_build.$(OBJEXT) testlib.$(OBJEXT)
|
||||
edtest_OBJECTS = $(am_edtest_OBJECTS)
|
||||
@ -140,6 +161,14 @@ ttest_OBJECTS = $(am_ttest_OBJECTS)
|
||||
ttest_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=link $(CCLD) $(ttest_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
|
||||
$(LDFLAGS) -o $@
|
||||
@NATIVE_TRUE@am_ztest_OBJECTS = ztest-ztest.$(OBJEXT) \
|
||||
@NATIVE_TRUE@ ztest-testlib.$(OBJEXT)
|
||||
ztest_OBJECTS = $(am_ztest_OBJECTS)
|
||||
@NATIVE_TRUE@ztest_DEPENDENCIES = libbacktrace.la \
|
||||
@NATIVE_TRUE@ $(am__DEPENDENCIES_1)
|
||||
ztest_LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=link $(CCLD) $(ztest_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
|
||||
$(LDFLAGS) -o $@
|
||||
DEFAULT_INCLUDES = -I.@am__isrc@
|
||||
depcomp =
|
||||
am__depfiles_maybe =
|
||||
@ -153,8 +182,9 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
|
||||
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
|
||||
$(LDFLAGS) -o $@
|
||||
SOURCES = $(libbacktrace_la_SOURCES) $(EXTRA_libbacktrace_la_SOURCES) \
|
||||
$(btest_SOURCES) $(edtest_SOURCES) $(stest_SOURCES) \
|
||||
$(ttest_SOURCES)
|
||||
$(btest_SOURCES) $(ctesta_SOURCES) $(ctestg_SOURCES) \
|
||||
$(edtest_SOURCES) $(stest_SOURCES) $(ttest_SOURCES) \
|
||||
$(ztest_SOURCES)
|
||||
MULTISRCTOP =
|
||||
MULTIBUILDTOP =
|
||||
MULTIDIRS =
|
||||
@ -345,17 +375,28 @@ libbacktrace_la_LIBADD = \
|
||||
$(ALLOC_FILE)
|
||||
|
||||
libbacktrace_la_DEPENDENCIES = $(libbacktrace_la_LIBADD)
|
||||
TESTS = $(check_PROGRAMS) $(am__append_3)
|
||||
TESTS = $(check_PROGRAMS) $(am__append_4)
|
||||
@NATIVE_TRUE@btest_SOURCES = btest.c testlib.c
|
||||
@NATIVE_TRUE@btest_CFLAGS = $(AM_CFLAGS) -g -O
|
||||
@NATIVE_TRUE@btest_LDADD = libbacktrace.la
|
||||
@NATIVE_TRUE@stest_SOURCES = stest.c
|
||||
@NATIVE_TRUE@stest_LDADD = libbacktrace.la
|
||||
@NATIVE_TRUE@ztest_SOURCES = ztest.c testlib.c
|
||||
@NATIVE_TRUE@ztest_CFLAGS = -DSRCDIR=\"$(srcdir)\"
|
||||
@NATIVE_TRUE@ztest_LDADD = libbacktrace.la $(am__append_2)
|
||||
@NATIVE_TRUE@edtest_SOURCES = edtest.c edtest2_build.c testlib.c
|
||||
@NATIVE_TRUE@edtest_LDADD = libbacktrace.la
|
||||
@HAVE_PTHREAD_TRUE@@NATIVE_TRUE@ttest_SOURCES = ttest.c testlib.c
|
||||
@HAVE_PTHREAD_TRUE@@NATIVE_TRUE@ttest_CFLAGS = $(AM_CFLAGS) -pthread
|
||||
@HAVE_PTHREAD_TRUE@@NATIVE_TRUE@ttest_LDADD = libbacktrace.la
|
||||
@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@ctestg_SOURCES = btest.c testlib.c
|
||||
@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@ctestg_CFLAGS = $(AM_CFLAGS) -g
|
||||
@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@ctestg_LDFLAGS = -Wl,--compress-debug-sections=zlib-gnu
|
||||
@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@ctestg_LDADD = libbacktrace.la
|
||||
@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@ctesta_SOURCES = btest.c testlib.c
|
||||
@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@ctesta_CFLAGS = $(AM_CFLAGS) -g
|
||||
@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@ctesta_LDFLAGS = -Wl,--compress-debug-sections=zlib-gabi
|
||||
@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@ctesta_LDADD = libbacktrace.la
|
||||
|
||||
# We can't use automake's automatic dependency tracking, because it
|
||||
# breaks when using bootstrap-lean. Automatic dependency tracking
|
||||
@ -448,6 +489,12 @@ clean-checkPROGRAMS:
|
||||
btest$(EXEEXT): $(btest_OBJECTS) $(btest_DEPENDENCIES) $(EXTRA_btest_DEPENDENCIES)
|
||||
@rm -f btest$(EXEEXT)
|
||||
$(btest_LINK) $(btest_OBJECTS) $(btest_LDADD) $(LIBS)
|
||||
ctesta$(EXEEXT): $(ctesta_OBJECTS) $(ctesta_DEPENDENCIES) $(EXTRA_ctesta_DEPENDENCIES)
|
||||
@rm -f ctesta$(EXEEXT)
|
||||
$(ctesta_LINK) $(ctesta_OBJECTS) $(ctesta_LDADD) $(LIBS)
|
||||
ctestg$(EXEEXT): $(ctestg_OBJECTS) $(ctestg_DEPENDENCIES) $(EXTRA_ctestg_DEPENDENCIES)
|
||||
@rm -f ctestg$(EXEEXT)
|
||||
$(ctestg_LINK) $(ctestg_OBJECTS) $(ctestg_LDADD) $(LIBS)
|
||||
edtest$(EXEEXT): $(edtest_OBJECTS) $(edtest_DEPENDENCIES) $(EXTRA_edtest_DEPENDENCIES)
|
||||
@rm -f edtest$(EXEEXT)
|
||||
$(LINK) $(edtest_OBJECTS) $(edtest_LDADD) $(LIBS)
|
||||
@ -457,6 +504,9 @@ stest$(EXEEXT): $(stest_OBJECTS) $(stest_DEPENDENCIES) $(EXTRA_stest_DEPENDENCIE
|
||||
ttest$(EXEEXT): $(ttest_OBJECTS) $(ttest_DEPENDENCIES) $(EXTRA_ttest_DEPENDENCIES)
|
||||
@rm -f ttest$(EXEEXT)
|
||||
$(ttest_LINK) $(ttest_OBJECTS) $(ttest_LDADD) $(LIBS)
|
||||
ztest$(EXEEXT): $(ztest_OBJECTS) $(ztest_DEPENDENCIES) $(EXTRA_ztest_DEPENDENCIES)
|
||||
@rm -f ztest$(EXEEXT)
|
||||
$(ztest_LINK) $(ztest_OBJECTS) $(ztest_LDADD) $(LIBS)
|
||||
|
||||
mostlyclean-compile:
|
||||
-rm -f *.$(OBJEXT)
|
||||
@ -485,6 +535,30 @@ btest-testlib.o: testlib.c
|
||||
btest-testlib.obj: testlib.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(btest_CFLAGS) $(CFLAGS) -c -o btest-testlib.obj `if test -f 'testlib.c'; then $(CYGPATH_W) 'testlib.c'; else $(CYGPATH_W) '$(srcdir)/testlib.c'; fi`
|
||||
|
||||
ctesta-btest.o: btest.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ctesta_CFLAGS) $(CFLAGS) -c -o ctesta-btest.o `test -f 'btest.c' || echo '$(srcdir)/'`btest.c
|
||||
|
||||
ctesta-btest.obj: btest.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ctesta_CFLAGS) $(CFLAGS) -c -o ctesta-btest.obj `if test -f 'btest.c'; then $(CYGPATH_W) 'btest.c'; else $(CYGPATH_W) '$(srcdir)/btest.c'; fi`
|
||||
|
||||
ctesta-testlib.o: testlib.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ctesta_CFLAGS) $(CFLAGS) -c -o ctesta-testlib.o `test -f 'testlib.c' || echo '$(srcdir)/'`testlib.c
|
||||
|
||||
ctesta-testlib.obj: testlib.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ctesta_CFLAGS) $(CFLAGS) -c -o ctesta-testlib.obj `if test -f 'testlib.c'; then $(CYGPATH_W) 'testlib.c'; else $(CYGPATH_W) '$(srcdir)/testlib.c'; fi`
|
||||
|
||||
ctestg-btest.o: btest.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ctestg_CFLAGS) $(CFLAGS) -c -o ctestg-btest.o `test -f 'btest.c' || echo '$(srcdir)/'`btest.c
|
||||
|
||||
ctestg-btest.obj: btest.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ctestg_CFLAGS) $(CFLAGS) -c -o ctestg-btest.obj `if test -f 'btest.c'; then $(CYGPATH_W) 'btest.c'; else $(CYGPATH_W) '$(srcdir)/btest.c'; fi`
|
||||
|
||||
ctestg-testlib.o: testlib.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ctestg_CFLAGS) $(CFLAGS) -c -o ctestg-testlib.o `test -f 'testlib.c' || echo '$(srcdir)/'`testlib.c
|
||||
|
||||
ctestg-testlib.obj: testlib.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ctestg_CFLAGS) $(CFLAGS) -c -o ctestg-testlib.obj `if test -f 'testlib.c'; then $(CYGPATH_W) 'testlib.c'; else $(CYGPATH_W) '$(srcdir)/testlib.c'; fi`
|
||||
|
||||
ttest-ttest.o: ttest.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ttest_CFLAGS) $(CFLAGS) -c -o ttest-ttest.o `test -f 'ttest.c' || echo '$(srcdir)/'`ttest.c
|
||||
|
||||
@ -497,6 +571,18 @@ ttest-testlib.o: testlib.c
|
||||
ttest-testlib.obj: testlib.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ttest_CFLAGS) $(CFLAGS) -c -o ttest-testlib.obj `if test -f 'testlib.c'; then $(CYGPATH_W) 'testlib.c'; else $(CYGPATH_W) '$(srcdir)/testlib.c'; fi`
|
||||
|
||||
ztest-ztest.o: ztest.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ztest_CFLAGS) $(CFLAGS) -c -o ztest-ztest.o `test -f 'ztest.c' || echo '$(srcdir)/'`ztest.c
|
||||
|
||||
ztest-ztest.obj: ztest.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ztest_CFLAGS) $(CFLAGS) -c -o ztest-ztest.obj `if test -f 'ztest.c'; then $(CYGPATH_W) 'ztest.c'; else $(CYGPATH_W) '$(srcdir)/ztest.c'; fi`
|
||||
|
||||
ztest-testlib.o: testlib.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ztest_CFLAGS) $(CFLAGS) -c -o ztest-testlib.o `test -f 'testlib.c' || echo '$(srcdir)/'`testlib.c
|
||||
|
||||
ztest-testlib.obj: testlib.c
|
||||
$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(ztest_CFLAGS) $(CFLAGS) -c -o ztest-testlib.obj `if test -f 'testlib.c'; then $(CYGPATH_W) 'testlib.c'; else $(CYGPATH_W) '$(srcdir)/testlib.c'; fi`
|
||||
|
||||
mostlyclean-libtool:
|
||||
-rm -f *.lo
|
||||
|
||||
|
@ -31,6 +31,9 @@
|
||||
/* Define to 1 if you have the <inttypes.h> header file. */
|
||||
#undef HAVE_INTTYPES_H
|
||||
|
||||
/* Define to 1 if you have the `z' library (-lz). */
|
||||
#undef HAVE_LIBZ
|
||||
|
||||
/* Define to 1 if you have the <link.h> header file. */
|
||||
#undef HAVE_LINK_H
|
||||
|
||||
@ -76,6 +79,9 @@
|
||||
/* Define to 1 if you have the <unistd.h> header file. */
|
||||
#undef HAVE_UNISTD_H
|
||||
|
||||
/* Define if -lz is available. */
|
||||
#undef HAVE_ZLIB
|
||||
|
||||
/* Define to the sub-directory in which libtool stores uninstalled libraries.
|
||||
*/
|
||||
#undef LT_OBJDIR
|
||||
|
113
libbacktrace/configure
vendored
113
libbacktrace/configure
vendored
@ -607,6 +607,10 @@ NATIVE_TRUE
|
||||
HAVE_OBJCOPY_DEBUGLINK_FALSE
|
||||
HAVE_OBJCOPY_DEBUGLINK_TRUE
|
||||
OBJCOPY
|
||||
HAVE_COMPRESSED_DEBUG_FALSE
|
||||
HAVE_COMPRESSED_DEBUG_TRUE
|
||||
HAVE_ZLIB_FALSE
|
||||
HAVE_ZLIB_TRUE
|
||||
HAVE_PTHREAD_FALSE
|
||||
HAVE_PTHREAD_TRUE
|
||||
PTHREAD_CFLAGS
|
||||
@ -11141,7 +11145,7 @@ else
|
||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<_LT_EOF
|
||||
#line 11144 "configure"
|
||||
#line 11148 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
@ -11247,7 +11251,7 @@ else
|
||||
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
|
||||
lt_status=$lt_dlunknown
|
||||
cat > conftest.$ac_ext <<_LT_EOF
|
||||
#line 11250 "configure"
|
||||
#line 11254 "configure"
|
||||
#include "confdefs.h"
|
||||
|
||||
#if HAVE_DLFCN_H
|
||||
@ -12779,6 +12783,103 @@ else
|
||||
fi
|
||||
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for compress in -lz" >&5
|
||||
$as_echo_n "checking for compress in -lz... " >&6; }
|
||||
if test "${ac_cv_lib_z_compress+set}" = set; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
ac_check_lib_save_LIBS=$LIBS
|
||||
LIBS="-lz $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 compress ();
|
||||
int
|
||||
main ()
|
||||
{
|
||||
return compress ();
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_link "$LINENO"; then :
|
||||
ac_cv_lib_z_compress=yes
|
||||
else
|
||||
ac_cv_lib_z_compress=no
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
LIBS=$ac_check_lib_save_LIBS
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_z_compress" >&5
|
||||
$as_echo "$ac_cv_lib_z_compress" >&6; }
|
||||
if test "x$ac_cv_lib_z_compress" = x""yes; then :
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define HAVE_LIBZ 1
|
||||
_ACEOF
|
||||
|
||||
LIBS="-lz $LIBS"
|
||||
|
||||
fi
|
||||
|
||||
if test $ac_cv_lib_z_compress = "yes"; then
|
||||
|
||||
$as_echo "#define HAVE_ZLIB 1" >>confdefs.h
|
||||
|
||||
fi
|
||||
if test "$ac_cv_lib_z_compress" = yes; then
|
||||
HAVE_ZLIB_TRUE=
|
||||
HAVE_ZLIB_FALSE='#'
|
||||
else
|
||||
HAVE_ZLIB_TRUE='#'
|
||||
HAVE_ZLIB_FALSE=
|
||||
fi
|
||||
|
||||
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether --compress-debug-sections is supported" >&5
|
||||
$as_echo_n "checking whether --compress-debug-sections is supported... " >&6; }
|
||||
if test "${libgo_cv_ld_compress+set}" = set; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
LDFLAGS_hold=$LDFLAGS
|
||||
LDFLAGS="$LDFLAGS -Wl,--compress-debug-sections=zlib-gnu"
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
int
|
||||
main ()
|
||||
{
|
||||
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_link "$LINENO"; then :
|
||||
libgo_cv_ld_compress=yes
|
||||
else
|
||||
libgo_cv_ld_compress=no
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
LDFLAGS=$LDFLAGS_hold
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libgo_cv_ld_compress" >&5
|
||||
$as_echo "$libgo_cv_ld_compress" >&6; }
|
||||
if test "$libgo_cv_ld_compress" = yes; then
|
||||
HAVE_COMPRESSED_DEBUG_TRUE=
|
||||
HAVE_COMPRESSED_DEBUG_FALSE='#'
|
||||
else
|
||||
HAVE_COMPRESSED_DEBUG_TRUE='#'
|
||||
HAVE_COMPRESSED_DEBUG_FALSE=
|
||||
fi
|
||||
|
||||
|
||||
|
||||
# Extract the first word of "objcopy", so it can be a program name with args.
|
||||
set dummy objcopy; ac_word=$2
|
||||
@ -13008,6 +13109,14 @@ if test -z "${HAVE_PTHREAD_TRUE}" && test -z "${HAVE_PTHREAD_FALSE}"; then
|
||||
as_fn_error "conditional \"HAVE_PTHREAD\" was never defined.
|
||||
Usually this means the macro was only invoked conditionally." "$LINENO" 5
|
||||
fi
|
||||
if test -z "${HAVE_ZLIB_TRUE}" && test -z "${HAVE_ZLIB_FALSE}"; then
|
||||
as_fn_error "conditional \"HAVE_ZLIB\" was never defined.
|
||||
Usually this means the macro was only invoked conditionally." "$LINENO" 5
|
||||
fi
|
||||
if test -z "${HAVE_COMPRESSED_DEBUG_TRUE}" && test -z "${HAVE_COMPRESSED_DEBUG_FALSE}"; then
|
||||
as_fn_error "conditional \"HAVE_COMPRESSED_DEBUG\" was never defined.
|
||||
Usually this means the macro was only invoked conditionally." "$LINENO" 5
|
||||
fi
|
||||
if test -z "${HAVE_OBJCOPY_DEBUGLINK_TRUE}" && test -z "${HAVE_OBJCOPY_DEBUGLINK_FALSE}"; then
|
||||
as_fn_error "conditional \"HAVE_OBJCOPY_DEBUGLINK\" was never defined.
|
||||
Usually this means the macro was only invoked conditionally." "$LINENO" 5
|
||||
|
@ -405,6 +405,23 @@ AC_SUBST(PTHREAD_CFLAGS)
|
||||
|
||||
AM_CONDITIONAL(HAVE_PTHREAD, test "$libgo_cv_lib_pthread" = yes)
|
||||
|
||||
AC_CHECK_LIB([z], [compress], [])
|
||||
if test $ac_cv_lib_z_compress = "yes"; then
|
||||
AC_DEFINE(HAVE_ZLIB, 1, [Define if -lz is available.])
|
||||
fi
|
||||
AM_CONDITIONAL(HAVE_ZLIB, test "$ac_cv_lib_z_compress" = yes)
|
||||
|
||||
dnl Test whether the linker supports the --compress_debug_sections option.
|
||||
AC_CACHE_CHECK([whether --compress-debug-sections is supported],
|
||||
[libgo_cv_ld_compress],
|
||||
[LDFLAGS_hold=$LDFLAGS
|
||||
LDFLAGS="$LDFLAGS -Wl,--compress-debug-sections=zlib-gnu"
|
||||
AC_LINK_IFELSE([AC_LANG_PROGRAM(,)],
|
||||
[libgo_cv_ld_compress=yes],
|
||||
[libgo_cv_ld_compress=no])
|
||||
LDFLAGS=$LDFLAGS_hold])
|
||||
AM_CONDITIONAL(HAVE_COMPRESSED_DEBUG, test "$libgo_cv_ld_compress" = yes)
|
||||
|
||||
AC_ARG_VAR(OBJCOPY, [location of objcopy])
|
||||
AC_CHECK_PROG(OBJCOPY, objcopy, objcopy,)
|
||||
AC_CACHE_CHECK([whether objcopy supports debuglink],
|
||||
|
1629
libbacktrace/elf.c
1629
libbacktrace/elf.c
File diff suppressed because it is too large
Load Diff
@ -292,4 +292,13 @@ extern int backtrace_dwarf_add (struct backtrace_state *state,
|
||||
backtrace_error_callback error_callback,
|
||||
void *data, fileline *fileline_fn);
|
||||
|
||||
/* A test-only hook for elf_uncompress_zdebug. */
|
||||
|
||||
extern int backtrace_uncompress_zdebug (struct backtrace_state *,
|
||||
const unsigned char *compressed,
|
||||
size_t compressed_size,
|
||||
backtrace_error_callback, void *data,
|
||||
unsigned char **uncompressed,
|
||||
size_t *uncompressed_size);
|
||||
|
||||
#endif
|
||||
|
446
libbacktrace/ztest.c
Normal file
446
libbacktrace/ztest.c
Normal file
@ -0,0 +1,446 @@
|
||||
/* ztest.c -- Test for libbacktrace inflate code.
|
||||
Copyright (C) 2017 Free Software Foundation, Inc.
|
||||
Written by Ian Lance Taylor, Google.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
(1) Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
(2) Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in
|
||||
the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
|
||||
(3) The name of the author may not be used to
|
||||
endorse or promote products derived from this software without
|
||||
specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
||||
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE. */
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#ifdef HAVE_ZLIB
|
||||
#include <zlib.h>
|
||||
#endif
|
||||
|
||||
#include "backtrace.h"
|
||||
#include "backtrace-supported.h"
|
||||
|
||||
#include "internal.h"
|
||||
#include "testlib.h"
|
||||
|
||||
/* Some tests for the local zlib inflation code. */
|
||||
|
||||
struct zlib_test
|
||||
{
|
||||
const char *name;
|
||||
const char *uncompressed;
|
||||
const char *compressed;
|
||||
size_t compressed_len;
|
||||
};
|
||||
|
||||
/* Error callback. */
|
||||
|
||||
static void
|
||||
error_callback_compress (void *vdata, const char *msg, int errnum)
|
||||
{
|
||||
fprintf (stderr, "%s", msg);
|
||||
if (errnum > 0)
|
||||
fprintf (stderr, ": %s", strerror (errnum));
|
||||
fprintf (stderr, "\n");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static const struct zlib_test tests[] =
|
||||
{
|
||||
{
|
||||
"empty",
|
||||
"",
|
||||
"\x78\x9c\x03\x00\x00\x00\x00\x01",
|
||||
8,
|
||||
},
|
||||
{
|
||||
"hello",
|
||||
"hello, world\n",
|
||||
("\x78\x9c\xca\x48\xcd\xc9\xc9\xd7\x51\x28\xcf"
|
||||
"\x2f\xca\x49\xe1\x02\x04\x00\x00\xff\xff\x21\xe7\x04\x93"),
|
||||
25,
|
||||
},
|
||||
{
|
||||
"goodbye",
|
||||
"goodbye, world",
|
||||
("\x78\x9c\x4b\xcf\xcf\x4f\x49\xaa"
|
||||
"\x4c\xd5\x51\x28\xcf\x2f\xca\x49"
|
||||
"\x01\x00\x28\xa5\x05\x5e"),
|
||||
22,
|
||||
}
|
||||
};
|
||||
|
||||
/* Test the hand coded samples. */
|
||||
|
||||
static void
|
||||
test_samples (struct backtrace_state *state)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < sizeof tests / sizeof tests[0]; ++i)
|
||||
{
|
||||
char *p;
|
||||
size_t v;
|
||||
size_t j;
|
||||
unsigned char *uncompressed;
|
||||
size_t uncompressed_len;
|
||||
|
||||
p = malloc (12 + tests[i].compressed_len);
|
||||
memcpy (p, "ZLIB", 4);
|
||||
v = strlen (tests[i].uncompressed);
|
||||
for (j = 0; j < 8; ++j)
|
||||
p[j + 4] = (v >> ((7 - j) * 8)) & 0xff;
|
||||
memcpy (p + 12, tests[i].compressed, tests[i].compressed_len);
|
||||
uncompressed = NULL;
|
||||
uncompressed_len = 0;
|
||||
if (!backtrace_uncompress_zdebug (state, (unsigned char *) p,
|
||||
tests[i].compressed_len + 12,
|
||||
error_callback_compress, NULL,
|
||||
&uncompressed, &uncompressed_len))
|
||||
{
|
||||
fprintf (stderr, "test %s: uncompress failed\n", tests[i].name);
|
||||
++failures;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (uncompressed_len != v)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"test %s: got uncompressed length %zu, want %zu\n",
|
||||
tests[i].name, uncompressed_len, v);
|
||||
++failures;
|
||||
}
|
||||
else if (memcmp (tests[i].uncompressed, uncompressed, v) != 0)
|
||||
{
|
||||
size_t j;
|
||||
|
||||
fprintf (stderr, "test %s: uncompressed data mismatch\n",
|
||||
tests[i].name);
|
||||
for (j = 0; j < v; ++j)
|
||||
if (tests[i].uncompressed[j] != uncompressed[j])
|
||||
fprintf (stderr, " %zu: got %#x want %#x\n", j,
|
||||
uncompressed[j], tests[i].uncompressed[j]);
|
||||
++failures;
|
||||
}
|
||||
else
|
||||
printf ("PASS: inflate %s\n", tests[i].name);
|
||||
|
||||
backtrace_free (state, uncompressed, uncompressed_len,
|
||||
error_callback_compress, NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_ZLIB
|
||||
|
||||
/* Given a set of TRIALS timings, discard the lowest and highest
|
||||
values and return the mean average of the rest. */
|
||||
|
||||
static size_t
|
||||
average_time (const size_t *times, size_t trials)
|
||||
{
|
||||
size_t imax;
|
||||
size_t max;
|
||||
size_t imin;
|
||||
size_t min;
|
||||
size_t i;
|
||||
size_t sum;
|
||||
|
||||
imin = 0;
|
||||
imax = 0;
|
||||
min = times[0];
|
||||
max = times[0];
|
||||
for (i = 1; i < trials; ++i)
|
||||
{
|
||||
if (times[i] < min)
|
||||
{
|
||||
imin = i;
|
||||
min = times[i];
|
||||
}
|
||||
if (times[i] > max)
|
||||
{
|
||||
imax = i;
|
||||
max = times[i];
|
||||
}
|
||||
}
|
||||
|
||||
sum = 0;
|
||||
for (i = 0; i < trials; ++i)
|
||||
{
|
||||
if (i != imax && i != imin)
|
||||
sum += times[i];
|
||||
}
|
||||
return sum / (trials - 2);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Test a larger text, if available. */
|
||||
|
||||
static void
|
||||
test_large (struct backtrace_state *state)
|
||||
{
|
||||
#ifdef HAVE_ZLIB
|
||||
unsigned char *orig_buf;
|
||||
size_t orig_bufsize;
|
||||
size_t i;
|
||||
char *compressed_buf;
|
||||
size_t compressed_bufsize;
|
||||
unsigned long compress_sizearg;
|
||||
unsigned char *uncompressed_buf;
|
||||
size_t uncompressed_bufsize;
|
||||
int r;
|
||||
clockid_t cid;
|
||||
struct timespec ts1;
|
||||
struct timespec ts2;
|
||||
size_t ctime;
|
||||
size_t ztime;
|
||||
const size_t trials = 16;
|
||||
size_t ctimes[16];
|
||||
size_t ztimes[16];
|
||||
static const char * const names[] = {
|
||||
"Mark.Twain-Tom.Sawyer.txt",
|
||||
"../libgo/go/compress/testdata/Mark.Twain-Tom.Sawyer.txt"
|
||||
};
|
||||
|
||||
orig_buf = NULL;
|
||||
orig_bufsize = 0;
|
||||
uncompressed_buf = NULL;
|
||||
compressed_buf = NULL;
|
||||
|
||||
for (i = 0; i < sizeof names / sizeof names[0]; ++i)
|
||||
{
|
||||
size_t len;
|
||||
char *namebuf;
|
||||
FILE *e;
|
||||
struct stat st;
|
||||
char *rbuf;
|
||||
size_t got;
|
||||
|
||||
len = strlen (SRCDIR) + strlen (names[i]) + 2;
|
||||
namebuf = malloc (len);
|
||||
if (namebuf == NULL)
|
||||
{
|
||||
perror ("malloc");
|
||||
goto fail;
|
||||
}
|
||||
snprintf (namebuf, len, "%s/%s", SRCDIR, names[i]);
|
||||
e = fopen (namebuf, "r");
|
||||
free (namebuf);
|
||||
if (e == NULL)
|
||||
continue;
|
||||
if (fstat (fileno (e), &st) < 0)
|
||||
{
|
||||
perror ("fstat");
|
||||
fclose (e);
|
||||
continue;
|
||||
}
|
||||
rbuf = malloc (st.st_size);
|
||||
if (rbuf == NULL)
|
||||
{
|
||||
perror ("malloc");
|
||||
goto fail;
|
||||
}
|
||||
got = fread (rbuf, 1, st.st_size, e);
|
||||
fclose (e);
|
||||
if (got > 0)
|
||||
{
|
||||
orig_buf = rbuf;
|
||||
orig_bufsize = got;
|
||||
break;
|
||||
}
|
||||
free (rbuf);
|
||||
}
|
||||
|
||||
if (orig_buf == NULL)
|
||||
{
|
||||
/* We couldn't find an input file. */
|
||||
printf ("UNSUPPORTED: inflate large\n");
|
||||
return;
|
||||
}
|
||||
|
||||
compressed_bufsize = compressBound (orig_bufsize) + 12;
|
||||
compressed_buf = malloc (compressed_bufsize);
|
||||
if (compressed_buf == NULL)
|
||||
{
|
||||
perror ("malloc");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
compress_sizearg = compressed_bufsize - 12;
|
||||
r = compress (compressed_buf + 12, &compress_sizearg,
|
||||
orig_buf, orig_bufsize);
|
||||
if (r != Z_OK)
|
||||
{
|
||||
fprintf (stderr, "zlib compress failed: %d\n", r);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
compressed_bufsize = compress_sizearg + 12;
|
||||
|
||||
/* Prepare the header that our library expects. */
|
||||
memcpy (compressed_buf, "ZLIB", 4);
|
||||
for (i = 0; i < 8; ++i)
|
||||
compressed_buf[i + 4] = (orig_bufsize >> ((7 - i) * 8)) & 0xff;
|
||||
|
||||
uncompressed_buf = malloc (orig_bufsize);
|
||||
if (uncompressed_buf == NULL)
|
||||
{
|
||||
perror ("malloc");
|
||||
goto fail;
|
||||
}
|
||||
uncompressed_bufsize = orig_bufsize;
|
||||
|
||||
if (!backtrace_uncompress_zdebug (state, compressed_buf, compressed_bufsize,
|
||||
error_callback_compress, NULL,
|
||||
&uncompressed_buf, &uncompressed_bufsize))
|
||||
{
|
||||
fprintf (stderr, "inflate large: backtrace_uncompress_zdebug failed\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (uncompressed_bufsize != orig_bufsize)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"inflate large: got uncompressed length %zu, want %zu\n",
|
||||
uncompressed_bufsize, orig_bufsize);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (memcmp (uncompressed_buf, orig_buf, uncompressed_bufsize) != 0)
|
||||
{
|
||||
fprintf (stderr, "inflate large: uncompressed data mismatch\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
printf ("PASS: inflate large\n");
|
||||
|
||||
for (i = 0; i < trials; ++i)
|
||||
{
|
||||
cid = CLOCK_REALTIME;
|
||||
#ifdef CLOCK_PROCESS_CPUTIME_ID
|
||||
cid = CLOCK_PROCESS_CPUTIME_ID;
|
||||
#endif
|
||||
if (clock_gettime (cid, &ts1) < 0)
|
||||
{
|
||||
perror ("clock_gettime");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!backtrace_uncompress_zdebug (state, compressed_buf,
|
||||
compressed_bufsize,
|
||||
error_callback_compress, NULL,
|
||||
&uncompressed_buf,
|
||||
&uncompressed_bufsize))
|
||||
{
|
||||
fprintf (stderr,
|
||||
("inflate large: "
|
||||
"benchmark backtrace_uncompress_zdebug failed\n"));
|
||||
return;
|
||||
}
|
||||
|
||||
if (clock_gettime (cid, &ts2) < 0)
|
||||
{
|
||||
perror ("clock_gettime");
|
||||
return;
|
||||
}
|
||||
|
||||
ctime = (ts2.tv_sec - ts1.tv_sec) * 1000000000;
|
||||
ctime += ts2.tv_nsec - ts1.tv_nsec;
|
||||
ctimes[i] = ctime;
|
||||
|
||||
if (clock_gettime (cid, &ts1) < 0)
|
||||
{
|
||||
perror("clock_gettime");
|
||||
return;
|
||||
}
|
||||
|
||||
r = uncompress (uncompressed_buf, &uncompressed_bufsize,
|
||||
compressed_buf + 12, compressed_bufsize - 12);
|
||||
|
||||
if (clock_gettime (cid, &ts2) < 0)
|
||||
{
|
||||
perror ("clock_gettime");
|
||||
return;
|
||||
}
|
||||
|
||||
if (r != Z_OK)
|
||||
{
|
||||
fprintf (stderr,
|
||||
"inflate large: benchmark zlib uncompress failed: %d\n",
|
||||
r);
|
||||
return;
|
||||
}
|
||||
|
||||
ztime = (ts2.tv_sec - ts1.tv_sec) * 1000000000;
|
||||
ztime += ts2.tv_nsec - ts1.tv_nsec;
|
||||
ztimes[i] = ztime;
|
||||
}
|
||||
|
||||
/* Toss the highest and lowest times and average the rest. */
|
||||
ctime = average_time (ctimes, trials);
|
||||
ztime = average_time (ztimes, trials);
|
||||
|
||||
printf ("backtrace time: %zu ns\n", ctime);
|
||||
printf ("zlib time: : %zu ns\n", ztime);
|
||||
printf ("percentage : %g\n", (double) ztime / (double) ctime);
|
||||
|
||||
return;
|
||||
|
||||
fail:
|
||||
printf ("FAIL: inflate large\n");
|
||||
++failures;
|
||||
|
||||
if (orig_buf != NULL)
|
||||
free (orig_buf);
|
||||
if (compressed_buf != NULL)
|
||||
free (compressed_buf);
|
||||
if (uncompressed_buf != NULL)
|
||||
free (uncompressed_buf);
|
||||
|
||||
#else /* !HAVE_ZLIB */
|
||||
|
||||
printf ("UNSUPPORTED: inflate large\n");
|
||||
|
||||
#endif /* !HAVE_ZLIB */
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc ATTRIBUTE_UNUSED, char **argv)
|
||||
{
|
||||
struct backtrace_state *state;
|
||||
|
||||
state = backtrace_create_state (argv[0], BACKTRACE_SUPPORTS_THREADS,
|
||||
error_callback_create, NULL);
|
||||
|
||||
test_samples (state);
|
||||
test_large (state);
|
||||
|
||||
exit (failures != 0 ? EXIT_FAILURE : EXIT_SUCCESS);
|
||||
}
|
Loading…
Reference in New Issue
Block a user