On 25-01-19 01:51, Ian Lance Taylor wrote: > On Thu, Jan 24, 2019 at 4:11 PM Nathan Sidwell <nat...@acm.org> wrote: >> >> I just tripped over a segfault in libbacktrace. We apply strrchr to a >> possibly NULL filename, with predictable results when it is. >> >> elf.c:3044 passes NULL as the filename parm: >> ret = elf_add (state, NULL, d, base_address, error_callback, data, >> fileline_fn, found_sym, found_dwarf, NULL, 0, 1, >> NULL, >> 0); >> >> This gets to elf_open_debugfile_by_debuglink which passes it on through: >> ddescriptor = elf_find_debugfile_by_debuglink (state, filename, >> debuglink_name, >> error_callback, data); >> >> this patch avoids the strrchr when filename is null. I reordered the >> way prefix & prefix len got set, finding it prefereable to: >> slash = filename ? NULL : strrchr (filename, '/'); >> but if you prefer to avoid the assignment in the conditional I'm fine >> with that too. > > Yeah, please don't do an assignment in a conditional. > > Why don't we just pass "" instead of NULL in the call to elf_add? If > that works, that is OK. >
With this refactoring preamble ...
[libbacktrace] Rename dtest to btest_gnudebuglink Create a pattern rule for copying an existing test-case, separating out the debug information into a .debug file, and referencing the .debug file from the copied test-case using a .gnu_debuglink. 2019-01-25 Tom de Vries <tdevr...@suse.de> * Makefile.am: Rewrite dtest rule into "%_gnudebuglink" pattern rule. (TESTS): Rename dtest to btest_gnudebuglink. * Makefile.in: Regenerate. --- libbacktrace/Makefile.am | 8 ++++---- libbacktrace/Makefile.in | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/libbacktrace/Makefile.am b/libbacktrace/Makefile.am index bf90ebdb2d5..2f1d9af89c3 100644 --- a/libbacktrace/Makefile.am +++ b/libbacktrace/Makefile.am @@ -255,11 +255,11 @@ endif HAVE_PTHREAD if HAVE_OBJCOPY_DEBUGLINK -TESTS += dtest +TESTS += btest_gnudebuglink -dtest: btest - $(OBJCOPY) --only-keep-debug btest btest.debug - $(OBJCOPY) --strip-debug --add-gnu-debuglink=btest.debug btest dtest +%_gnudebuglink: % + $(OBJCOPY) --only-keep-debug $< $@.debug + $(OBJCOPY) --strip-debug --add-gnu-debuglink=$@.debug $< $@ endif HAVE_OBJCOPY_DEBUGLINK diff --git a/libbacktrace/Makefile.in b/libbacktrace/Makefile.in index d55e0501171..0b73e3d6981 100644 --- a/libbacktrace/Makefile.in +++ b/libbacktrace/Makefile.in @@ -130,7 +130,7 @@ check_PROGRAMS = $(am__EXEEXT_1) $(am__EXEEXT_2) $(am__EXEEXT_3) @HAVE_ZLIB_TRUE@@NATIVE_TRUE@am__append_4 = -lz @HAVE_ZLIB_TRUE@@NATIVE_TRUE@am__append_5 = -lz @HAVE_PTHREAD_TRUE@@NATIVE_TRUE@am__append_6 = ttest ttest_alloc -@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@am__append_7 = dtest +@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@am__append_7 = btest_gnudebuglink @HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@am__append_8 = ctestg ctesta \ @HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@ ctestg_alloc \ @HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@ ctesta_alloc @@ -1585,9 +1585,9 @@ btest_dwz.log: btest_dwz --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ "$$tst" $(AM_TESTS_FD_REDIRECT) -dtest.log: dtest - @p='dtest'; \ - b='dtest'; \ +btest_gnudebuglink.log: btest_gnudebuglink + @p='btest_gnudebuglink'; \ + b='btest_gnudebuglink'; \ $(am__check_pre) $(LOG_DRIVER) --test-name "$$f" \ --log-file $$b.log --trs-file $$b.trs \ $(am__common_driver_flags) $(AM_LOG_DRIVER_FLAGS) $(LOG_DRIVER_FLAGS) -- $(LOG_COMPILE) \ @@ -1767,9 +1767,9 @@ uninstall-am: @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 +@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@%_gnudebuglink: % +@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@ $(OBJCOPY) --only-keep-debug $< $@.debug +@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@ $(OBJCOPY) --strip-debug --add-gnu-debuglink=$@.debug $< $@ 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