Commit Graph

143 Commits

Author SHA1 Message Date
90136608c8 Merge (theirs) branch 'debugedit' into sisyphus
On rpm commit 98b71f7a92e8e9d902e2bfcd6c30af84dd80289b:
  $ git fast-export HEAD -- tools/debugedit.c > a

On rpm-build:
  $ git fast-import < a
  $ git br -m master debugedit
  $ git merge -X theirs --allow-unrelated-histories debugedit
2020-11-09 22:36:32 +03:00
dfc381d732 debugedit: Fix 'canonicalization unexpectedly shrank by one character'
Do not let canonicalization shrink directory name by 1 character. Or else
that would prevent (in-place) changing of Directory Table entries in
.debug_line section, causing following error in brp-debuginfo:

  /usr/lib/rpm/debugedit: canonicalization unexpectedly shrank by one character

Fixes: https://bugzilla.altlinux.org/show_bug.cgi?id=39184
2020-11-06 15:16:45 +03:00
Jan Kratochvil
c93ac72a8e debugedit: Fix missing relocation of .debug_types section. 2020-08-12 11:21:13 +03:00
Jan Kratochvil
612e1ecd4c [NFC] debugedit: Move code from edit_dwarf2() to edit_info(). 2020-08-12 11:21:13 +03:00
1f2ad272a1 debugedit: Add -n to avoid recomputing of build-id
Avoid `DWARF version 0 unhandled' for compressed ELFs in
find-debuginfo-files.

Based on 6e9fd97f6 ("debugedit: Add -n, --no-recompute-build-id.")
by Mark Wielaard <mark@klomp.org>.
2020-07-05 01:06:16 +03:00
5133ad68aa setcmp: use 'm' instead of 'a' as the assignment-allocation modifier
Support for the 'm' modifier was added to glibc starting with version 2.7,
programs should use that modifier instead of 'a'.
2019-11-24 11:58:18 +00:00
Mark Wielaard
add384514f debugedit: Make sure .debug_line old/new idx start equal.
Found by running the debugedit tests under valgrind.
If the old and new .debug_line offset isn't changed then we might
write out an uninitialized new_idx.
2019-06-19 15:06:55 +03:00
Mark Wielaard
15118eb683 Handle .debug_macro in debugedit.
When compiling with -g3 gcc will generate a .debug_macro section
which has pointers to the .debug_str section. Since we might rewrite
the .debug_str section, we also need to update any .debug_macro
pointers.

Updated the debugedit.at testcase by building everything with -g
and add various checks to see the .debug_macro section looks OK
after running debugedit. Added a new rpmbuild.at testcase to check
handing of .debug_macro in the whole rpmbuild debuginfo pipeline
to double check the separate .debug file also contains the macros.

Original patch by Michael Schroeder <mls@suse.de>. Extended by
Mark Wielaard <mark@klomp.org> to deal with relocations and possible
multiple COMDAT .debug_macro sections.
2019-06-19 15:06:55 +03:00
Mark Wielaard
5d7ca6efec debugedit: Refactor reading/writing of relocated values.
This refactors the reading and writing of relocated values into seperate
helper functions (setup_relbuf and update_rela_data). It will be easier
to reuse this code in case we want to read/write relocated values in other
sections than DEBUG_INFO. The only functional change is that we explicitly
track whether the relocation data is updated, and only explicitly update
and write out the relocation data if so. In the case there were no strp
or stmt updates, there will also not be any relocation updates, even if
there is relocation data available.

All new debugedit testcases pass before and after this refactoring.
2019-06-19 15:06:55 +03:00
Mark Wielaard
83e6accd81 Add some debugedit tests.
debugedit didn't have any direct tests, it was only tested indirectly
through some other debuginfo testcases.  So add some testcases that
just test debugedit functionality directly.

The tests create different kinds of ELF files (object files, partially
linked files and executables) and run debugedit path replacements on
them, checking that the resulting .debug_str, .debug_info and .debug_line
sections look sane.

Testcases verified against various different gcc and binutils versions.
gcc 4.8 and gcc 6 generate slightly different .debuginfo

Also add debugedit --version. Which makes it easy to see we are
testing the correct version/install of debugedit in rpmtests.log.

Adjust autotest paths to include rpmlibexecdir, where debuginfo
is installed.  Note that rpmlibexecdir != libexecdir (see rpm.am).
2019-06-19 15:06:55 +03:00
0ea2deffe3 suggest_bpp: fix harmless off-by-one error in bpp estimation
Give detailed explanation of the formulae which makes the mistake obvious.

Also rewrite suggest_bpp from perl to C.
2019-01-20 23:40:39 +00:00
Mark Wielaard
9f6127af4d debugedit: Only try to collect comp_dir in phase zero.
edit_attributes is run twice. Once for phase zero in which all strings are
collected. Then then for phase one in which the strings are rewritten. In
phase zero we also try to collect the comp_dir (either from the
DW_AT_comp_dir or the DW_AT_name of the compile unit). We were also
collecting the comp_dir is phase 1, which is unnecessary, and would not
actually work, since we would be using to old string table index for that,
which had already been rewritten.

Caught by the new string table index checks.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2018-03-12 15:29:19 +02:00
Mark Wielaard
df15b0d018 debugedit: Check .debug_str index is valid before use.
debugedit would blindly use an .debug_str index from the .debug_info or
.debug_line sections assuming it would result in a valid string. Which
would crash and burn if the DWARF data was bogus when the string was
used. So check whenever converting an string index into a char pointer
so we can produce a more helpful error message.

https://bugzilla.redhat.com/show_bug.cgi?id=1543912

Signed-off-by: Mark Wielaard <mark@klomp.org>
2018-03-09 16:22:33 +02:00
Andreas Schwab
d50520d94e debugedit: handle RISC-V relocation
Resolves #407
2018-03-05 12:26:22 +01:00
Mark Wielaard
857b7a3d6e Fix type mismatch calculating new line program offset in debugedit.c.
edit_dwarf2 calculates the (new) offset in the line program by
taking the difference between the old and new idx, which are of type
size_t (unsigned), plus the size_diff of the header given as ssize_t
(signed), and adding that to the current r_offset, which is an Elf64_Addr
(unsigned). On 64bit architectures, where the size of Elf64_Addr and
ssize_t are the same this isn't a problem. But on 32bit architectures,
where the size of ssize_t is smaller than Elf64_Addr the smaller signed
result gets promoted to an unsigned long first causing issues if the
size_diff was negative.

This would have been caught by gcc -Wsign-conversion

warning: conversion to ‘long unsigned int’ from ‘ssize_t’ {aka ‘long int’}
may change the sign of the result

But enabling this by default gives a lot of false positives.

Found and fixed by Richard Biener <rguenther@suse.de>.
2018-02-01 13:11:12 +02:00
Mark Wielaard
846b83212c debugedit: edit_dwarf2 check lndx is in range before checking r_offset. 2017-10-16 12:42:47 +03:00
Mark Wielaard
b4ecfcfff1 debugedit: skip_dir_prefix should check for dir separator.
To count as a real directory prefix the string matched should either
be equal to the given prefix or start with the prefix plus '/'.

skip_dir_prefix is always used with base_dir or dest_dir which don't
end with a slash themselves.

This really only is an issue if a package would put a directory named
similar to the package source dir (which cargo on fedora does, by adding
a directory named cargo-vendor in the builddir itself).

Signed-off-by: Mark Wielaard <mark@klomp.org>
2017-06-30 16:04:23 +03:00
Ville Skyttä
9b619fa46e Spelling fixes 2017-06-27 14:42:21 +02:00
Mark Wielaard
f2a239f539 debugedit: Only output comp_dir under build dir (once).
The fix for rhbz#444310 (commit c1a5eb - Include empty CU current dirs)
was a little greedy. It would also include comp_dirs outside the build
root. Those are unnecessary and we don't have a good way to store them.
Such dirs (e.g. /tmp) would then show up at the root of /usr/src/debug.

Fix this by including only comp_dirs under base_dir. Also only output
all dirs once (during phase zero) and don't output empty dirs (which
was harmless but would produce a warning from cpio).

This still includes all empty dirs from the original rhbz#444310
nodir testcase and it is an alternative fix for rhbz#641022
(commit c707ab).

Both fixes are necessary in case of an unexpected mode for a directory
actually in the build root that we want to include in the source list.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2017-04-24 14:01:06 +03:00
Mark Wielaard
92d43b7d1e debugedit: Add -n, --no-recompute-build-id.
Some packages depend on the build-ids as generated during the build
and cannot handle rpmbuild recomputing them before generating the
package file list. Add -n, --no-recompute-build-id to debugedit and
add -n to find-debuginfo.sh set by defining the %_no_recompute_build_ids
macro for such packages. %_no_recompute_build_ids can not be used together
with %_unique_build_ids.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2017-04-19 12:36:05 +03:00
Mark Wielaard
8e73dbe69d debugedit: Fix off-by-one adding DW_FORM_string replacement slashes.
We would put one too many slashes in between the new dest_dir and file name
part of the replacement of a DW_FORM_string in the .debug_info. If there
was file part then we would overwrite the first character of the name. If
there was no file part at all then this would overwrite the zero terminator
and cause a crash reading the rest of the data.

A crash did happen while building the docker package on fedora s390x.
https://bugzilla.redhat.com/show_bug.cgi?id=1434347

The reason neither issue would normally trigger is because if we do detect
that the dest_dir is larger than the base_dir we refuse to replace anything.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2017-03-22 14:54:18 +02:00
Mark Wielaard
03f489af5c debugedit: Fix edit_dwarf2_line replace_dirs -> replace_files typo.
We wouldn't replace the changed file names if replace_dirs was false,
but replace_files was true. This could overrun the new debug_line data
buffer if the original file name was larger than the replacement. It
wasn't found before because often when we need to replace files we
also would have to replace dirs.

This fixes the kubernetes build in fedora.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2017-03-21 14:25:39 +02:00
Mark Wielaard
2da619aa8e debugedit: Fix cross-endian build-id reading and updating section data.
debugedit doesn't read raw mmap data any longer. Which made the complex
way to read the build-id unnecessary (and it was broken for cross-endian).
Just use gelf_getnote to read the notes.

Also in some special cases when only the debug_info or build_id data
was updated, but no section changed size and we had to preserve the
allocated section headers we could hit a bug in elfutils that could
trash some section data in case there were gaps between non-dirty and
dirty sections. See https://sourceware.org/bugzilla/show_bug.cgi?id=21199
Add a workaround for that issue.

This fixes the kompose package build on fedora ppc64.
And makes it possible to replicate that issue on x86_64.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2017-03-21 14:25:39 +02:00
Mark Wielaard
2a38104411 debugedit: Support String/Line table rewriting for larger/smaller paths.
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>
2017-03-06 15:17:20 +02:00
Mark Wielaard
a519ab0c18 Make it possible to have unique build-ids across build versions/releases.
Introduce a new macro _unique_build_ids that when set will pass the
version and release to find-debuginfo.sh and debugedit to recalculate
the build-id of ELF files.

Includes two new testcases to make sure the new setting works as expected
both when set and unset.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2016-07-29 18:28:53 +02:00
Jan Kratochvil
392eeb3371 Make sure references to go sources in debuginfo packages go to the installed path and not the source file in the build environment.
- Resolves: rhbz#1184221
2015-04-15 09:54:29 +02:00
Panu Matilainen
448880543f Ensure clean paths are used for matching in debugedit (RhBug:1077148)
- Things like extra slashes can cause sources not to be found at all
  due to path prefix matching, canonicalize the argument paths first.
2014-03-25 14:06:34 +02:00
Andreas Schwab
77d8086bfe Add support for m68k
Tested on m68k-suse-linux.

Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2014-03-24 10:37:58 +02:00
Panu Matilainen
766b922eca Doh, its .debug_gdb_scripts, not _script (really fix SuseBug:818502) 2013-08-01 16:35:57 +03:00
Panu Matilainen
b0c850385c Teach debugedit about .debug_gdb_script section (SuseBug:818502) 2013-06-17 15:41:45 +03:00
Panu Matilainen
ff1d726911 Avoid breaking build on older systems which dont know AArch64 2013-06-17 10:17:07 +03:00
Kyle McMartin
386d486c9e debugedit: handle aarch64 debug_info relocations (RhBug:974860)
AArch64 generates a relocation which must be handled similar to other
architectures. Adding this patch allows debugedit to run against the
kernel debuginfo.

Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2013-06-17 10:06:23 +03:00
Panu Matilainen
8f2d0449ce Plug segfault on NULL pointer dereference in debugedit (RhBug:929365)
- Not sure what the right thing to do would be here, ignoring seems
  like a better option than crashing though...
2013-05-22 07:25:41 +03:00
Panu Matilainen
72b3e9f38a Revert "make "canonicalization(...)shrank by one character" error message more usefull"
- The message is not about basedir and destdir, and printing them
  here only makes the message even more confusing than it was, eg:
      canonicalization unexpectedly shrank by one character \
          ('/home/pmatilai/rpmbuild/BUILD/' vs '/usr/src/debug/')
- This reverts commit 1eea433d9961d74dbc797cea7f9bfceab8c16a3e
2013-01-09 14:06:56 +02:00
thierry.vignaud@gmail.com
a6255b1e06 make "canonicalization(...)shrank by one character" error message more usefull
Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2012-11-01 11:14:54 +02:00
Panu Matilainen
bdc7bf646a Warn but dont fail the build on STABS debuginfo (RhBug:725378, others)
- debugedit doesn't support STABS but there are some crazy cases
  like PPC Linux kernel which contains both STABS and DWARF debuginfo
  sections, manually added. A better fix would be erroring out
  if we didn't find any usable debuginfo and warning otherwise but
  this at least folks get their kernels built.
2012-03-07 13:47:09 +02:00
Panu Matilainen
436aacdec1 Teach debugedit about .debug_macro dwarf section (RhBug:759272) 2011-12-02 12:11:48 +02:00
Jakub Jelinek
390d0acb79 Add DWARF-4 support to debugedit (RhBug:707677)
Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
2011-06-17 16:40:20 +03:00
Panu Matilainen
ba3a76f737 Bail out of debuginfo if stabs format encountered (RhBug:453506)
- The previous "silently ignore" policy produces bogus debuginfo
  packages on some architectures and fails with other mysterious
  errors on others, better just fail hard until (if ever) somebody adds
  stabs support.
2011-05-24 17:23:37 +03:00
Panu Matilainen
a4a186ba20 Remove unused variable in debugedit 2011-03-04 14:50:30 +02:00
Anssi Hannula
51ee499614 debugedit: fix incorrect error messages regarding -b and -d 2010-09-01 10:01:13 +03:00
Roland McGrath
92fcba2a02 Make debugedit -i recompute build ID only when any DWARF was actually changed. 2010-05-11 15:09:53 +03:00
Roland McGrath
5eb7d2892e Whitespace fixups for tools/debugedit.c 2010-05-11 15:09:52 +03:00
Panu Matilainen
8f871dec97 Add debugedit support for DWARF-3 (RhBug:505774)
- patch from Jakub Jelinek
2009-06-16 13:52:43 +03:00
db62fbdc5a tools: build dump_ld_config and filesize with -D_FILE_OFFSET_BITS=64
... because they use stat().
2019-01-10 23:20:03 +00:00
e8c780c2b0 Disable build and install of unpackaged files
These are no longer packaged anyway, so no need to bother.
2017-01-14 13:42:53 +00:00
Gleb Fotengauer-Malinovskiy
03302d4963 relative.c: fix potential heap buffer overflow 2016-03-10 19:22:33 +03:00
4134fc39ac Fix automake warnings
Makefile.am:13: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
build/Makefile.am:5: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
lib/Makefile.am:5: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
python/Makefile.am:7: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
rpmdb/Makefile.am:5: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
rpmio/Makefile.am:9: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
tools/Makefile.am:5: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
2014-02-15 22:19:47 +00:00
f51a73c175 debugedit: enhance error diagnostics 2013-10-28 23:27:58 +00:00
Panu Matilainen
c14ca2efee Doh, its .debug_gdb_scripts, not _script (really fix SuseBug:818502) 2013-10-28 21:53:05 +00:00