Commit 9283471b by Ian Lance Taylor Committed by Ian Lance Taylor

re PR sanitizer/77631 (no symbols in backtrace shown by ASan when debug info is split)

	PR sanitizer/77631
	Support for external debug info.
	* elf.c: Include <errno.h>, <sys/stat.h>, <unistd.h>.
	(S_ISLNK): Define if not defined.
	(xstrnlen): Define if strnlen is not available.
	(b_elf_note): Define type.
	(NT_GNU_BUILD_ID): Define macro.
	(elf_crc32, elf_crc32_file): New static functions.
	(elf_is_symlink, elf_readlink): New static functions.
	(elf_open_debugfile_by_buildid): New static function.
	(elf_try_debugfile): New static function.
	(elf_find_debugfile_by_debuglink): New static function.
	(elf_open_debugfile_by_debuglink): New static function.
	(elf_add): Add filename and debuginfo parameters.  Adjust all
	callers.  Look for external debug info notes, and try to fetch
	debug info from external file.
	(struct phdr_data): Add exe_filename field.
	(phdr_callback): Pass filename to elf_add.
	(backtrace_initialize): Add filename parameter.
	* internal.h (backtrace_initialize): Add filename parameter.
	* fileline.c (fileline_initialize): Pass filename to
	backtrace_initialize.
	* pecoff.c (fileline_initialize): Add unused filename parameter.
	* unknown.c (fileline_initialize): Likewise.
	* xcoff.c (fileline_initialize): Likewise.
	* configure.ac: Check for objcopy --add-gnu-debuglink.
	* Makefile.am (dtest): New test target.
	* configure, Makefile.in: Rebuild.

Co-Authored-By: Denis Khalikov <d.khalikov@partner.samsung.com>

From-SVN: r253032
parent 2ffb5745
2017-09-20 Ian Lance Taylor <iant@golang.org>
Denis Khalikov <d.khalikov@partner.samsung.com>
PR sanitizer/77631
Support for external debug info.
* elf.c: Include <errno.h>, <sys/stat.h>, <unistd.h>.
(S_ISLNK): Define if not defined.
(xstrnlen): Define if strnlen is not available.
(b_elf_note): Define type.
(NT_GNU_BUILD_ID): Define macro.
(elf_crc32, elf_crc32_file): New static functions.
(elf_is_symlink, elf_readlink): New static functions.
(elf_open_debugfile_by_buildid): New static function.
(elf_try_debugfile): New static function.
(elf_find_debugfile_by_debuglink): New static function.
(elf_open_debugfile_by_debuglink): New static function.
(elf_add): Add filename and debuginfo parameters. Adjust all
callers. Look for external debug info notes, and try to fetch
debug info from external file.
(struct phdr_data): Add exe_filename field.
(phdr_callback): Pass filename to elf_add.
(backtrace_initialize): Add filename parameter.
* internal.h (backtrace_initialize): Add filename parameter.
* fileline.c (fileline_initialize): Pass filename to
backtrace_initialize.
* pecoff.c (fileline_initialize): Add unused filename parameter.
* unknown.c (fileline_initialize): Likewise.
* xcoff.c (fileline_initialize): Likewise.
* configure.ac: Check for objcopy --add-gnu-debuglink.
* Makefile.am (dtest): New test target.
* configure, Makefile.in: Rebuild.
2017-09-12 Steve Ellcey <sellcey@cavium.com>
PR other/81096
......
......@@ -122,6 +122,16 @@ ttest_LDADD = libbacktrace.la
endif HAVE_PTHREAD
if HAVE_OBJCOPY_DEBUGLINK
TESTS += dtest
dtest: btest
$(OBJCOPY) --only-keep-debug btest btest.debug
$(OBJCOPY) --strip-debug --add-gnu-debuglink=btest.debug btest dtest
endif HAVE_OBJCOPY_DEBUGLINK
endif NATIVE
# We can't use automake's automatic dependency tracking, because it
......
......@@ -86,6 +86,7 @@ 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
subdir = .
DIST_COMMON = README ChangeLog $(srcdir)/Makefile.in \
$(srcdir)/Makefile.am $(top_srcdir)/configure \
......@@ -217,6 +218,7 @@ MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJCOPY = @OBJCOPY@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
OTOOL = @OTOOL@
......@@ -343,7 +345,7 @@ libbacktrace_la_LIBADD = \
$(ALLOC_FILE)
libbacktrace_la_DEPENDENCIES = $(libbacktrace_la_LIBADD)
TESTS = $(check_PROGRAMS)
TESTS = $(check_PROGRAMS) $(am__append_3)
@NATIVE_TRUE@btest_SOURCES = btest.c testlib.c
@NATIVE_TRUE@btest_CFLAGS = $(AM_CFLAGS) -g -O
@NATIVE_TRUE@btest_LDADD = libbacktrace.la
......@@ -799,6 +801,10 @@ uninstall-am:
@NATIVE_TRUE@ cat $(srcdir)/edtest2.c > tmp-edtest2_build.c
@NATIVE_TRUE@ $(SHELL) $(srcdir)/../move-if-change tmp-edtest2_build.c edtest2_build.c
@NATIVE_TRUE@ echo timestamp > $@
@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@dtest: btest
@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@ $(OBJCOPY) --only-keep-debug btest btest.debug
@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@ $(OBJCOPY) --strip-debug --add-gnu-debuglink=btest.debug btest dtest
alloc.lo: config.h backtrace.h internal.h
backtrace.lo: config.h backtrace.h internal.h
btest.lo: (INCDIR)/filenames.h backtrace.h backtrace-supported.h
......
......@@ -604,6 +604,9 @@ LTLIBOBJS
LIBOBJS
NATIVE_FALSE
NATIVE_TRUE
HAVE_OBJCOPY_DEBUGLINK_FALSE
HAVE_OBJCOPY_DEBUGLINK_TRUE
OBJCOPY
HAVE_PTHREAD_FALSE
HAVE_PTHREAD_TRUE
PTHREAD_CFLAGS
......@@ -746,7 +749,8 @@ CFLAGS
LDFLAGS
LIBS
CPPFLAGS
CPP'
CPP
OBJCOPY'
# Initialize some variables set by options.
......@@ -1396,6 +1400,7 @@ Some influential environment variables:
CPPFLAGS C/C++/Objective C preprocessor flags, e.g. -I<include dir> if
you have headers in a nonstandard directory <include dir>
CPP C preprocessor
OBJCOPY location of objcopy
Use these variables to override the choices made by `configure' or to help
it to find libraries and programs with nonstandard names/locations.
......@@ -11136,7 +11141,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 11139 "configure"
#line 11144 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
......@@ -11242,7 +11247,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext <<_LT_EOF
#line 11245 "configure"
#line 11250 "configure"
#include "confdefs.h"
#if HAVE_DLFCN_H
......@@ -12761,6 +12766,69 @@ else
fi
# Extract the first word of "objcopy", so it can be a program name with args.
set dummy objcopy; ac_word=$2
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
$as_echo_n "checking for $ac_word... " >&6; }
if test "${ac_cv_prog_OBJCOPY+set}" = set; then :
$as_echo_n "(cached) " >&6
else
if test -n "$OBJCOPY"; then
ac_cv_prog_OBJCOPY="$OBJCOPY" # 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 { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then
ac_cv_prog_OBJCOPY="objcopy"
$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
OBJCOPY=$ac_cv_prog_OBJCOPY
if test -n "$OBJCOPY"; then
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $OBJCOPY" >&5
$as_echo "$OBJCOPY" >&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_n "checking whether objcopy supports debuglink... " >&6; }
if test "${libbacktrace_cv_objcopy_debuglink+set}" = set; then :
$as_echo_n "(cached) " >&6
else
if test -n "${with_target_subdir}"; then
libbacktrace_cv_objcopy_debuglink=no
elif ${OBJCOPY} --add-gnu-debuglink=x /bin/ls /tmp/ls$$; then
rm -f /tmp/ls$$
libbacktrace_cv_objcopy_debuglink=yes
else
libbacktrace_cv_objcopy_debuglink=no
fi
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $libbacktrace_cv_objcopy_debuglink" >&5
$as_echo "$libbacktrace_cv_objcopy_debuglink" >&6; }
if test "$libbacktrace_cv_objcopy_debuglink" = yes; then
HAVE_OBJCOPY_DEBUGLINK_TRUE=
HAVE_OBJCOPY_DEBUGLINK_FALSE='#'
else
HAVE_OBJCOPY_DEBUGLINK_TRUE='#'
HAVE_OBJCOPY_DEBUGLINK_FALSE=
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether tests can run" >&5
$as_echo_n "checking whether tests can run... " >&6; }
if test "${libbacktrace_cv_sys_native+set}" = set; then :
......@@ -12927,6 +12995,10 @@ 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_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
fi
if test -z "${NATIVE_TRUE}" && test -z "${NATIVE_FALSE}"; then
as_fn_error "conditional \"NATIVE\" was never defined.
Usually this means the macro was only invoked conditionally." "$LINENO" 5
......
......@@ -404,6 +404,20 @@ AC_SUBST(PTHREAD_CFLAGS)
AM_CONDITIONAL(HAVE_PTHREAD, test "$libgo_cv_lib_pthread" = yes)
AC_ARG_VAR(OBJCOPY, [location of objcopy])
AC_CHECK_PROG(OBJCOPY, objcopy, objcopy,)
AC_CACHE_CHECK([whether objcopy supports debuglink],
[libbacktrace_cv_objcopy_debuglink],
[if test -n "${with_target_subdir}"; then
libbacktrace_cv_objcopy_debuglink=no
elif ${OBJCOPY} --add-gnu-debuglink=x /bin/ls /tmp/ls$$; then
rm -f /tmp/ls$$
libbacktrace_cv_objcopy_debuglink=yes
else
libbacktrace_cv_objcopy_debuglink=no
fi])
AM_CONDITIONAL(HAVE_OBJCOPY_DEBUGLINK, test "$libbacktrace_cv_objcopy_debuglink" = yes)
AC_CACHE_CHECK([whether tests can run],
[libbacktrace_cv_sys_native],
[AC_RUN_IFELSE([AC_LANG_PROGRAM([], [return 0;])],
......
......@@ -58,6 +58,7 @@ fileline_initialize (struct backtrace_state *state,
int pass;
int called_error_callback;
int descriptor;
const char *filename;
char buf[64];
if (!state->threaded)
......@@ -84,7 +85,6 @@ fileline_initialize (struct backtrace_state *state,
called_error_callback = 0;
for (pass = 0; pass < 5; ++pass)
{
const char *filename;
int does_not_exist;
switch (pass)
......@@ -140,8 +140,8 @@ fileline_initialize (struct backtrace_state *state,
if (!failed)
{
if (!backtrace_initialize (state, descriptor, error_callback, data,
&fileline_fn))
if (!backtrace_initialize (state, filename, descriptor, error_callback,
data, &fileline_fn))
failed = 1;
}
......
......@@ -268,6 +268,7 @@ extern int backtrace_vector_release (struct backtrace_state *state,
appropriate one. */
extern int backtrace_initialize (struct backtrace_state *state,
const char *filename,
int descriptor,
backtrace_error_callback error_callback,
void *data,
......
......@@ -890,7 +890,8 @@ coff_add (struct backtrace_state *state, int descriptor,
sections. */
int
backtrace_initialize (struct backtrace_state *state, int descriptor,
backtrace_initialize (struct backtrace_state *state,
const char *filename ATTRIBUTE_UNUSED, int descriptor,
backtrace_error_callback error_callback,
void *data, fileline *fileline_fn)
{
......
......@@ -54,6 +54,7 @@ unknown_fileline (struct backtrace_state *state ATTRIBUTE_UNUSED,
int
backtrace_initialize (struct backtrace_state *state ATTRIBUTE_UNUSED,
const char *filename ATTRIBUTE_UNUSED,
int descriptor ATTRIBUTE_UNUSED,
backtrace_error_callback error_callback ATTRIBUTE_UNUSED,
void *data ATTRIBUTE_UNUSED, fileline *fileline_fn)
......
......@@ -1434,7 +1434,8 @@ xcoff_add_shared_libs (struct backtrace_state *state,
Returns 1 on success, 0 on failure. */
int
backtrace_initialize (struct backtrace_state *state, int descriptor,
backtrace_initialize (struct backtrace_state *state,
const char *filename ATTRIBUTE_UNUSED, int descriptor,
backtrace_error_callback error_callback,
void *data, fileline *fileline_fn)
{
......
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