libbacktrace: read symbol table of debuginfo file

These become another symbol table to search.  This is needed if people
use --strip-all rather than --strip-debug when adding a debuglink
section.

Patch is from GitHub user pickard1.

Fixes https://github.com/ianlancetaylor/libbacktrace/issues/113.

	* elf.c (elf_add): Add the symbol table from a debuginfo file.
	* Makefile.am (MAKETESTS): Add buildidfull and gnudebuglinkfull
	variants of buildid and gnudebuglink tests.
	(%_gnudebuglinkfull, %_buildidfull): New patterns.
	* Makefile.in: Regenerate.
This commit is contained in:
Ian Lance Taylor 2024-02-29 19:44:19 -08:00
parent b05f474c8f
commit c6d4fb0062
3 changed files with 48 additions and 7 deletions

View File

@ -257,7 +257,7 @@ b2test_LDFLAGS = -Wl,--build-id
b2test_LDADD = libbacktrace_elf_for_test.la
check_PROGRAMS += b2test
MAKETESTS += b2test_buildid
MAKETESTS += b2test_buildid b2test_buildidfull
if HAVE_DWZ
@ -267,7 +267,7 @@ b3test_LDFLAGS = -Wl,--build-id
b3test_LDADD = libbacktrace_elf_for_test.la
check_PROGRAMS += b3test
MAKETESTS += b3test_dwz_buildid
MAKETESTS += b3test_dwz_buildid b3test_dwz_buildidfull
endif HAVE_DWZ
@ -443,12 +443,16 @@ endif HAVE_PTHREAD
if HAVE_OBJCOPY_DEBUGLINK
MAKETESTS += btest_gnudebuglink
MAKETESTS += btest_gnudebuglink btest_gnudebuglinkfull
%_gnudebuglink: %
$(OBJCOPY) --only-keep-debug $< $@.debug
$(OBJCOPY) --strip-debug --add-gnu-debuglink=$@.debug $< $@
%_gnudebuglinkfull: %
$(OBJCOPY) --only-keep-debug $< $@.debug
$(OBJCOPY) --strip-all --add-gnu-debuglink=$@.debug $< $@
endif HAVE_OBJCOPY_DEBUGLINK
%_buildid: %
@ -457,6 +461,12 @@ endif HAVE_OBJCOPY_DEBUGLINK
$<
$(OBJCOPY) --strip-debug $< $@
%_buildidfull: %
./install-debuginfo-for-buildid.sh \
"$(TEST_BUILD_ID_DIR)" \
$<
$(OBJCOPY) --strip-all $< $@
if HAVE_COMPRESSED_DEBUG
ctestg_SOURCES = btest.c testlib.c

View File

@ -134,9 +134,9 @@ TESTS = $(am__append_4) $(MAKETESTS) $(am__EXEEXT_16)
@NATIVE_TRUE@@USE_DSYMUTIL_TRUE@ stest.dSYM stest_alloc.dSYM \
@NATIVE_TRUE@@USE_DSYMUTIL_TRUE@ edtest.dSYM edtest_alloc.dSYM
@HAVE_BUILDID_TRUE@@HAVE_ELF_TRUE@@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@am__append_6 = b2test
@HAVE_BUILDID_TRUE@@HAVE_ELF_TRUE@@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@am__append_7 = b2test_buildid
@HAVE_BUILDID_TRUE@@HAVE_ELF_TRUE@@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@am__append_7 = b2test_buildid b2test_buildidfull
@HAVE_BUILDID_TRUE@@HAVE_DWZ_TRUE@@HAVE_ELF_TRUE@@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@am__append_8 = b3test
@HAVE_BUILDID_TRUE@@HAVE_DWZ_TRUE@@HAVE_ELF_TRUE@@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@am__append_9 = b3test_dwz_buildid
@HAVE_BUILDID_TRUE@@HAVE_DWZ_TRUE@@HAVE_ELF_TRUE@@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@am__append_9 = b3test_dwz_buildid b3test_dwz_buildidfull
@HAVE_ELF_TRUE@@NATIVE_TRUE@am__append_10 = btest_lto
@NATIVE_TRUE@am__append_11 = btest_alloc stest stest_alloc
@HAVE_DWZ_TRUE@@NATIVE_TRUE@am__append_12 = btest_dwz
@ -152,7 +152,7 @@ TESTS = $(am__append_4) $(MAKETESTS) $(am__EXEEXT_16)
@HAVE_PTHREAD_TRUE@@NATIVE_TRUE@@USE_DSYMUTIL_TRUE@am__append_21 = \
@HAVE_PTHREAD_TRUE@@NATIVE_TRUE@@USE_DSYMUTIL_TRUE@ ttest.dSYM \
@HAVE_PTHREAD_TRUE@@NATIVE_TRUE@@USE_DSYMUTIL_TRUE@ ttest_alloc.dSYM
@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@am__append_22 = btest_gnudebuglink
@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@am__append_22 = btest_gnudebuglink btest_gnudebuglinkfull
@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@am__append_23 = ctestg ctesta
@HAVE_COMPRESSED_DEBUG_TRUE@@HAVE_COMPRESSED_DEBUG_ZSTD_TRUE@@NATIVE_TRUE@am__append_24 = ctestzstd
@HAVE_COMPRESSED_DEBUG_TRUE@@NATIVE_TRUE@am__append_25 = ctestg_alloc ctesta_alloc
@ -2113,6 +2113,13 @@ b2test_buildid.log: b2test_buildid
--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)
b2test_buildidfull.log: b2test_buildidfull
@p='b2test_buildidfull'; \
b='b2test_buildidfull'; \
$(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) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
b3test_dwz_buildid.log: b3test_dwz_buildid
@p='b3test_dwz_buildid'; \
b='b3test_dwz_buildid'; \
@ -2120,6 +2127,13 @@ b3test_dwz_buildid.log: b3test_dwz_buildid
--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)
b3test_dwz_buildidfull.log: b3test_dwz_buildidfull
@p='b3test_dwz_buildidfull'; \
b='b3test_dwz_buildidfull'; \
$(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) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
btest_dwz.log: btest_dwz
@p='btest_dwz'; \
b='btest_dwz'; \
@ -2141,6 +2155,13 @@ btest_gnudebuglink.log: btest_gnudebuglink
--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)
btest_gnudebuglinkfull.log: btest_gnudebuglinkfull
@p='btest_gnudebuglinkfull'; \
b='btest_gnudebuglinkfull'; \
$(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) \
"$$tst" $(AM_TESTS_FD_REDIRECT)
mtest_minidebug.log: mtest_minidebug
@p='mtest_minidebug'; \
b='mtest_minidebug'; \
@ -2578,12 +2599,22 @@ uninstall-am:
@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@ $(OBJCOPY) --only-keep-debug $< $@.debug
@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@ $(OBJCOPY) --strip-debug --add-gnu-debuglink=$@.debug $< $@
@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@%_gnudebuglinkfull: %
@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@ $(OBJCOPY) --only-keep-debug $< $@.debug
@HAVE_OBJCOPY_DEBUGLINK_TRUE@@NATIVE_TRUE@ $(OBJCOPY) --strip-all --add-gnu-debuglink=$@.debug $< $@
@NATIVE_TRUE@%_buildid: %
@NATIVE_TRUE@ ./install-debuginfo-for-buildid.sh \
@NATIVE_TRUE@ "$(TEST_BUILD_ID_DIR)" \
@NATIVE_TRUE@ $<
@NATIVE_TRUE@ $(OBJCOPY) --strip-debug $< $@
@NATIVE_TRUE@%_buildidfull: %
@NATIVE_TRUE@ ./install-debuginfo-for-buildid.sh \
@NATIVE_TRUE@ "$(TEST_BUILD_ID_DIR)" \
@NATIVE_TRUE@ $<
@NATIVE_TRUE@ $(OBJCOPY) --strip-all $< $@
@HAVE_MINIDEBUG_TRUE@@NATIVE_TRUE@%_minidebug: %
@HAVE_MINIDEBUG_TRUE@@NATIVE_TRUE@ $(NM) -D $< -P --defined-only | $(AWK) '{ print $$1 }' | sort > $<.dsyms
@HAVE_MINIDEBUG_TRUE@@NATIVE_TRUE@ $(NM) $< -P --defined-only | $(AWK) '{ if ($$2 == "T" || $$2 == "t" || $$2 == "D") print $$1 }' | sort > $<.fsyms

View File

@ -6872,7 +6872,7 @@ elf_add (struct backtrace_state *state, const char *filename, int descriptor,
if (symtab_shndx == 0)
symtab_shndx = dynsym_shndx;
if (symtab_shndx != 0 && !debuginfo)
if (symtab_shndx != 0)
{
const b_elf_shdr *symtab_shdr;
unsigned int strtab_shndx;