Drop unused field struct Dwarf_Files_s.cu

Signed-off-by: Petr Machata <pmachata@redhat.com>
libdw: Add dwarf_peel_type. Use it in dwarf_aggregate_size.

Add new function dwarf_peel_type. Some type annotations in DWARF are
specified by modifier tag type wrappers instead of attributes.
For type aliases (typedef) and qualifiers (const, volatile, restrict)
tags dwarf_peel_type follows the DW_AT_type attributes till it finds
a base, user-defined, reference or pointer type DIE.

Use this new function in the backends for return type DIEs (replacing
the existing dwarf_peel_type there) and in dwarf_aggregate_size so
it can provide the sizes for qualified types too. Add a new version
and testcase for the new dwarf_aggregate_size functionality.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
libelf: Correct shdr size check for (raw) getdata.

Reported-by: Hanno Böck <hanno@hboeck.de>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
readelf: Sanity check hash section contents before processing.

Reported by: Hanno Böck <hanno@hboeck.de>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
readelf.c (handle_versym): Initialize vername and filename array elements.

We check whether the elements are set before printing their contents,
but didn't make sure they were initialized.

Reported-by: Hanno Böck <hanno@hboeck.de>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Support .debug_macro

- This code is based on the following proposal:
    http://www.dwarfstd.org/ShowIssue.php?issue=110722.1

- dwarf_getmacros serves either of .debug_macinfo or .debug_macro
  transparently, but if the latter uses opcode 0xff, it bails out with
  an error.  The reason is that in .debug_macro, 0xff is a custom code
  that can mean anything, while in .debug_macinfo there's fixed
  semantics associated with 0xff.

- dwarf_getmacros_off is a new interface used for requesting iteration
  through transparently included units.

- dwarf_macro_getparamcnt and dwarf_macro_param are new interfaces
  used for requesting number of parameters of an opcode and individual
  parameters.  dwarf_macro_getsrcfiles is a new interface used for
  requesting a file part of .debug_line unit associated with macro
  unit that the opcode comes from.

- The existing interfaces dwarf_macro_opcode, dwarf_macro_param1 and
  dwarf_macro_param2 remain operational for old- as well as new-style
  Dwarf macro sections, if applicable.

- dwarf_getsrclines was made into a light wrapper around a worker
  function that loads line unit given its offset.  The worker also
  caches loaded units in an offset-keyed search tree, so that we don't
  end up re-reading units even though they were read in a different
  domain (e.g. a macro unit request can prime cache for later CU
  lookup).  dwarf_macro_getsrcfiles calls the worker function under
  covers.

Signed-off-by: Petr Machata <pmachata@redhat.com>
Test cases for .debug_macro support

Signed-off-by: Petr Machata <pmachata@redhat.com>
libdw: Fix dwarf_getsrclines.c 32bit compile error.

__libdw_getsrclines should have been marked as internal_function in
both libdwP.h and dwarf_getsrclines.c. Do address_size comparison as
uint8_t to avoid signedness warning.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
libelf: Use mempcpy not __mempcpy.

We were using mempcpy everywhere else, only __libelf_next_arhdr_wrlock used
__mempcpy.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
libelf: Fix unsigned overflow check in elf_getdata.
libdwfl: find_dynsym don't assume dynamic linker has adjusted DYNAMIC entries.

commit 037505 "Fix resolving ELF symbols for live PIDs with deleted files"
changed find_dynsym to assume the PT_DYNAMIC entries had been adjusted by
the dynamic linker. That is often a correct assumption when the ELF image
comes from remote memory. But we cannot rely on that. In the case of the
vdso image the DYNAMIC segment has not been adjusted for example.

There is no good way to determine whether the DYNAMIC segment has or
hasn't been adjusted already to the load address by the dynamic linker.
So we just try twice. Once without and if the fails again with assuming
adjustments being applied.

Includes a new vdsosyms testcase that fails on i686 before and succeeds
after the fix.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
readelf: Check def == NULL before use in handle_versym.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
libdwfl: dwfl_module_getdwarf.c don't use symtab with bogus sh_entsize.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
libdwelf: Check the d_buf actually exists in dwelf_elf_gnu_debuglink.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
libelf: gelf_getnote check for offset overflow.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
readelf: Sanity check CIE unit_length and augmentationlen in debug_frame.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
libelf: getdata check 64bit values correctly on 32bit arch.

On 32bit arches size_t is too small to do size and overflow checks
of 64bit ELF files. Use the actual Elf64 types to make sure checks
on 64bit ELF files are done correctly on 32bit arches.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
gelf_getnote: Check padding overflow.

Since ELF notes need to be properly aligned they can include padding.
Make sure the padding itself and the padding calculation doesn't overflow.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
readelf: Robustify print_cfa_program.

Check block len before calling print_ops.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
libelf: Fix handling of (extended) phnum.

If there is no e_phoff e_phnum cannot be trusted. Extended phnum can only
be gotten if we have an actual section table and a shdr for section zero,
Extended phnum can be too large to fit in the file (or a size_t).

Signed-off-by: Mark Wielaard <mjw@redhat.com>