Skip to content

Commit

Permalink
PR sanitizer/77631
Browse files Browse the repository at this point in the history
	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.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@253032 138bc75d-0d04-0410-961f-82ee72b054a4
  • Loading branch information
ian committed Sep 20, 2017
1 parent e6b5fa1 commit b919941
Show file tree
Hide file tree
Showing 11 changed files with 705 additions and 19 deletions.
32 changes: 32 additions & 0 deletions libbacktrace/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
2017-09-20 Ian Lance Taylor <[email protected]>
Denis Khalikov <[email protected]>

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 <[email protected]>

PR other/81096
Expand Down
10 changes: 10 additions & 0 deletions libbacktrace/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion libbacktrace/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -217,6 +218,7 @@ MAKEINFO = @MAKEINFO@
MKDIR_P = @MKDIR_P@
NM = @NM@
NMEDIT = @NMEDIT@
OBJCOPY = @OBJCOPY@
OBJDUMP = @OBJDUMP@
OBJEXT = @OBJEXT@
OTOOL = @OTOOL@
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
78 changes: 75 additions & 3 deletions libbacktrace/configure
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -746,7 +749,8 @@ CFLAGS
LDFLAGS
LIBS
CPPFLAGS
CPP'
CPP
OBJCOPY'


# Initialize some variables set by options.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 :
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions libbacktrace/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -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;])],
Expand Down
Loading

0 comments on commit b919941

Please sign in to comment.