libbacktrace: avoid infinite recursion

We could get an infinite recursion in an odd case in which a
.gnu_debugdata section was added to a debug file, and mini_debuginfo
was put into the debug file, and the debug file was put into a
/usr/lib/debug directory to be found by build ID.  This combination
doesn't really make sense but we shouldn't get an infinite recursion.

	* elf.c (elf_add): Don't use .gnu_debugdata if we are already
	reading a debuginfo file.
	* Makefile.am (m2test_*): New test targets.
	(CHECK_PROGRAMS): Add m2test.
	(MAKETESTS): Add m2test_minidebug2.
	(%_minidebug2): New pattern.
	(CLEANFILES): Remove minidebug2 files.
	* Makefile.in: Regenerate.

Fixes #129
This commit is contained in:
Ian Lance Taylor
2024-07-11 19:36:00 -07:00
parent 1023a09511
commit febbb9bff9
3 changed files with 134 additions and 42 deletions

View File

@@ -595,6 +595,39 @@ MAKETESTS += mtest_minidebug
$(OBJCOPY) --add-section .gnu_debugdata=$<.mdbg.xz $<.strip
mv $<.strip $@
if HAVE_ELF
if HAVE_BUILDID
if HAVE_OBJCOPY_DEBUGLINK
m2test_SOURCES = $(mtest_SOURCES)
m2test_CFLAGS = $(libbacktrace_TEST_CFLAGS) -O
m2test_LDFLAGS = -Wl,--build-id $(libbacktrace_testing_ldflags)
m2test_LDADD = libbacktrace_elf_for_test.la
check_PROGRAMS += m2test
MAKETESTS += m2test_minidebug2
# minidebug2 is like minidebug but also adds the gnu_debugdata section
# to the debug file, and uses a build ID file. There is no reason to do
# this but it was causing an infinite recursion.
%_minidebug2: %
$(NM) -D $< -P --defined-only | $(AWK) '{ print $$1 }' | sort > $<.dsyms2
$(NM) $< -P --defined-only | $(AWK) '{ if ($$2 == "T" || $$2 == "t" || $$2 == "D") print $$1 }' | sort > $<.fsyms2
$(COMM) -13 $<.dsyms2 $<.fsyms2 > $<.keepsyms2
$(OBJCOPY) --only-keep-debug $< $<.dbg2
$(OBJCOPY) -S --remove-section .gdb_index --remove-section .comment --keep-symbols=$<.keepsyms2 $<.dbg2 $<.mdbg2
$(OBJCOPY) --strip-all --remove-section ..comment $< $<.strip2
rm -f $<.mdbg2.xz
$(XZ) $<.mdbg2
$(OBJCOPY) --add-section .gnu_debugdata=$<.mdbg2.xz $<.dbg2
$(OBJCOPY) --add-section .gnu_debugdata=$<.mdbg2.xz $<.strip2
$(SHELL) ./install-debuginfo-for-buildid.sh $(TEST_BUILD_ID_DIR) $<.dbg2
mv $<.strip2 $@
endif HAVE_OBJCOPY_DEBUGLINK
endif HAVE_BUILDID
endif HAVE_ELF
endif HAVE_MINIDEBUG
endif NATIVE
@@ -630,7 +663,8 @@ TESTS += $(MAKETESTS) $(BUILDTESTS)
CLEANFILES = \
$(MAKETESTS) $(BUILDTESTS) *.debug elf_for_test.c edtest2_build.c \
gen_edtest2_build \
*.dsyms *.fsyms *.keepsyms *.dbg *.mdbg *.mdbg.xz *.strip
*.dsyms *.fsyms *.keepsyms *.dbg *.mdbg *.mdbg.xz *.strip \
*.dsyms2 *.fsyms2 *.keepsyms2 *.dbg2 *.mdbg2 *.mdbg2.xz *.strip2
clean-local:
-rm -rf usr