libdwfl: Handle LZMA .ko.xz compressed kernel modules.

Linux kernel modules can not just be compressed with gz and bz2, but also
with xz.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
libdw: Add new function dwarf_cu_getdwarf.

In both systemtap and libabigail there is a need to get the actual Dwarf
underlying an Dwarf_Die or Dwarf_Attribute. Following a DIE reference
might end up in an alternate Dwarf since the addition of DWZ multifile
forms. Both Dwarf_Die and Dwarf_Attribute already contain a Dwarf_CU
handle. Add a function dwarf_cu_getdwarf to retrieve the underlying
Dwarf using the Dwarf_CU.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
libdw: Add new function dwarf_cu_die.

Given a Dwarf_Die or Dwarf_Attribute it is often convenient to get at the
CU DIE and the CU header information. There is dwarf_diecu but that doesn't
provide all information from the header and it doesn't work for attributes.
Add a new dwarf_cu_die function that provides all information given a
Dwarf_CU, which both Dwarf_Die and Dwarf_Attribute reference.

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

Signed-off-by: Mark Wielaard <mjw@redhat.com>
Prevent premature @AR@ replacement in a sed expression.

The Makefile rule for make-debug-archive has a sed expression to replace
@AR@ will the installed name, but this was itself getting replaced when
the Makefile was configured, for a pattern like "s,ar,/path/prefix-,g".
Havoc ensued in the resulting make-debug-archive.

The fix matches it using a regex bracket expression, "[@]AR[@]", so sed
will still match it, but it's immune to configure's replacement.

Signed-off-by: Josh Stone <jistone@redhat.com>
Fix resolving ELF symbols for live PIDs with deleted files

For deleted shared library files the offsets to the symbol table were
calculated wrongly from the phdrs because the main_bias wasn't taken into
account.

Formerly shared libraries did not get resolved properly:
	#2  0x00007fc4d86c56d6
	#3  0x0000000000400938 main

Fixed elfutils produce:
	#2  0x00007f61094876d6 libfunc
	#3  0x0000000000400938 main

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
elf_begin sets elf_errno for cases that the file is completely unreadable

- The problem this is trying to solve can be seen for example thus:
	$ eu-readelf -a /
	eu-readelf: failed reading '/': (null)

  With the fix we see a proper error number and get a reasonable error
  message:

	$ eu-readelf -a /
	eu-readelf: failed reading '/': invalid file descriptor

Signed-off-by: Petr Machata <pmachata@redhat.com>
Accept DW_AT_GNU_call_site_* as attributes that hold location expressions

- These are extension attributes that correspond in behavior to
  attributes described in this proposal:
	http://www.dwarfstd.org/ShowIssue.php?issue=100909.2

- N.B.: DW_AT_call_site_data_location doesn't have a DW_AT_GNU_*
  counterpart.

Signed-off-by: Petr Machata <pmachata@redhat.com>
Rename read_ubyte_unaligned_inc to read_addr_unaligned_inc

- The behavior of this function has been changed to read only
  address-sized quantities, i.e. the size of 2 is no longer allowed.
  (Size of 1 never was.)  The two outstanding uses, both in readelf.c,
  which actually do use this call to read address-sized units, were
  updated, rejecting fields that indicate weird address sizes.

- The three related calls, read_sbyte_unaligned_inc,
  read_ubyte_unaligned and read_sbyte_unaligned were dropped.  There
  are currently no uses for these calls.

Signed-off-by: Petr Machata <pmachata@redhat.com>
Add is_executable to Dwfl_Module.

Next patch will find module names from NT_FILE note so that main executable
will no longer necessarily have the name "[exe]" or "[pie]".
-e|--executable still should be able to override such module.

libdwfl/
2014-09-18  Jan Kratochvil  <jan.kratochvil@redhat.com>

	* dwfl_build_id_find_elf.c (dwfl_build_id_find_elf): Use IS_EXECUTABLE.
	* dwfl_segment_report_module.c (dwfl_segment_report_module): Set
	IS_EXECUTABLE.
	* libdwflP.h (struct Dwfl_Module): New field is_executable.

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
readelf: Fix typo in a check in handle_relocs_rela

- Testing shdr makes no sense, that pointer was dereferenced several
  times throughout the section.  destshdr on the other hand is not
  tested at all.

Signed-off-by: Petr Machata <pmachata@redhat.com>
libdwfl: dwfl_segment_report_module use ei_class, ei_data and e_type.

To make it easier to see that the code is using the correct fields of
the ehdr e32/e64 union extract ei_class, ei_data and e_type early and
use them directly.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
Support note NT_FILE for locating files.

Martin Milata:
------------------------------------------------------------------------------
RFE: dwfl_core_file_report: use NT_FILE core note if the link_map chain is broken
https://bugzilla.redhat.com/show_bug.cgi?id=1129777

The dwfl_core_file_report function follows dynamic linker's link_map chain in
order to determine the shared libraries used by the executable. As this data
structure is located in writable memory it can be overwritten by garbage, which
is sometimes the case.
	https://github.com/abrt/satyr/issues/127#issuecomment-46957546

Since version 3.7 (commit 2aa362c49), Linux kernel adds NT_FILE note to core
files which contains the files mapped by the process, including shared
libraries.
------------------------------------------------------------------------------

dwfl_core_file_report now tries to fall back on NT_FILE if the link_map chain
is broken.

elfutils would already find the appropriate binary file from
/usr/lib/debug/.build-id/ symbolic links.  But those symbolic links do not have
to be present on the system while NT_FILE still points to the correct binaries.

Filenames from the note NT_FILE are used only if link_map filenames failed to
locate matching binaries.

tests/test-core.core.bz2 had to have its NT_FILE disabled as run-unstrip-n.sh
otherwise FAILs:
FAIL: 0x7f67f2aaf000+0x202000 - . - /home/jkratoch/redhat/elfutils-libregr/test-core-lib.so
PASS: 0x7f67f2aaf000+0x202000 - . - test-core-lib.so
As test-core-lib.so is found in link_map but it is not present on the disk
elfutils now chooses the more reliable filename from NT_FILE (although that
filename is also not found on the disk).  Updating the expected text would be
also sufficient.

libdwfl/
2014-09-26  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Support NT_FILE for locating files.
	* core-file.c (dwfl_core_file_report): New variables note_file and
	note_file_size, set them and pass them to dwfl_segment_report_module.
	* dwfl_segment_report_module.c: Include common.h and fcntl.h.
	(buf_has_data, buf_read_ulong, handle_file_note): New functions.
	(invalid_elf): New function from code of dwfl_segment_report_module.
	(dwfl_segment_report_module): Add parameters note_file and
	note_file_size.  New variables elf and fd, clean them up in finish.
	Move some code to invalid_elf.  Call handle_file_note, if it found
	a name verify the file by invalid_elf.  Protect elf and fd against
	cleanup by finish if we found the file for new Dwfl_Module.
	* libdwflP.h (dwfl_segment_report_module): Add parameters note_file and
	note_file_size.

tests/
2014-09-26  Jan Kratochvil  <jan.kratochvil@redhat.com>

	Support NT_FILE for locating files.
	* Makefile.am (TESTS): Add run-linkmap-cut.sh.
	(EXTRA_DIST): Add run-linkmap-cut.sh, linkmap-cut-lib.so.bz2,
	linkmap-cut.bz2 and linkmap-cut.core.bz2 .
	* linkmap-cut-lib.so.bz2: New file.
	* linkmap-cut.bz2: New file.
	* linkmap-cut.core.bz2: New file.
	* run-linkmap-cut.sh: New file.
	* run-unstrip-n.sh: Update its expected output.

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>