Commit fddbc193 by Tom de Vries Committed by Tom de Vries

[libbacktrace] Add test-cases exercising build-id and dwz

Add test-cases b2test_buildid and b3test_dwz_buildid.

The last one triggers the segfault fixed by "[backtrace] Avoid segfault"
( r268275 ).

2019-01-29  Tom de Vries  <tdevries@suse.de>

	* install-debuginfo-for-buildid.sh.in: New script.
	* Makefile.am (check_PROGRAMS): Add b2test and b3test.
	(TESTS): Add b2test_buildid and b3test_dwz_buildid.
	* Makefile.in: Regenerate.
	* configure.ac (HAVE_ELF): Set with AM_CONDITIONAL.
	(READELF): Set with AC_CHECK_PROG.
	(install-debuginfo-for-buildid.sh): Generate with AC_CONFIG_FILES.
	* configure: Regenerate.
	* elf.c (SYSTEM_BUILD_ID_DIR): Factor out of ...
	(elf_open_debugfile_by_buildid): ... here.

From-SVN: r268369
parent 7e574f68
2019-01-29 Tom de Vries <tdevries@suse.de> 2019-01-29 Tom de Vries <tdevries@suse.de>
* install-debuginfo-for-buildid.sh.in: New script.
* Makefile.am (check_PROGRAMS): Add b2test and b3test.
(TESTS): Add b2test_buildid and b3test_dwz_buildid.
* Makefile.in: Regenerate.
* configure.ac (HAVE_ELF): Set with AM_CONDITIONAL.
(READELF): Set with AC_CHECK_PROG.
(install-debuginfo-for-buildid.sh): Generate with AC_CONFIG_FILES.
* configure: Regenerate.
* elf.c (SYSTEM_BUILD_ID_DIR): Factor out of ...
(elf_open_debugfile_by_buildid): ... here.
2019-01-29 Tom de Vries <tdevries@suse.de>
* Makefile.am: Replace check_PROGRAMS with BUILDTESTS, except for * Makefile.am: Replace check_PROGRAMS with BUILDTESTS, except for
allocfail. allocfail.
(TESTS): Don't add check_PROGRAMS. Add BUILDTESTS. (TESTS): Don't add check_PROGRAMS. Add BUILDTESTS.
......
...@@ -108,6 +108,28 @@ libbacktrace_noformat_la_LIBADD = $(BACKTRACE_FILE) $(VIEW_FILE) $(ALLOC_FILE) ...@@ -108,6 +108,28 @@ libbacktrace_noformat_la_LIBADD = $(BACKTRACE_FILE) $(VIEW_FILE) $(ALLOC_FILE)
libbacktrace_noformat_la_DEPENDENCIES = $(libbacktrace_noformat_la_LIBADD) libbacktrace_noformat_la_DEPENDENCIES = $(libbacktrace_noformat_la_LIBADD)
if HAVE_ELF
if HAVE_OBJCOPY_DEBUGLINK
TEST_BUILD_ID_DIR=$(abs_builddir)/usr/lib/debug/.build-id/
check_LTLIBRARIES += libbacktrace_elf_for_test.la
libbacktrace_elf_for_test_la_SOURCES = $(libbacktrace_la_SOURCES)
libbacktrace_elf_for_test_la_LIBADD = $(BACKTRACE_FILE) elf_for_test.lo \
$(VIEW_FILE) $(ALLOC_FILE)
elf_for_test.c: elf.c
SEARCH='^#define SYSTEM_BUILD_ID_DIR.*$$'; \
REPLACE="#define SYSTEM_BUILD_ID_DIR \"$(TEST_BUILD_ID_DIR)\""; \
$(SED) "s%$$SEARCH%$$REPLACE%" \
$< \
> $@.tmp
mv $@.tmp $@
endif HAVE_OBJCOPY_DEBUGLINK
endif HAVE_ELF
xcoff_%.c: xcoff.c xcoff_%.c: xcoff.c
SEARCH='#error "Unknown BACKTRACE_XCOFF_SIZE"'; \ SEARCH='#error "Unknown BACKTRACE_XCOFF_SIZE"'; \
REPLACE='#undef BACKTRACE_XCOFF_SIZE\ REPLACE='#undef BACKTRACE_XCOFF_SIZE\
...@@ -172,6 +194,28 @@ allocfail.sh: allocfail ...@@ -172,6 +194,28 @@ allocfail.sh: allocfail
TESTS += allocfail.sh TESTS += allocfail.sh
if HAVE_ELF
if HAVE_OBJCOPY_DEBUGLINK
b2test_SOURCES = $(btest_SOURCES)
b2test_CFLAGS = $(btest_CFLAGS)
b2test_LDFLAGS = -Wl,--build-id
b2test_LDADD = libbacktrace_elf_for_test.la
check_PROGRAMS += b2test
TESTS += b2test_buildid
b3test_SOURCES = $(btest_SOURCES)
b3test_CFLAGS = $(btest_CFLAGS)
b3test_LDFLAGS = -Wl,--build-id
b3test_LDADD = libbacktrace_elf_for_test.la
check_PROGRAMS += b3test
TESTS += b3test_dwz_buildid
endif HAVE_OBJCOPY_DEBUGLINK
endif HAVE_ELF
btest_SOURCES = btest.c testlib.c btest_SOURCES = btest.c testlib.c
btest_CFLAGS = $(AM_CFLAGS) -g -O btest_CFLAGS = $(AM_CFLAGS) -g -O
btest_LDADD = libbacktrace.la btest_LDADD = libbacktrace.la
...@@ -275,6 +319,12 @@ TESTS += btest_gnudebuglink ...@@ -275,6 +319,12 @@ TESTS += btest_gnudebuglink
endif HAVE_OBJCOPY_DEBUGLINK endif HAVE_OBJCOPY_DEBUGLINK
%_buildid: %
./install-debuginfo-for-buildid.sh \
"$(TEST_BUILD_ID_DIR)" \
$<
$(OBJCOPY) --strip-debug $< $@
if HAVE_COMPRESSED_DEBUG if HAVE_COMPRESSED_DEBUG
ctestg_SOURCES = btest.c testlib.c ctestg_SOURCES = btest.c testlib.c
......
...@@ -637,6 +637,7 @@ NATIVE_FALSE ...@@ -637,6 +637,7 @@ NATIVE_FALSE
NATIVE_TRUE NATIVE_TRUE
HAVE_OBJCOPY_DEBUGLINK_FALSE HAVE_OBJCOPY_DEBUGLINK_FALSE
HAVE_OBJCOPY_DEBUGLINK_TRUE HAVE_OBJCOPY_DEBUGLINK_TRUE
READELF
OBJCOPY OBJCOPY
HAVE_COMPRESSED_DEBUG_FALSE HAVE_COMPRESSED_DEBUG_FALSE
HAVE_COMPRESSED_DEBUG_TRUE HAVE_COMPRESSED_DEBUG_TRUE
...@@ -651,6 +652,8 @@ ALLOC_FILE ...@@ -651,6 +652,8 @@ ALLOC_FILE
VIEW_FILE VIEW_FILE
BACKTRACE_SUPPORTS_DATA BACKTRACE_SUPPORTS_DATA
BACKTRACE_SUPPORTED BACKTRACE_SUPPORTED
HAVE_ELF_FALSE
HAVE_ELF_TRUE
FORMAT_FILE FORMAT_FILE
BACKTRACE_SUPPORTS_THREADS BACKTRACE_SUPPORTS_THREADS
PIC_FLAG PIC_FLAG
...@@ -11489,7 +11492,7 @@ else ...@@ -11489,7 +11492,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF cat > conftest.$ac_ext <<_LT_EOF
#line 11492 "configure" #line 11495 "configure"
#include "confdefs.h" #include "confdefs.h"
#if HAVE_DLFCN_H #if HAVE_DLFCN_H
...@@ -11595,7 +11598,7 @@ else ...@@ -11595,7 +11598,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2 lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF cat > conftest.$ac_ext <<_LT_EOF
#line 11598 "configure" #line 11601 "configure"
#include "confdefs.h" #include "confdefs.h"
#if HAVE_DLFCN_H #if HAVE_DLFCN_H
...@@ -12512,6 +12515,14 @@ cat >>confdefs.h <<_ACEOF ...@@ -12512,6 +12515,14 @@ cat >>confdefs.h <<_ACEOF
#define BACKTRACE_ELF_SIZE $elfsize #define BACKTRACE_ELF_SIZE $elfsize
_ACEOF _ACEOF
if test "$FORMAT_FILE" = "elf.lo"; then
HAVE_ELF_TRUE=
HAVE_ELF_FALSE='#'
else
HAVE_ELF_TRUE='#'
HAVE_ELF_FALSE=
fi
# XCOFF defines. # XCOFF defines.
xcoffsize= xcoffsize=
...@@ -13400,6 +13411,43 @@ $as_echo "no" >&6; } ...@@ -13400,6 +13411,43 @@ $as_echo "no" >&6; }
fi fi
# Extract the first word of "readelf", so it can be a program name with args.
set dummy readelf; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if ${ac_cv_prog_READELF+:} false; then :
$as_echo_n "(cached) " >&6
else
if test -n "$READELF"; then
ac_cv_prog_READELF="$READELF" # Let the user override the test.
else
as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
for as_dir in $PATH
do
IFS=$as_save_IFS
test -z "$as_dir" && as_dir=.
for ac_exec_ext in '' $ac_executable_extensions; do
if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
ac_cv_prog_READELF="readelf"
$as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
break 2
fi
done
done
IFS=$as_save_IFS
fi
fi
READELF=$ac_cv_prog_READELF
if test -n "$READELF"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $READELF" >&5
$as_echo "$READELF" >&6; }
else
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether objcopy supports debuglink" >&5 { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether objcopy supports debuglink" >&5
$as_echo_n "checking whether objcopy supports debuglink... " >&6; } $as_echo_n "checking whether objcopy supports debuglink... " >&6; }
if ${libbacktrace_cv_objcopy_debuglink+:} false; then : if ${libbacktrace_cv_objcopy_debuglink+:} false; then :
...@@ -13473,6 +13521,8 @@ fi ...@@ -13473,6 +13521,8 @@ fi
ac_config_files="$ac_config_files Makefile backtrace-supported.h" ac_config_files="$ac_config_files Makefile backtrace-supported.h"
ac_config_files="$ac_config_files install-debuginfo-for-buildid.sh"
# We need multilib support, but only if configuring for the target. # We need multilib support, but only if configuring for the target.
ac_config_commands="$ac_config_commands default" ac_config_commands="$ac_config_commands default"
...@@ -13611,6 +13661,10 @@ if test -z "${HAVE_DWZ_TRUE}" && test -z "${HAVE_DWZ_FALSE}"; then ...@@ -13611,6 +13661,10 @@ if test -z "${HAVE_DWZ_TRUE}" && test -z "${HAVE_DWZ_FALSE}"; then
as_fn_error $? "conditional \"HAVE_DWZ\" was never defined. as_fn_error $? "conditional \"HAVE_DWZ\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5 Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi fi
if test -z "${HAVE_ELF_TRUE}" && test -z "${HAVE_ELF_FALSE}"; then
as_fn_error $? "conditional \"HAVE_ELF\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
fi
if test -z "${HAVE_PTHREAD_TRUE}" && test -z "${HAVE_PTHREAD_FALSE}"; then if test -z "${HAVE_PTHREAD_TRUE}" && test -z "${HAVE_PTHREAD_FALSE}"; then
as_fn_error $? "conditional \"HAVE_PTHREAD\" was never defined. as_fn_error $? "conditional \"HAVE_PTHREAD\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5 Usually this means the macro was only invoked conditionally." "$LINENO" 5
...@@ -14525,6 +14579,7 @@ do ...@@ -14525,6 +14579,7 @@ do
"gstdint.h") CONFIG_COMMANDS="$CONFIG_COMMANDS gstdint.h" ;; "gstdint.h") CONFIG_COMMANDS="$CONFIG_COMMANDS gstdint.h" ;;
"Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;; "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
"backtrace-supported.h") CONFIG_FILES="$CONFIG_FILES backtrace-supported.h" ;; "backtrace-supported.h") CONFIG_FILES="$CONFIG_FILES backtrace-supported.h" ;;
"install-debuginfo-for-buildid.sh") CONFIG_FILES="$CONFIG_FILES install-debuginfo-for-buildid.sh" ;;
"default") CONFIG_COMMANDS="$CONFIG_COMMANDS default" ;; "default") CONFIG_COMMANDS="$CONFIG_COMMANDS default" ;;
*) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
...@@ -16140,6 +16195,7 @@ else ...@@ -16140,6 +16195,7 @@ else
fi fi
;; ;;
"install-debuginfo-for-buildid.sh":F) chmod +x install-debuginfo-for-buildid.sh ;;
"default":C) if test -n "$CONFIG_FILES"; then "default":C) if test -n "$CONFIG_FILES"; then
if test -n "${with_target_subdir}"; then if test -n "${with_target_subdir}"; then
# Multilibs need MULTISUBDIR defined correctly in certain makefiles so # Multilibs need MULTISUBDIR defined correctly in certain makefiles so
......
...@@ -259,6 +259,7 @@ elf64) elfsize=64 ;; ...@@ -259,6 +259,7 @@ elf64) elfsize=64 ;;
*) elfsize=unused *) elfsize=unused
esac esac
AC_DEFINE_UNQUOTED([BACKTRACE_ELF_SIZE], [$elfsize], [ELF size: 32 or 64]) AC_DEFINE_UNQUOTED([BACKTRACE_ELF_SIZE], [$elfsize], [ELF size: 32 or 64])
AM_CONDITIONAL(HAVE_ELF, test "$FORMAT_FILE" = "elf.lo")
# XCOFF defines. # XCOFF defines.
xcoffsize= xcoffsize=
...@@ -445,6 +446,7 @@ AM_CONDITIONAL(HAVE_COMPRESSED_DEBUG, test "$libgo_cv_ld_compress" = yes) ...@@ -445,6 +446,7 @@ AM_CONDITIONAL(HAVE_COMPRESSED_DEBUG, test "$libgo_cv_ld_compress" = yes)
AC_ARG_VAR(OBJCOPY, [location of objcopy]) AC_ARG_VAR(OBJCOPY, [location of objcopy])
AC_CHECK_PROG(OBJCOPY, objcopy, objcopy,) AC_CHECK_PROG(OBJCOPY, objcopy, objcopy,)
AC_CHECK_PROG(READELF, readelf, readelf)
AC_CACHE_CHECK([whether objcopy supports debuglink], AC_CACHE_CHECK([whether objcopy supports debuglink],
[libbacktrace_cv_objcopy_debuglink], [libbacktrace_cv_objcopy_debuglink],
[if test -n "${with_target_subdir}"; then [if test -n "${with_target_subdir}"; then
...@@ -472,6 +474,7 @@ else ...@@ -472,6 +474,7 @@ else
fi fi
AC_CONFIG_FILES(Makefile backtrace-supported.h) AC_CONFIG_FILES(Makefile backtrace-supported.h)
AC_CONFIG_FILES(install-debuginfo-for-buildid.sh, chmod +x install-debuginfo-for-buildid.sh)
# We need multilib support, but only if configuring for the target. # We need multilib support, but only if configuring for the target.
AC_CONFIG_COMMANDS([default], AC_CONFIG_COMMANDS([default],
......
...@@ -809,6 +809,8 @@ elf_readlink (struct backtrace_state *state, const char *filename, ...@@ -809,6 +809,8 @@ elf_readlink (struct backtrace_state *state, const char *filename,
} }
} }
#define SYSTEM_BUILD_ID_DIR "/usr/lib/debug/.build-id/"
/* Open a separate debug info file, using the build ID to find it. /* Open a separate debug info file, using the build ID to find it.
Returns an open file descriptor, or -1. Returns an open file descriptor, or -1.
...@@ -821,7 +823,7 @@ elf_open_debugfile_by_buildid (struct backtrace_state *state, ...@@ -821,7 +823,7 @@ elf_open_debugfile_by_buildid (struct backtrace_state *state,
backtrace_error_callback error_callback, backtrace_error_callback error_callback,
void *data) void *data)
{ {
const char * const prefix = "/usr/lib/debug/.build-id/"; const char * const prefix = SYSTEM_BUILD_ID_DIR;
const size_t prefix_len = strlen (prefix); const size_t prefix_len = strlen (prefix);
const char * const suffix = ".debug"; const char * const suffix = ".debug";
const size_t suffix_len = strlen (suffix); const size_t suffix_len = strlen (suffix);
......
#!/bin/sh
# install-debug-info-for-buildid.sh -- Helper script for libbacktrace library
# testing.
# Copyright (C) 2019 Free Software Foundation, Inc.
# 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.
# Extract build-id from src, and copy debug info of src to
# $build_id_dir/aa/bb...zz.debug.
set -e
sed=@SED@
awk=@AWK@
grep=@GREP@
objcopy=@OBJCOPY@
readelf=@READELF@
mkdir_p="@MKDIR_P@"
build_id_dir="$1"
src="$2"
buildid=$($readelf -n $src \
| $grep "Build ID" \
| $awk '{print $3}')
prefix=$(echo $buildid \
| $sed 's/^\(.\{2\}\).*/\1/')
remainder=$(echo $buildid \
| $sed 's/^.\{2\}//')
dir=$build_id_dir/$prefix
dst=$dir/$remainder.debug
$mkdir_p $dir
$objcopy --only-keep-debug $src $dst
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment