Commit Graph

502 Commits

Author SHA1 Message Date
Mark Wielaard 2ea5619e37 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ä 2901e265a0 Spelling fixes 2017-06-27 14:42:21 +02:00
Peter Kjellerstedt d7e74c492a Do not call rpmfcPrint() with an uninitialized buffer in rpmdeps
The filling of the buffer, buf, that was passed to rpmfcPrint() was
removed in d16bdb15 (in 2007). Since then, an uninitialized buffer was
used if the files to calculate the dependencies for were passed as
arguments on the command line.

Signed-off-by: Peter Kjellerstedt <peter.kjellerstedt@gmail.com>
2017-05-18 13:30:48 +02:00
Mark Wielaard e795899780 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 6e9fd97f6d 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
Panu Matilainen f493dfdeb4 Eliminate warning from '_' being redefined in sepdebugcrcfix.c
Exposed by commit cf6c87997f which
includes system.h which includes the NLS stuff.
2017-03-24 12:54:04 +02:00
Gleb Fotengauer-Malinovskiy cf6c87997f Fix Large File Support (LFS) in sepdebugcrcfix tool and systemd_inhibit.so plugin
This problem was found by ALT rpm verify-elf brp script:
verify-elf: WARNING: ./usr/lib/rpm-plugins/systemd_inhibit.so: uses non-LFS functions: __lxstat
verify-elf: WARNING: ./usr/lib/rpm/sepdebugcrcfix: uses non-LFS functions: __xstat mmap open pread pwrite

Signed-off-by: Gleb Fotengauer-Malinovskiy <glebfm@altlinux.org>
2017-03-24 12:51:33 +02:00
Mark Wielaard c510b96acb 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 dc759bc655 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 a6e7676003 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 88989572ff 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 245b5a3b4b Eliminate unnecessary dependency on bfd.h from sepdebugcrcfix
I think the reliance on bfd.h was a mistake. The code was lifted from
bfd, but should be totally independent (it just calculates a CRC).
Fix the type to be a normal size_t and include sys/stat.h (which was
included through bfd.h) to get the definitions of stat and chmod.
2016-12-09 10:31:23 +02:00
Mark Wielaard 5ef1166ad9 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
Mark Wielaard 4ec7c396fb Add sepdebugcrcfix to fixup old style gnu_debuglink CRC checksum.
Some old tools might still use the .gnu_debuglink section to find
separate debuginfo files instead of build-id style lookups. When
dwz has compresses the .debug files the original CRC in the main
ELF file will no longer match. Make sure to run sepdebugcrcfix
after dwz to recalculate the CRC.

The original fix was created by Jan Kratochvil based on code
from GNU binutils BFD. https://bugzilla.redhat.com/show_bug.cgi?id=971119
I added a testcase to make sure the CRCs were all correctly
updated after dwz has run to compress a debuginfo package.
And a change (plus testcase) to make sure implicit suid binaries
didn't accidentially got their suid flag bit.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2016-07-29 18:28:53 +02:00
Ville Skyttä 0e51d17004 Remove some unnecessary assignments flagged by cppcheck 2016-07-29 17:41:36 +02:00
Kamil Rytarowski 61109446ac Reimplement setprogname() and getprogname() to be generic and portable
The RPM code contains setprogname()/getprogname() support implemented through compatiblity layer with very old GLIBC (internals supported back to '95 and earlier), before stabilization of the GNU C library. This compatiblity layer (__progname, __assert_progname, setprogname()) is supposed to support well archaic GLIBC, but on the other hand it pollutes the library namespace and introduces unpredicable compillation errors on BSD systems.

The functions setprogname() and getprogname() are natively supported in NetBSD and work the same way as __progname from the GNU C library (they are even implemented in the same way - but with a slightly changed logic). The support for very old (20 years and older) GNU C Library is obfuscating the code, because it uses defines over defines without a word of explaination why to do so.

It's important to note that the setprogname()/getprogname() was inconstiently implemented in the codebase, duplicating the code and/or functionality.

Add new generic functions getprogname() and setprogname() and bind it to:
- the current and for two decades stable GNU LIB C implementation,
- the current NetBSD implementation (introduces to NetBSD in 2002),
- fallback reimplementation functions of the setprogname() and getprogname() functionality for other systems.

Don't support anymore old GNU Lib C internals and don't support older NetBSD systems, as they aren't supported for many years.

Add to the codebase comments explaining the relevant codeparts.
2016-02-11 14:05:25 +01:00
Lubos Kardos 7a84b45c62 Add support for various types of dependencies to rpmdeps tool
Options added to rpmdeps tool:
--recommends
--suggests
--supplements
--enhances
--conflicts
--obsoletes
2015-09-21 14:21:27 +02:00
Jan Kratochvil 363c015da5 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 91456b1bb8 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 bc66cb3480 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 ee5a500fee Filter out garbage sonames from dependencies (ticket #158)
- The original case of empty string ending up in a dependency is already
  taken care of by commit 66a01c977e and
  soname filtering. However if filtering is disabled, an an empty
  (or all-whitespace) soname will produce gems like "()(64bit)" on
  multilib arches, so we need to sanity check the soname itself in
  elfdeps.
- The linker doesn't seem to care what kind of junk the soname contains,
  we care just a little bit more as eg empty strings and whitespace
  messes up other things.
2014-01-24 15:02:39 +02:00
Panu Matilainen 0f2a4640de Doh, its .debug_gdb_scripts, not _script (really fix SuseBug:818502) 2013-08-01 16:35:57 +03:00
Florian Festi f6771b6722 Do not filter ld64.* and ld64-* provides and requires
Fixes #988373
2013-07-30 16:35:21 +02:00
Panu Matilainen b9ce1c4d7a Teach debugedit about .debug_gdb_script section (SuseBug:818502) 2013-06-17 15:41:45 +03:00
Panu Matilainen 606749c3b5 Avoid breaking build on older systems which dont know AArch64 2013-06-17 10:17:07 +03:00
Kyle McMartin 389d260ca4 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 ea47e7a816 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 e83cc97792 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 1eea433d99
2013-01-09 14:06:56 +02:00
Panu Matilainen 6941d51e7e Alternatively accept files from command line arguments in elfdeps
- Nothing actually needs this, but for testing & debugging command line
  args are often nicer than having to pass stuff via stdin.
2013-01-08 13:57:41 +02:00
Panu Matilainen 39fa042c9e Extract (and optionally require) interpreter from ELF files
- A dependency on the interpreter is likely to be redundant, but
  presence of PT_INTERP is a useful indication of whether a file
  is executable or not: all normal dynamically linked executables
  have it whether PIE DSO or "plain" executable. Some libraries
  also have it but they are supposed to be really executable:
  for example glibc's libc.so and libQtCore.so have it and print out
  config, version etc information when executed.
- For now, we dont actually use the PT_INTERP information for anything
  apart from the optional require.
2013-01-08 11:51:31 +02:00
Panu Matilainen 73bd9636d0 Filter ELF dependencies by name
- Instead of vain heuristics on DT_SONAME presence, filter out
  irregular sonames from all dependencies: linkable library names generally
  must contain ".so" and start with "lib" for the linker to find it at all,
  anything else is an exception of one kind or another (the prime exception
  of ld.so variants we handle here). This weeds out provides for most
  dlopen()'ed modules etc, and filtering both provides and requires
  by the same rules means we wont generate requires for things that wont be
  provided.  Of course this also means we can omit things that are in
  DT_NEEDED, but these should be rare exceptions which the new
  --no-filter-soname switch is for.
2013-01-07 16:31:52 +02:00
Panu Matilainen b6f159a34c Fake ELF sonames by default (again)
- (Private) libraries which might intentionally not have DT_SONAME
  are still recorded as requires from DT_NEEDED, and there's no
  way of knowing what's an internal library when generating requires.
  Not faking the soname in these cases will only result in broken
  requires in cases that always used to "just work".
- Change the switch to --no-fake-soname disabler instead to allow
  tweaking in special cases but by default we gotta match linker
  (and ELF specification) behavior, no matter how much we'd like to
  use this for our own heuristics :-/
2013-01-07 15:27:22 +02:00
Panu Matilainen 8e3ce7417a Centralize elf soname provide addition, comment
- Remember DT_SONAME in the elfInfo struct if encountered and
  only add it after everything else has been processed. This doesn't
  change any actual functionality for now, but gives us a single
  place where to control the addition.
- Additionally document what the related DT_DEBUG test is for and
  clean up the processDynamic() loop and switch-case a bit.
2013-01-03 17:21:10 +02:00
Panu Matilainen 6c0bdc393d Only fake ELF soname's if requested
- This helps cutting down the number of bogus provides from dlopen()'ed
  plugins and internal libraries which preferrably shouldn't have a
  soname at all. Unfortunately libtool always puts in a soname even if
  -module -avoid-version is used :-/
- OTOH there are broken libraries which dont have a soname even though
  they should, so (we need to) allow falling back to the former behavior
  of faking up a soname from the basename.
2013-01-03 14:16:20 +02:00
Panu Matilainen f84a71cdc7 Move elf class marker figuring to helper function, generalize a bit
- Determine arch-specific issues by looking at the elf header instead
  of compile-time #ifdefs, so we'll generate correct dependencies for
  non-native elf binaries too. Currently this is just alpha which despite
  being a 64bit system, never had the (64bit) markers in its dependencies.
  Of course alpha has pretty much already met its mark^H^H er maker by now,
  but doing the right thing is cheap... Also we'll need similar special
  cases sooner or later for other archs (such as x32).
2013-01-03 13:08:03 +02:00
Panu Matilainen e7489abd66 Consolidate elf dependency string generation to helper function
- Figure out the elf class marker early and handle the rest in helper
  to avoid copy-slop code. No functional changes.
2013-01-03 12:11:26 +02:00
thierry.vignaud@gmail.com 1eea433d99 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 fe252f21b3 Accept files as command line arguments again in rpmdeps (RhBug:807767)
- Commit a25c3c7bac removed what was
  supposedly a non-supported method of passing files as arguments
  (instead of the normal stdin method) to rpmdeps. Turns out
  rpmdeps is even documented to take files as cli args, and that's
  how Fedora's %filter_setup macros are calling it...
- Allow files as arguments again, but in a way that doesn't cause
  argvFoo() vs popt crash-n-burn.
2012-03-29 11:26:57 +03:00
Panu Matilainen 1684b69611 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 7c463c32fc Teach debugedit about .debug_macro dwarf section (RhBug:759272) 2011-12-02 12:11:48 +02:00
Panu Matilainen 9958e535ff Eliminate the last two fpio uses in rpm codebase
- Both relate to reading manifests and it doesn't make the damnest
  difference what io mode these use as rpmReadPackageManifest()
  opens its own stream on the fd with fdopen() which works on
  any io type, not just fpio..
2011-07-08 10:20:02 +03:00
Jakub Jelinek 9d440c488b 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 f67c47b856 Eliminate bunch of dead assignments on ts vsflags
- The common pattern here is grabbing current flags to a local
  variable, modifying them for an operation and then restoring,
  which is fine... but we dont care about the previous flags
  when we're restoring them.
2011-05-30 15:50:29 +03:00
Panu Matilainen b296ddb840 Eliminate a few dead NULL-assignment eliminations in rpmgraph
- There are more but leaving the rest as a reminder to clean
  up rpmGraph() someday when bored enough...
2011-05-30 11:00:31 +03:00
Panu Matilainen a25c3c7bac Spring-cleaning for rpmdeps
- Depgen helpers take nno args, their input comes from stdin. Eliminates
  popt vs ARGV_t mismatch which would've caused us to blow up if
  it weren't for a memleak on the generated argv.
- Another memleak on the file classifier in case rpmfcClassify()
  or rpmfcApply() fails - just free all allocated resources at exit.
- Remove fluff: fgets() is guaranteed to \0-terminate non-NULL returns,
  eliminate unused/useless variables
- Fixup indentation where busted
2011-05-30 10:44:43 +03:00
Panu Matilainen fe2167ead9 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 f6579c0ac3 Reflect file classifier errors in rpmdeps exit code
- rpmfcClassify() or rpmfcApply() failing is pretty fatal to rpmdeps,
  exit with error code
- OTOH argvAdd() and argvSort() can't really fail, ignore their return
  codes, shutting up another set-but-not-used whine
2011-04-18 12:25:43 +03:00
Panu Matilainen b098c17348 Drop the unused + unmaintained javadeps helper
- It contains piles of buffer overflow etc material and AFAIK this
  has been unused for its entire lifespan of > 10 years, fixing
  an unused piece of code seems like a waste of time. If somebody
  shows interest later on it can be resurrected, but in the meanwhile...
2011-03-25 15:20:26 +02:00
Panu Matilainen b925a084ed Remove unused variable in debugedit 2011-03-04 14:50:30 +02:00
Panu Matilainen fe68483d1b Add switch to allow printing only soname dependencies to elfdeps helper 2011-01-13 10:14:25 +02:00