platform/upstream/elfutils.git
10 years agolibdwelf: New DWARF ELF Low-level Functions. Add dwelf_elf_gnu_debuglink.
Mark Wielaard [Fri, 11 Apr 2014 21:52:47 +0000 (23:52 +0200)]
libdwelf: New DWARF ELF Low-level Functions. Add dwelf_elf_gnu_debuglink.

New public header elfutils/libdwelf.h for low-level DWARF/ELF helper
functions.  The new function dwelf_elf_gnu_debuglink returns the name and
crc as found in the .gnu_debuglink section of an ELF file.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoreadelf: handle_core_item make sure variable length array isn't zero size.
Mark Wielaard [Tue, 22 Apr 2014 21:26:34 +0000 (23:26 +0200)]
readelf: handle_core_item make sure variable length array isn't zero size.

The printed array should have at least space for the terminating zero char.
Found by gcc -fsanitize=undefined while running run-readelf-vmcoreinfo.sh.
runtime error: variable length array bound evaluates to non-positive value 0

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibdwfl: __libdwfl_frame_reg_[gs]et use uint64_t when checking bits.
Mark Wielaard [Tue, 22 Apr 2014 20:52:06 +0000 (22:52 +0200)]
libdwfl: __libdwfl_frame_reg_[gs]et use uint64_t when checking bits.

Found by gcc -fsanitize=undefined while running the backtrace-core-ppc test.
runtime error: shift exponent 45 is too large for 32-bit type 'unsigned int'

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoreadelf.c (print_gdb_index_section): Use unsigned int for 31 bits left shift.
Mark Wielaard [Tue, 22 Apr 2014 20:23:18 +0000 (22:23 +0200)]
readelf.c (print_gdb_index_section): Use unsigned int for 31 bits left shift.

Found by gcc -fsanitize=undefined.
left shift of 1 by 31 places cannot be represented in type 'int'

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibdw (get_sleb128_step): Remove undefined behavior.
Mark Wielaard [Tue, 22 Apr 2014 14:43:11 +0000 (16:43 +0200)]
libdw (get_sleb128_step): Remove undefined behavior.

As pointed out by gcc -fsanitize=undefined left shifting a negative value
is undefined. Replace it with a multiplication of the signed value as
suggested by Richard Henderson and Josh Stone.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agotests: run-nm-self.sh use test = not == for string comparisons.
Mark Wielaard [Wed, 23 Apr 2014 07:54:30 +0000 (09:54 +0200)]
tests: run-nm-self.sh use test = not == for string comparisons.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoUnwinding is only supported on Linux
Kurt Roeckx [Tue, 22 Apr 2014 19:46:22 +0000 (21:46 +0200)]
Unwinding is only supported on Linux

Signed-off-by: Kurt Roeckx <kurt@roeckx.be>
10 years agoRemove mudflap build option.
Mark Wielaard [Sun, 13 Apr 2014 15:39:57 +0000 (17:39 +0200)]
Remove mudflap build option.

The --enable-mudflap configure build has been broken for 2 years without
anybody apparently noticing. GCC 4.9 removed mudflap support. Before
release we now run make distcheck with valgrind support. Removal of the
mudflap configure option simplifies the build a little.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoreadelf: Read the decompressed data when processing .zdebug DWARF sections.
Mark Wielaard [Wed, 9 Apr 2014 20:38:07 +0000 (22:38 +0200)]
readelf: Read the decompressed data when processing .zdebug DWARF sections.

readelf uses libdw to open the Dwarf and read some of the DWARF data.
But it also uses its own parsers to display some of the low-level
unprocessed data. If the DWARF debug section was zlib compressed it
should actually use the decompressed section data from libdw instead
of the raw section data.

Includes a testcase for those sections that couldn't be properly
displayed when compressed before.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoreadelf: convert up to a target long in buf_read_ulong.
Mark Wielaard [Thu, 10 Apr 2014 13:02:53 +0000 (15:02 +0200)]
readelf: convert up to a target long in buf_read_ulong.

Add a i686 corefile test.

Reported-by: Markus Engel <m_engel@cs.uni-kl.de>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agobackends: Add aarch64 native and core unwind support.
Mark Wielaard [Wed, 9 Apr 2014 09:48:23 +0000 (11:48 +0200)]
backends: Add aarch64 native and core unwind support.

Add aarch64 backend functions frame_nregs and set_initial_registers_tid.
Mark pc_register in aarch64 prstatus_regs as pc_register.
Add backtrace-core-aarch64 testcase.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoCVE-2014-0172 Check for overflow before calling malloc to uncompress data.
Mark Wielaard [Wed, 9 Apr 2014 09:33:23 +0000 (11:33 +0200)]
CVE-2014-0172 Check for overflow before calling malloc to uncompress data.

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

Reported-by: Florian Weimer <fweimer@redhat.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agobackends: add ARM compatible mode to AARCH64
Jean Pihet [Fri, 28 Mar 2014 14:13:10 +0000 (15:13 +0100)]
backends: add ARM compatible mode to AARCH64

Add the initial register setup for AARCH64 running ARM code (so
called compat mode). This makes 'eu-stack -p' happy on ARM binaries
while running on a AARCH64 kernel.

Signed-off-by: Jean Pihet <jean.pihet@linaro.org>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agobackends: AARCH64_ABS32 and AARCH64_ABS64 are also valid in ET_REL.
Mark Wielaard [Wed, 19 Mar 2014 13:41:00 +0000 (14:41 +0100)]
backends: AARCH64_ABS32 and AARCH64_ABS64 are also valid in ET_REL.

This is tested now in a native aarch64 build by tests/run-elflint-self.sh
since we added some .o files to the self tests.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibdwfl: elf_from_remote_memory only trust shdrs of last file-only segment.
Mark Wielaard [Mon, 3 Mar 2014 14:07:31 +0000 (15:07 +0100)]
libdwfl: elf_from_remote_memory only trust shdrs of last file-only segment.

If the last PT_LOAD segment that contains the whole shdrs also extends
the segment in memory beyond the end of file the program might be reusing
the memory space that we expect the shdrs to be in. Don't trust the shdrs
are valid in that case.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibdwfl: test dwflsyms on ET_EXEC with minisymtab
Josh Stone [Wed, 12 Mar 2014 01:13:55 +0000 (18:13 -0700)]
libdwfl: test dwflsyms on ET_EXEC with minisymtab

This adds testfilebaxmin, an ET_EXEC binary with .gnu_debugdata that
doesn't match the load address of the main file.  A previous bug made
this trigger a kernel heuristic that forces the module to act like
ET_DYN, which makes things like dwfl_module_relocate_address report
relative addresses rather than proper absolute addresses.

For example, before the fix dwflsyms would print:

    deregister_tm_clones (0) 0x400430, rel: 0x430 (.text)

Now it properly prints:

    deregister_tm_clones (0) 0x400430, rel: 0x400430 (.text)

These new test additions confirm that it's fixed.

Signed-off-by: Josh Stone <jistone@redhat.com>
10 years agolibdwfl: dwfl_module_getdwarf.c (open_elf) only (re)set mod->e_type once.
Josh Stone [Tue, 11 Mar 2014 17:19:28 +0000 (10:19 -0700)]
libdwfl: dwfl_module_getdwarf.c (open_elf) only (re)set mod->e_type once.

As noted in https://sourceware.org/bugzilla/show_bug.cgi?id=16676#c2 for
systemtap, the heuristic used by open_elf to set the kernel Dwfl_Module
type to ET_DYN, even if the underlying ELF file e_type was set to
ET_EXEC, could trigger erroneously for non-kernel/non-main (debug or
aux) files.  Make sure we only set the e_type of the module once when
processing the main file (when the phdrs can be trusted).

10 years agolibdwfl: dwfl_linux_proc_find_elf use elf_from_remote_memory for (deleted).
Mark Wielaard [Tue, 4 Mar 2014 10:27:15 +0000 (11:27 +0100)]
libdwfl: dwfl_linux_proc_find_elf use elf_from_remote_memory for (deleted).

If a module has a "(deleted)" main ELF file, then try to read it from
remote memory if the Dwfl has process state attached by reusing the ptrace
mechanism from linux-pid-attach.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibdwfl: elf_from_remote_memory should use pagesize, not p_align.
Mark Wielaard [Mon, 3 Mar 2014 10:43:43 +0000 (11:43 +0100)]
libdwfl: elf_from_remote_memory should use pagesize, not p_align.

elf_from_remote_memory would use the actual p_align of the PT_LOAD segments
to calculate the loadbase, end and start of a segment. But the dynamic
loader aligns the segments using the pagesize and only sanity checks the
p_align values. So we should do the same to get accurate segment addresses.
Also fixes a small memory leak in case the ELF image appears to be bad.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoreadelf: Print DW_FORM_sdata values as signed numbers.
Mark Wielaard [Wed, 5 Mar 2014 15:17:54 +0000 (16:17 +0100)]
readelf: Print DW_FORM_sdata values as signed numbers.

Printing DW_FORM_sdata numbers as unsigned values is misleading.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoFix abort() on missing section headers.
Jan Kratochvil [Mon, 3 Mar 2014 23:04:27 +0000 (00:04 +0100)]
Fix abort() on missing section headers.

libdw/
2014-03-03  Jan Kratochvil  <jan.kratochvil@redhat.com>

Fix abort() on missing section headers.
* dwarf_begin_elf.c (check_section): Replace abort call by goto err.
New label err to return NULL.

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
10 years agolibdwfl: linux-proc-maps.c (proc_maps_report): Don't assert on bad input.
Mark Wielaard [Wed, 26 Feb 2014 16:00:39 +0000 (17:00 +0100)]
libdwfl: linux-proc-maps.c (proc_maps_report): Don't assert on bad input.

If ino == last_ino && dmajor == last_dmajor && dminor == last_dminor then
we expect the file names to be the same as well. Which is reasonable if
the input came from the /proc file system. But there could be bad user
input if the file was supplied through dwfl_linux_proc_maps_report.
Instead of asserting on the bad input, just signal a bad_report.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibdwfl: elf-from-memory.c (elf_from_remote_memory): Check against p64 p_type.
Mark Wielaard [Wed, 26 Feb 2014 16:17:07 +0000 (17:17 +0100)]
libdwfl: elf-from-memory.c (elf_from_remote_memory): Check against p64 p_type.

There was a type in the case of parsing ELFCLASS64 phdrs. Check against
p64 p_type, not the p32 p_type which at a different location in the union.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoreadelf: More sanity checks before trying to display interpreter string.
Mark Wielaard [Mon, 24 Feb 2014 16:44:42 +0000 (17:44 +0100)]
readelf: More sanity checks before trying to display interpreter string.

Check there is a SHT_PROGBITS section at the offset given by p_offsets for
a PT_INTERP segment before trying to display the interpreter string.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoreadelf: Robustify print_phdr program interpreter printing.
Mark Wielaard [Fri, 7 Feb 2014 13:23:24 +0000 (14:23 +0100)]
readelf: Robustify print_phdr program interpreter printing.

Check phdr->p_filesz and make sure interpreter string is zero terminated
before calling printf.

Reported-by: Florian Weimer <fweimer@redhat.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibdw: Read DW_AT_decl_file/line/column as unsigned
Josh Stone [Wed, 5 Feb 2014 19:26:27 +0000 (11:26 -0800)]
libdw: Read DW_AT_decl_file/line/column as unsigned

Section 2.14 of the DWARF v3 & v4 standards specifies that all three
declaration coordinates are unsigned integer constants.  DWARF v2 did
not specify signedness.  Now dwarf_decl_* use dwarf_formudata to read
these values.

Also, an assertion on the range of line/column is now a handled error,
setting DWARF_E_INVALID_DWARF for values greater than INT_MAX.

Signed-off-by: Josh Stone <jistone@redhat.com>
10 years agobackends: Make aarch64_regs.c checkable by -Wprintf
Petr Machata [Thu, 30 Jan 2014 14:34:33 +0000 (15:34 +0100)]
backends: Make aarch64_regs.c checkable by -Wprintf

10 years agobackends: Add arm frame_nregs and set_initial_registers_tid.
Mark Wielaard [Sun, 26 Jan 2014 19:16:48 +0000 (20:16 +0100)]
backends: Add arm frame_nregs and set_initial_registers_tid.

This allows CFI unwinding for ARM. It relies on having .debug_frame around
which is always the case in our testsuite. All native backtrace tests PASS
on arm if debuginfo (for glibc) is installed on the system. Otherwise the
tests SKIP.

For non-debug unwinding ARM uses EXIDX tables, not .eh_frames, which
would have to be translated to CFI to do unwinding without .debug_frame
available.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agobackends: arm_cfi SP (r13) is restored from CFA by default.
Mark Wielaard [Sat, 25 Jan 2014 13:32:42 +0000 (14:32 +0100)]
backends: arm_cfi SP (r13) is restored from CFA by default.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agobackends: Update arm_reloc.def.
Mark Wielaard [Fri, 24 Jan 2014 14:50:52 +0000 (15:50 +0100)]
backends: Update arm_reloc.def.

The elflint self test now also checks ET_REL files. Update the list of
relocation types to include all known relocations from elf.h.
R_ARM_SWI24 was obsolete and is now named R_ARM_TLS_DESC. The only other
relocation used in the dynamic linker is R_ARM_IRELATIVE.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoUse -Wformat=2 by default for all files.
Mark Wielaard [Wed, 22 Jan 2014 23:56:41 +0000 (00:56 +0100)]
Use -Wformat=2 by default for all files.

This just makes sure that all format strings are given as literals to
printf like functions so the compiler can see and check them. Remove
all no_Wformat, add -Wformat=2 unconditionally to AM_CFLAGS.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agostack: Add -i, --inlines. Show inlined call frames using DWARF debuginfo.
Mark Wielaard [Tue, 21 Jan 2014 15:13:49 +0000 (16:13 +0100)]
stack: Add -i, --inlines. Show inlined call frames using DWARF debuginfo.

Using dwarf_getscopes_die we can get all scopes that make up the current
subprogram representing an address. Using the call_file/line/column
attributes we can also show the source locations of these "inlined" calls.
Includes a test that shows that when DWARF debuginfo is available all
inlined function call frames and their source location can be shown.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agostack: Initialize -n maxframes to 256 by default.
Mark Wielaard [Mon, 27 Jan 2014 15:05:54 +0000 (16:05 +0100)]
stack: Initialize -n maxframes to 256 by default.

Make -n default just 256 frames, 2048 was too big. Also Document magic
number used in frames.allocated initialization.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agostack: Add -d, --debugname. Lookup DWARF debuginfo name for frame address.
Mark Wielaard [Mon, 20 Jan 2014 22:09:26 +0000 (23:09 +0100)]
stack: Add -d, --debugname. Lookup DWARF debuginfo name for frame address.

Includes test that shows -d matches the function name that corresponds to
the actual source line we report with -s for a frame address.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoaddr2line: handle_address initialize scopes to NULL.
Mark Wielaard [Mon, 20 Jan 2014 12:49:48 +0000 (13:49 +0100)]
addr2line: handle_address initialize scopes to NULL.

dwarf_getscopes returns the number of scope DIEs containing a PC address.
It returns -1 for errors or 0 if no scopes match PC. If dwarf_getscopes
returned 0, then scopes will not be allocated and handle_address might free
the uninitialized scopes pointer. Make sure it always has a defined value.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agorobustify: libelf gelf define INVALID_NDX macro.
Jakub Jelinek [Fri, 17 Jan 2014 19:38:01 +0000 (20:38 +0100)]
robustify: libelf gelf define INVALID_NDX macro.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agorobustify: libelf.
Jakub Jelinek [Fri, 17 Jan 2014 18:36:16 +0000 (19:36 +0100)]
robustify: libelf.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agorobustify: strip.
Roland McGrath [Fri, 17 Jan 2014 16:12:46 +0000 (17:12 +0100)]
robustify: strip.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agorobustify: readelf.
Roland McGrath [Fri, 17 Jan 2014 16:11:39 +0000 (17:11 +0100)]
robustify: readelf.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agorobustify: elflint.
Jakub Jelinek [Fri, 17 Jan 2014 16:07:27 +0000 (17:07 +0100)]
robustify: elflint.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agorobustify: Use gelf_fsize instead of relying on shdr->sh_entsize.
Petr Machata [Fri, 17 Jan 2014 16:00:12 +0000 (17:00 +0100)]
robustify: Use gelf_fsize instead of relying on shdr->sh_entsize.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agotests: Reduce the total number of self-test files and add ET_REL files.
Mark Wielaard [Thu, 16 Jan 2014 12:48:24 +0000 (13:48 +0100)]
tests: Reduce the total number of self-test files and add ET_REL files.

Some self tests would run for a really long time (especially under valgrind)
because we included all libebl backends in the list (there are 12 backends).
Now only test two explicitly. Also there were no ET_REL files in the
self test file list. So add two ET_REL files. The total number of self test
files is now 12.

run-nm-self.sh would run 4 * 3 * 3 * 22 = 792 tests (on all self test files).
Reduce the number of different files to test to 3 (one ET_EXEC, one ET_DYN
and one ET_REL file). Reducing the number of test runs to 99.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agotests: run-backtrace-demangle.sh check exitcode and max number of frames.
Mark Wielaard [Thu, 16 Jan 2014 08:45:51 +0000 (09:45 +0100)]
tests: run-backtrace-demangle.sh check exitcode and max number of frames.

There can be more than 3 frames, but depending on the system/installed
glibc we might not be able to unwind fully till the end.
cxxfunc -> f -> main
Expect to see the top two and a warning that there are more frames
(exit code 1)

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoFix false FAILs on testsuite with ulimit -c unlimited.
Jan Kratochvil [Sat, 18 Jan 2014 20:56:13 +0000 (21:56 +0100)]
Fix false FAILs on testsuite with ulimit -c unlimited.

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
10 years agobackends: aarch64_check_special_symbol check shdr is not NULL before usage.
Mark Wielaard [Tue, 14 Jan 2014 21:14:23 +0000 (22:14 +0100)]
backends: aarch64_check_special_symbol check shdr is not NULL before usage.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoreadelf: print_debug_macro_section clear vendor array before use.
Mark Wielaard [Tue, 14 Jan 2014 21:13:43 +0000 (22:13 +0100)]
readelf: print_debug_macro_section clear vendor array before use.

Not setting a vendor code before use would be invalid which we tried to
catch. But to detect that we do need to initialize the vendor array to
zero first.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolib: Add missing config.h #include to crc32_file.c.
Lei Zhang [Fri, 17 Jan 2014 11:20:45 +0000 (03:20 -0800)]
lib: Add missing config.h #include to crc32_file.c.

Without config.h, there is no possibility of large file support.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoFix corruption of non-C++ symbols by the demangler.
Jan Kratochvil [Wed, 15 Jan 2014 20:16:57 +0000 (21:16 +0100)]
Fix corruption of non-C++ symbols by the demangler.

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
10 years agotests: backtrace-subr.sh (check_native_core) should check core file name.
Matthias Klose [Tue, 7 Jan 2014 09:25:29 +0000 (10:25 +0100)]
tests: backtrace-subr.sh (check_native_core) should check core file name.

Needed when /proc/sys/kernel/core_uses_pid is set to 0. Try to rename
the core file, and if it does still fail, skip the test.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibdwfl: Only skip reset of return register for non-CIE-return regno (ppc64). elfutils-0.158 upstream/0.158
Mark Wielaard [Sun, 5 Jan 2014 19:37:30 +0000 (20:37 +0100)]
libdwfl: Only skip reset of return register for non-CIE-return regno (ppc64).

For PPC64 we skip resetting the return register if it is already set.
This is because on PPC64 there are two DWARF registers numbers that can
represent the same register. Setting the return address again confuses
the unwinder. But we do want to reset it if the register number
(non-translated by the ppc64 ebl) is equal to the actual register number
as set in the CIE as return address. This happens on older toolchains in
.debug_frame where the return address is set to 108, but the ebl abi_cfi
also sets register number 65.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agotests: Don't use ptrace detach stopped trick. Raise can return.
Mark Wielaard [Sat, 4 Jan 2014 22:28:33 +0000 (23:28 +0100)]
tests: Don't use ptrace detach stopped trick. Raise can return.

On older kernels the ptrace detach stop trick doesn't work reliably.
Just keep the child processes attached and stopped during the tests,
dwfl_linux_proc_attach will handle that fine now. Also on older kernels
raise would sometimes return anyway and cause a spurious assert. Just
ignore it.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agobackends: Add PPC64 machine_flag_check.
Mark Wielaard [Sat, 4 Jan 2014 18:19:16 +0000 (19:19 +0100)]
backends: Add PPC64 machine_flag_check.

To distinguish between the current PPC64 ELF ABI and the revised
ELFv2 ABI that will not use function descriptors binutils started
to emit the version (currently 1) in the ehdr e_flags. Recognize
all valid versions (0, 1 or 2) in elflint by adding the hook
ppc64_machine_flag_check.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agotests: backtrace-subr.sh skip check_native_core test if core ulimit fails.
Mark Wielaard [Sat, 4 Jan 2014 14:41:04 +0000 (15:41 +0100)]
tests: backtrace-subr.sh skip check_native_core test if core ulimit fails.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agotests: Simplify backtrace-dwarf (gcc cleanup-13.c) testcase.
Mark Wielaard [Sat, 4 Jan 2014 13:24:58 +0000 (14:24 +0100)]
tests: Simplify backtrace-dwarf (gcc cleanup-13.c) testcase.

The testcase originally came from GCC which was testing the runtime
unwinder using _Unwind_ForcedUnwind. Since we are using our own external
unwinder we can just abort at the right place and unwind from there.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoPrepare 0.158 release.
Mark Wielaard [Fri, 3 Jan 2014 21:16:34 +0000 (22:16 +0100)]
Prepare 0.158 release.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agobackends: Add aarch64 abi_cfi.
Mark Wielaard [Fri, 3 Jan 2014 17:15:02 +0000 (18:15 +0100)]
backends: Add aarch64 abi_cfi.

Setup initial CIE values for aarch64 for use with dwarf_frame functions.
Register info prefix should be the empty string (not NULL) when not used.
Add an EM_AARCH64 testcase to tests/run-addrcfi.sh to check both issues.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agostack: Show and handle -r,--raw even without USE_DEMANGLE.
Mark Wielaard [Thu, 2 Jan 2014 23:06:31 +0000 (00:06 +0100)]
stack: Show and handle -r,--raw even without USE_DEMANGLE.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agostack.c (print_frames): Print 0x before build-id hex-offset.
Mark Wielaard [Thu, 2 Jan 2014 22:59:41 +0000 (23:59 +0100)]
stack.c (print_frames): Print 0x before build-id hex-offset.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agostack: Allow -n 0 for unlimited frames. Make default 2048 frames.
Mark Wielaard [Thu, 2 Jan 2014 21:31:07 +0000 (22:31 +0100)]
stack: Allow -n 0 for unlimited frames. Make default 2048 frames.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibdwfl: linux-pid-attach.c (dwfl_linux_proc_attach): Use and check strtol
Mark Wielaard [Thu, 2 Jan 2014 20:17:18 +0000 (21:17 +0100)]
libdwfl: linux-pid-attach.c (dwfl_linux_proc_attach): Use and check strtol

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibdwfl: Add dwfl_core_file_attach and dwfl_linux_proc_attach.
Mark Wielaard [Mon, 30 Dec 2013 21:00:57 +0000 (22:00 +0100)]
libdwfl: Add dwfl_core_file_attach and dwfl_linux_proc_attach.

Rewrite __libdwfl_attach_state_for_pid and __libdwfl_attach_state_for_core
as public functions and don't call them from dwfl_linux_proc_report and
dwfl_core_file_report anymore. This lets the user attach state explicitly
independ from how the dwfl modules have been reported. Since attaching
state is an explicit action now the error can be returned directly and we
don't need to keep track of process_attach_error. dwfl_linux_proc_attach
lets the user can tell libdwfl whether caller takes care of ptrace
attaching and stopping the threads under inspection, or whether the
callback needs to take care of that and detaching again.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibdwfl: dwfl_linux_proc_find_elf should only return regular files.
Mark Wielaard [Sat, 28 Dec 2013 11:58:10 +0000 (12:58 +0100)]
libdwfl: dwfl_linux_proc_find_elf should only return regular files.

When the dwfl_linux_proc_find_elf callback is used together with the
dwfl_linux_proc_report callback that reads /proc/PID/maps files we might
see and try to open special character device files that cannot be normally
read and processed by libelf (and might hang the library on the initial
open or read from the file). Make sure we only try to open and return
regular files.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibdwfl: Fix memory leak in linux-core-attach. Allow reiterating threads.
Mark Wielaard [Tue, 24 Dec 2013 09:37:58 +0000 (10:37 +0100)]
libdwfl: Fix memory leak in linux-core-attach. Allow reiterating threads.

core_next_thread would allocate a new thread_arg each time but never free
it. We only need one active thread_arg to keep the state. Free it when
there are no more threads. It was also not possible to start walking all
threads in the core again. Just reset the note offset at the start.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibdwfl: Fix build_id memory leak in dwfl_segment_report_module.
Mark Wielaard [Mon, 23 Dec 2013 22:21:59 +0000 (23:21 +0100)]
libdwfl: Fix build_id memory leak in dwfl_segment_report_module.

We might already have allocated memory to hold the build_id early in
consider_notes when we called consider_phdr for the program headers
we've read from the image. We would leak that memory when we don't use
it then because we return early/fail. This can be because either we
didn't find the correct bias or we skip the module because it would
conflict in address space with any already existing module of DWFL.
In both cases explicitly free the build_id memory.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agostack: Add -l, --list-modules. Show module memory map, build-id and files.
Mark Wielaard [Sat, 28 Dec 2013 22:25:54 +0000 (23:25 +0100)]
stack: Add -l, --list-modules. Show module memory map, build-id and files.

Use to list modules detected for process or core file by stack program
and to see build-ids and which main elf and debug files were recognized
by libdwfl callbacks.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agostack: Improve error checking and exit code handling.
Mark Wielaard [Fri, 27 Dec 2013 09:49:51 +0000 (10:49 +0100)]
stack: Improve error checking and exit code handling.

Check up front whether we attached correctly, if not error out. Make sure
callbacks report -1 only on real errors and DWARF_CB_ABORT if exiting early
(but not in error). Handle all errors from frame callback in print_frames
after printing of good frames. Print as much information as possible like
tid, address and module name if known with error messages. Only exit with
exit code zero if everything went fine. Exit with error code one if there
were any non-fatal errors. Exit with error code two if no frames could be
printed or a fatal error occurred.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agostack: Add --quiet to not resolve addresses, add --raw to not demangle.
Mark Wielaard [Mon, 23 Dec 2013 20:19:05 +0000 (21:19 +0100)]
stack: Add --quiet to not resolve addresses, add --raw to not demangle.

Resolving addresses to function symbol names can be expensive. Use -q
to only print addresses (use together with --build-id to process later).
Demangle names by default, but add the -r option to not demangle and
show the raw names.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agostack: Simplify argument parsing. Don't use dwfl_standard_argp.
Mark Wielaard [Mon, 23 Dec 2013 09:46:54 +0000 (10:46 +0100)]
stack: Simplify argument parsing. Don't use dwfl_standard_argp.

We were using dwfl_standard_argp but trying to add our own and substract
some options from it. dwfl_standard_argp also handles kernel, modules,
executables without state and process maps that stack doesn't support.
That made argp parsing somewhat ugly and meant our --help and --usage
didn't really match. Just handle the dwfl_standard_argp options we do
want directly ('-p', '--core', '-e' and '--debuginfo-path'). That way
we can also do sanity checking on the options given.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agostack: -b, --build-id shows module build-id, load address and pc offset.
Mark Wielaard [Sun, 22 Dec 2013 23:47:06 +0000 (00:47 +0100)]
stack: -b, --build-id shows module build-id, load address and pc offset.

A convenient format for offline processing of the backtrace.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agostack: Add new '-n MAXFRAMES' option. Resolve addresses after unwind.
Mark Wielaard [Sun, 22 Dec 2013 22:48:26 +0000 (23:48 +0100)]
stack: Add new '-n MAXFRAMES' option. Resolve addresses after unwind.

Limit the number of frames printed per thread (defaults to 64) and resolve
addresses to names, modules and source after unwinding so the thread is
only stopped for the minimum time needed to do the actual unwinding. The
thread doesn't need to wait for the lookups and printing of information.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibdwfl: linux-pid-attach.c: Report actual PID (Tgid) to dwfl_attach_state.
Mark Wielaard [Mon, 23 Dec 2013 13:20:06 +0000 (14:20 +0100)]
libdwfl: linux-pid-attach.c: Report actual PID (Tgid) to dwfl_attach_state.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibdwfl: Make sure to set the CFI return register only once (for ppc64).
Mark Wielaard [Sat, 21 Dec 2013 20:56:35 +0000 (21:56 +0100)]
libdwfl: Make sure to set the CFI return register only once (for ppc64).

On PPC64 there are two DWARF registers numbers that can represent the
same register. If that register is the CIE return register then we only
want to set it once. The second setting will confuse the unwinder.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibdwfl: Add dwfl_getthread_frames.
Mark Wielaard [Fri, 20 Dec 2013 09:09:12 +0000 (10:09 +0100)]
libdwfl: Add dwfl_getthread_frames.

dwfl_getthread_frames is a convenience function for when the user is only
interested in one specific thread id of a process. It can be implemented by
a simple wrapper function that removes an extra callback layer just to
filter on thread id. But it also provides an optimized path to getting
access to just one particular Dwfl_Thread of the Dwfl process by providing
and (optional) new callback for the state provider. The pid_thread_callbacks
now provide an (optional) pid_getthread that doesn't need to travers all
threads anymore. Which is implemented for the linux-pid-attach provider.

stack now uses this to implement a new '-1' option that shows just one
specific thread of a process.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agotests: backtrace.c only check we caught the last instruction on x86_64.
Mark Wielaard [Sat, 21 Dec 2013 18:39:19 +0000 (19:39 +0100)]
tests: backtrace.c only check we caught the last instruction on x86_64.

On some architectures gcc might introduce some "padding instructions"
at the end of the function (like on ppc64). So only assert we are at the
last instruction of backtracegen if on x86_64 native. In theory the assert
could even fail on that architectures, but in practice it doesn't and it
is a nice test to have.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibdwfl: Correct nested asprintf result check in report_kernel_archive.
Mark Wielaard [Fri, 20 Dec 2013 23:04:21 +0000 (00:04 +0100)]
libdwfl: Correct nested asprintf result check in report_kernel_archive.

Because of wrongly placed parens the result of only one asprintf call
was checked correctly. Causing dwfl_linux_kernel_report_offline to return
ENOMEM. Rewrite nested if unlikely check into separate if statements to
make clear what is actually being checked and what the actual unlikely
condition is.

Reported against systemtap "build-id difficulties with hand-built kernels"
https://sourceware.org/bugzilla/show_bug.cgi?id=16358

Reported-by: Crestez Dan Leonard <lcrestez@ixiacom.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agobackends: aarch64 always has _GLOBAL_OFFSET_TABLE_ point to .got[0].
Mark Wielaard [Thu, 19 Dec 2013 15:11:19 +0000 (16:11 +0100)]
backends: aarch64 always has _GLOBAL_OFFSET_TABLE_ point to .got[0].

Like some other architectures aarch64 has a special rule for the
_GLOBAL_OFFSET_TABLE_ symbol. Even if there is a .plt.got section the symbol
value still points to the start of the .got section. This is also what the
dynamic linker expects.

See https://sourceware.org/ml/libc-ports/2013-06/msg00057.html

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibdwfl: Introduce dwfl_module_getsym_info and dwfl_module_addrinfo.
Mark Wielaard [Wed, 18 Dec 2013 10:05:54 +0000 (11:05 +0100)]
libdwfl: Introduce dwfl_module_getsym_info and dwfl_module_addrinfo.

Some arches like ppc64 use function descriptor values instead of function
addresses causing matching of names and addresses to fail when using
dwfl_module_getsym or dwfl_module_addrsym.

Add ebl hook to resolve any function descriptor values found in non-ET_REL
modules.

The new function dwfl_module_getsym_info doesn't adjust the symbol value
in any way, but returns the adjusted and/or resolved address associated
with the symbol separately. The new function dwfl_module_addrinfo resolves
against both the address associated with the symbol (which could be the
function entry address) value and the adjusted st_value. So that it is
easy to resolve and match either function descriptors and/or function
entry addresses.

Since these new functions also return more information they replace the
dwfl_module_getsym_elf and dwfl_module_addrsym_elf functions that never
made it into a released elfutils version.

addr2line and readelf now use the new functions when looking up functions
names. addr2line will now also display the section the address was found
in when given -x.

Extra testcases were added for both addr2line and the dwflsyms testscase.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoFix s390_initreg.c patch copy/paste error.
Mark Wielaard [Wed, 18 Dec 2013 17:26:55 +0000 (18:26 +0100)]
Fix s390_initreg.c patch copy/paste error.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agobackends: Avoid type-punning issue in s390_set_initial_registers_tid.
Mark Wielaard [Wed, 18 Dec 2013 17:02:42 +0000 (18:02 +0100)]
backends: Avoid type-punning issue in s390_set_initial_registers_tid.

Use union to avoid type-punning when assigning a double to a Dwarf_Word.
gcc complains otherwise. error: dereferencing type-punned pointer will
break strict-aliasing rules.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoUse executable_for_core in dwfl_build_id_find_elf.
Jan Kratochvil [Wed, 18 Dec 2013 14:02:19 +0000 (15:02 +0100)]
Use executable_for_core in dwfl_build_id_find_elf.

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
10 years agoAdd NEWS items for the new functions in 0.158.
Jan Kratochvil [Wed, 18 Dec 2013 13:37:49 +0000 (14:37 +0100)]
Add NEWS items for the new functions in 0.158.

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
10 years agounwinder: s390 and s390x
Jan Kratochvil [Tue, 17 Dec 2013 17:49:54 +0000 (18:49 +0100)]
unwinder: s390 and s390x

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
10 years agostack: show binary and source file names where a function is defined
Masatake YAMATO [Tue, 17 Dec 2013 03:03:29 +0000 (12:03 +0900)]
stack: show binary and source file names where a function is defined

This patch adds the module and source file information to the
each stack trace line.  `-m' is for module file information
and `-s' is for source file information. `-v' is for both and more.

This is based on private discussion with Jan Kratochvil
<jan.kratochvil@redhat.com>.

In v2 patch, `-s' and `-m' options are introduced instead
of using `-v' repeatedly as suggested by Mark Wielaard <mjw@redhat.com>.

In v3 patch `-a' is added as extra option and source lines are
printed on their own line.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoRemove tests/backtrace-dwarf.c unused code.
Jan Kratochvil [Tue, 17 Dec 2013 20:11:48 +0000 (21:11 +0100)]
Remove tests/backtrace-dwarf.c unused code.

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
10 years agoFix forgotten call of ebl_dwarf_to_regno.
Jan Kratochvil [Tue, 17 Dec 2013 17:17:32 +0000 (18:17 +0100)]
Fix forgotten call of ebl_dwarf_to_regno.

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
10 years agolibdwfl: linux-pid-attach.c (pid_next_thread): Use rewinddir on first call.
Mark Wielaard [Tue, 17 Dec 2013 09:37:29 +0000 (10:37 +0100)]
libdwfl: linux-pid-attach.c (pid_next_thread): Use rewinddir on first call.

dwfl_getthreads would otherwise fail to report any threads after it was
called once.

Reported-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibdwfl: Add dwfl_module_getsymtab_first_global.
Mark Wielaard [Mon, 16 Dec 2013 12:28:59 +0000 (13:28 +0100)]
libdwfl: Add dwfl_module_getsymtab_first_global.

New function that provides the index after the last non-local symbol as
returned by dwfl_module_getsym and dwfl_module_getsym_info. Allows users to
first search through all global symbols before searching the local symbols
in the table like dwfl_module_addrsym and dwfl_module_addrsym_info do as
optimization.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibdwfl: Fix various frame related memory leaks.
Mark Wielaard [Sat, 14 Dec 2013 14:02:56 +0000 (15:02 +0100)]
libdwfl: Fix various frame related memory leaks.

The result of dwarf_cfi_addrframe should have been freed when done.
Dwfl_Module cached the reloc_info and the eh_cfi it which also should
have been released when disposing of the module.

Reported-by: Masatake YAMATO <yamato@redhat.com>
Tested-by: Masatake YAMATO <yamato@redhat.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agounwinder: ppc and ppc64
Jan Kratochvil [Sun, 15 Dec 2013 17:56:17 +0000 (18:56 +0100)]
unwinder: ppc and ppc64

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
10 years agotests: Add backtrace_child_biarch_SOURCES to make distcheck happy.
Mark Wielaard [Fri, 13 Dec 2013 22:12:18 +0000 (23:12 +0100)]
tests: Add backtrace_child_biarch_SOURCES to make distcheck happy.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agotests: Disable valgrind for core dumping and for self-introspecting tests.
Mark Wielaard [Fri, 13 Dec 2013 21:42:46 +0000 (22:42 +0100)]
tests: Disable valgrind for core dumping and for self-introspecting tests.

The only tests that fork and exec are those that will then try to ptrace
attach the child for unwind testing. That won't work when the child is
also running under valgrind. So remove --trace-children=yes. Also disable
valgrind while dumping a core or for tests that try to inspect their own
state. They will get confused otherwise finding pieces of valgrind in
their maps.

Note we still seem to hit the following valgrind bug because the way we
map and unmap some shared libraries gets valgrind confused:
https://bugs.kde.org/show_bug.cgi?id=327427

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolib: Avoid the hash-lookup division if possible
Josh Stone [Fri, 13 Dec 2013 00:34:15 +0000 (16:34 -0800)]
lib: Avoid the hash-lookup division if possible

For Dwarf_Abbrev codes, the most common case is that they're packed at
the low end, saving uleb128 encoding size.  Since the hash table is
always resized to be no more than 90% full, those codes are always less
than the table size, and dividing for the remainder is unnecessary.

Dwarf_Dies are frequently created anew, and need to find abbrev each
time, so even that one division becomes a noticeable hotspot.  This
patch adds a branch to avoid it, which is very predictable for the CPU.

Signed-off-by: Josh Stone <jistone@redhat.com>
10 years agolibdw: Simplify and inline get_uleb128 and get_sleb128
Josh Stone [Tue, 10 Dec 2013 22:19:09 +0000 (14:19 -0800)]
libdw: Simplify and inline get_uleb128 and get_sleb128

This removes the IS_LIBDW distinction so LEB128 operations are now
always inlined, and the implementations are simplified, more direct.

Signed-off-by: Josh Stone <jistone@redhat.com>
10 years agolibdw: Add an inlined fast path for __libdw_form_val_len
Josh Stone [Mon, 9 Dec 2013 21:52:10 +0000 (13:52 -0800)]
libdw: Add an inlined fast path for __libdw_form_val_len

Quite a few DW_FORMs have a fixed length for their data, and we can
easily represent these in a small lookup table.  The rest of the forms
are left in the old function to compute as needed.  Combined with
inlining, this takes care of many forms with fewer branches and without
any call.  (It's conceivable that a smart compiler could make a similar
lookup transformation from the large switch itself, but GCC doesn't.)

Signed-off-by: Josh Stone <jistone@redhat.com>
10 years agolibdw: Handle empty location expression for (indirect) DIE locations.
Mark Wielaard [Mon, 9 Dec 2013 15:33:26 +0000 (16:33 +0100)]
libdw: Handle empty location expression for (indirect) DIE locations.

When dwarf_getlocation_implicit_pointer and dwarf_getlocation_attr
refer to a DIE that doesn't contain a DW_AT_location then don't generate
an error, but return an empty location expression to signal the actual
value pointed to is not available. This isn't invalid DWARF. Also make
sure that __libdw_intern_expression handles empty location expressions.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoAdd config/ar-lib to .gitignore
Josh Stone [Mon, 9 Dec 2013 21:15:56 +0000 (13:15 -0800)]
Add config/ar-lib to .gitignore

Signed-off-by: Josh Stone <jistone@redhat.com>
10 years agoFix test FAIL with -O2
Jan Kratochvil [Thu, 5 Dec 2013 15:16:14 +0000 (16:16 +0100)]
Fix test FAIL with -O2

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
10 years agotests: SKIP backtrace-data and backtrace-dwarf on unsupported arches.
Mark Wielaard [Thu, 5 Dec 2013 14:26:51 +0000 (15:26 +0100)]
tests: SKIP backtrace-data and backtrace-dwarf on unsupported arches.

run-backtrace-data.sh did check stderr whether the arch was unsupported
but the test didn't print that message yet. backtrace-dwarf did print
the message but was missing a check_unsupported test. Also add an explicit
check_main test for backtrace-dwarf.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agotests: automake 1.13 compatibility fix.
Mark Wielaard [Wed, 4 Dec 2013 19:55:23 +0000 (20:55 +0100)]
tests: automake 1.13 compatibility fix.

tests/Makefile.am:65: warning: deprecated feature: target
'backtrace-child-biarch' overrides 'backtrace-child-biarch$(EXEEXT)'
tests/Makefile.am:65: change your target to read
'backtrace-child-biarch$(EXEEXT)'

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoTests for unwinder of x86*.
Jan Kratochvil [Mon, 2 Dec 2013 19:54:28 +0000 (20:54 +0100)]
Tests for unwinder of x86*.

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