Skip to content

Commit

Permalink
debugedit: Support String/Line table rewriting for larger/smaller paths.
Browse files Browse the repository at this point in the history
debugedit --base to --dest rewriting of debug source file paths only
supported dest paths that were smaller or equal than the base path
(and the size should differ more than 1 character for correct debug lines).
All paths were changed "in place". Which could in theory mess up debug str
sharing.

This rewrite supports base and dest strings of any size (some limitations,
see below). This is done by reconstructing the debug_str and debug_line
tables and updating the references in the debug_info attributes pointing
to these tables. Plus, if necessary (only for ET_REL kernel modules),
updating any relocations for the debug_info and debug_line sections.

This has the nice benefit of merging any duplicate strings in the
debug_str table which might resulting on slightly smaller files.
kernel modules are ET_REL files that often contain a lot of duplicate
strings.

The rewrite uses elfutils (either libebl or libdw) to reconstruct the
debug_str table. Since we are changing some section sizes now we cannot
just use mmap and rawdata to poke the values, but need to read in and
write out the changed sections. This does take a bit more memory because
we now also need to keep track of all string/line references.

There are still some limitations (already in the original debugedit)
not fixed by this rewrite:
- DW_AT_comp_dir in .debug_info using DW_FORM_string can not be made
  larger. We only warn about that now instead of failing. The only
  producer of DW_FORM_string comp_dirs is binutils gas. It seems simpler
  to fix gas than to try to support resizing the debug_info section.
- A DW_AT_name on a DW_TAG_compile_unit is only rewritten for DW_FORM_strp
  not for DW_FORM_string. Probably no problem in practice since this
  wasn't supported originally either.
- The debug_line program isn't scanned for DW_LNE_define_file which
  could in theory define an absolute path that might need rewriting.
  Again probably not a problem because this wasn't supported before
  and there are no know producers for this construct.

To support the upcoming DWARFv5 in gcc 7 (not on by default), we will
need to add support for the new debug_line format and scan the new
debug_macro section that can have references to the debug_str table.

Signed-off-by: Mark Wielaard <mark@klomp.org>
  • Loading branch information
Mark Wielaard authored and pmatilai committed Mar 6, 2017
1 parent 2d9c8cc commit 8898957
Show file tree
Hide file tree
Showing 3 changed files with 1,330 additions and 253 deletions.
8 changes: 7 additions & 1 deletion Makefile.am
Expand Up @@ -155,13 +155,18 @@ rpm2archive_LDADD += @WITH_BEECRYPT_LIB@ @WITH_NSS_LIB@ @WITH_OPENSSL_LIB@ @WITH

if LIBELF
if LIBDWARF
if LIBDW
rpmconfig_SCRIPTS += scripts/find-debuginfo.sh

rpmlibexec_PROGRAMS += debugedit
debugedit_SOURCES = tools/debugedit.c tools/hashtab.c tools/hashtab.h
debugedit_LDADD = rpmio/librpmio.la
debugedit_LDADD += @WITH_LIBELF_LIB@ @WITH_POPT_LIB@

if HAVE_LIBDW_STRTAB
debugedit_LDADD += @WITH_LIBDW_LIB@
else
debugedit_LDADD += @WITH_LIBDW_LIB@ -lebl
endif
rpmlibexec_PROGRAMS += elfdeps
elfdeps_SOURCES = tools/elfdeps.c
elfdeps_LDADD = rpmio/librpmio.la
Expand All @@ -172,6 +177,7 @@ sepdebugcrcfix_SOURCES = tools/sepdebugcrcfix.c
sepdebugcrcfix_LDADD = @WITH_LIBELF_LIB@
endif
endif
endif

rpmlibexec_PROGRAMS += rpmdeps
rpmdeps_SOURCES = tools/rpmdeps.c
Expand Down
6 changes: 6 additions & 0 deletions configure.ac
Expand Up @@ -463,18 +463,24 @@ AM_CONDITIONAL(WITH_ARCHIVE,[test "$with_archive" = yes])
#=================
# Check for elfutils libdw library with dwelf_elf_gnu_build_id.
WITH_LIBDW_LIB=
HAVE_LIBDW_STRTAB=
AS_IF([test "$WITH_LIBELF" = yes],[
AC_CHECK_HEADERS([elfutils/libdwelf.h],[
# dwelf_elf_gnu_build_id was introduced in elfutils 0.159
AC_CHECK_LIB(dw, dwelf_elf_gnu_build_id, [
AC_DEFINE(HAVE_LIBDW, 1,
[Define to 1 if you have elfutils libdw library])
WITH_LIBDW_LIB="-ldw"
WITH_LIBDW=yes
# If possible we also want the strtab functions from elfutils 0.167.
# But we can fall back on the (unsupported) ebl alternatives if not.
AC_CHECK_LIB(dw, dwelf_strtab_init, [HAVE_LIBDW_STRTAB=yes])
])
])
])
AC_SUBST(WITH_LIBDW_LIB)
AM_CONDITIONAL(LIBDW,[test "$WITH_LIBDW" = yes])
AM_CONDITIONAL(HAVE_LIBDW_STRTAB,[test "$HAVE_LIBDW_STRTAB" = yes])

#=================
# Process --with/without-external-db
Expand Down

0 comments on commit 8898957

Please sign in to comment.