platform/upstream/elfutils.git
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>
10 years agoIntroduce process_attach_error.
Jan Kratochvil [Sat, 30 Nov 2013 20:40:29 +0000 (21:40 +0100)]
Introduce process_attach_error.

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
10 years agolibdwfl: Add dwfl_module_addrsym_elf and dwfl_module_getsym_elf.
Mark Wielaard [Wed, 27 Nov 2013 15:45:44 +0000 (16:45 +0100)]
libdwfl: Add dwfl_module_addrsym_elf and dwfl_module_getsym_elf.

Introduce two new functions that also return the elf associated with a
symbol to make symbol section indexing work for non-special sections.
Simplify code by removing dwfl_file where appropriate and just track Elf
directly. Document limitations of shndx with existing dwfl_module_addrsym
and dwfl_module_getsym. Extend dwflsyms testcase to check some more symbol
and section (index) properties.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoMark new dwfl functions with version ELFUTILS_0.158.
Mark Wielaard [Tue, 26 Nov 2013 14:13:22 +0000 (15:13 +0100)]
Mark new dwfl functions with version ELFUTILS_0.158.

It took two versions to get the new thread state and unwind dwfl functions
in. Make sure they carry the latest elfutils symbol version in which they
were actually added.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agotests: Makefile.am (EXTRA_DIST): Add run-funcretval.sh.
Mark Wielaard [Tue, 26 Nov 2013 09:44:18 +0000 (10:44 +0100)]
tests: Makefile.am (EXTRA_DIST): Add run-funcretval.sh.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoSupport AArch64 architecture
Petr Machata [Tue, 26 Nov 2013 02:10:31 +0000 (03:10 +0100)]
Support AArch64 architecture

Signed-off-by: Petr Machata <pmachata@redhat.com>
10 years agoSupport new 'h' core note item format for hidden fields
Petr Machata [Thu, 14 Nov 2013 00:07:22 +0000 (01:07 +0100)]
Support new 'h' core note item format for hidden fields

Signed-off-by: Petr Machata <pmachata@redhat.com>
10 years agoFix non-build-id core files on build-id system
Jan Kratochvil [Thu, 21 Nov 2013 14:33:22 +0000 (15:33 +0100)]
Fix non-build-id core files on build-id system

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
10 years agoVerify file vs. core build-id, when both available
Jan Kratochvil [Thu, 21 Nov 2013 14:31:04 +0000 (15:31 +0100)]
Verify file vs. core build-id, when both available

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
10 years agolink_map: Use proper bias, not l_addr
Jan Kratochvil [Thu, 21 Nov 2013 14:28:02 +0000 (15:28 +0100)]
link_map: Use proper bias, not l_addr

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
10 years agoCompatibility with older kernels such as RHEL-6.
Jan Kratochvil [Tue, 19 Nov 2013 14:00:15 +0000 (15:00 +0100)]
Compatibility with older kernels such as RHEL-6.

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
10 years agolibdwfl: Fix and test aux_sym address_sync with relocated ELF
Josh Stone [Mon, 18 Nov 2013 22:29:35 +0000 (14:29 -0800)]
libdwfl: Fix and test aux_sym address_sync with relocated ELF

The aux_sym address_sync already worked with a full prelink, which has
.gnu.prelink_undo, but it failed on plain relocations with prelink -r.

Now it uses the difference in ehdr.e_entry as a first offset guess, and
the tests confirm this seems to work fine.

Signed-off-by: Josh Stone <jistone@redhat.com>
10 years agotests: Fix broken dwflsyms tests, extend test and add prelink tests.
Mark Wielaard [Fri, 15 Nov 2013 23:11:38 +0000 (00:11 +0100)]
tests: Fix broken dwflsyms tests, extend test and add prelink tests.

The two test files that contains minisymtab tables and the expected test
output were wrongly generated. Also prelink tests were missing to check
that a prelinked main ELF file with separate debug or minisyms generated
correctly adjusted symbol values. The dwflsyms test was also extended to
check print and check the result of dwfl_module_relocate_address.

Reported-by: Josh Stone <jistone@redhat.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoUpdate m4/ChangeLog for m4/biarch.m4 authorship.
Jan Kratochvil [Fri, 15 Nov 2013 16:10:45 +0000 (17:10 +0100)]
Update m4/ChangeLog for m4/biarch.m4 authorship.

10 years agoCode cleanup: Remove const in prototype
Jan Kratochvil [Thu, 14 Nov 2013 19:55:41 +0000 (20:55 +0100)]
Code cleanup: Remove const in prototype

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
10 years agoFix dwfl_attach_state machine->elf
Jan Kratochvil [Thu, 14 Nov 2013 19:53:20 +0000 (20:53 +0100)]
Fix dwfl_attach_state machine->elf

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
10 years agoProvide __libdwfl_module_getsym to get dwfl_file *
Jan Kratochvil [Wed, 13 Nov 2013 19:00:56 +0000 (20:00 +0100)]
Provide __libdwfl_module_getsym to get dwfl_file *

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
10 years agoFix dwfl_module_addrsym for minidebuginfo
Jan Kratochvil [Wed, 13 Nov 2013 18:58:06 +0000 (19:58 +0100)]
Fix dwfl_module_addrsym for minidebuginfo

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
10 years agostack: Add basic argp version and bug definitions.
Mark Wielaard [Sun, 10 Nov 2013 21:17:05 +0000 (22:17 +0100)]
stack: Add basic argp version and bug definitions.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibelf: Only memcpy ehdr back when not already directly mmapped.
Mark Wielaard [Fri, 8 Nov 2013 18:28:16 +0000 (19:28 +0100)]
libelf: Only memcpy ehdr back when not already directly mmapped.

When the elf file is mmapped ehdr can still point to ehdr_mem if the
address is unaligned.  In such cases we do need to memcpy the ehdr back
to the file. We shouldn't when ehdr already comes directly from the mmapped
file, because that would cause an memcpy call with overlapping addresses
(ehdr being copied directly over itself).

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoFix some (harmless) cppcheck warnings.
Mark Wielaard [Sat, 9 Nov 2013 15:45:22 +0000 (16:45 +0100)]
Fix some (harmless) cppcheck warnings.

[dwarf_getaranges.c:149]: (warning) Ineffective statement similar to '*A++;'.
Did you intend to write '(*A)++;'?

There was already an XXX statement that we weren't using the result.
Explicitly read the segment_size and check it is zero. And report an
error if it isn't, since we aren't prepared to handle such a case.

[arlib.c:62]: (error) Uninitialized variable: tmpbuf
[arlib.c:124]: (error) Uninitialized variable: tmpbuf

cppcheck is wrong. tmpbuf is initialized in the snprintf call whose result
is use in the same memcpy call. It does make the code less readable and
harder to understand. So explicitly split the snprintf and memcpy calls.

[nm.c:766]: (warning) Assert statement modifies 'cnt'.

The cnt variable was only used for this assert sanity check.
But it is bad style to do have side effects inside an assert statement.
Increase cnt after the assert.

Reported-by: David Binderman <dcb314@hotmail.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoUnwinder for x86*.
Jan Kratochvil [Thu, 30 May 2013 12:37:38 +0000 (14:37 +0200)]
Unwinder for x86*.

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agodwfl_core_file_report: Remove the use of MAX.
Jan Kratochvil [Thu, 7 Nov 2013 20:30:17 +0000 (21:30 +0100)]
dwfl_core_file_report: Remove the use of MAX.

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
10 years agodwfl_core_file_report: Fix a regression of dwfl_core_file_report retval
Jan Kratochvil [Thu, 7 Nov 2013 20:27:54 +0000 (21:27 +0100)]
dwfl_core_file_report: Fix a regression of dwfl_core_file_report retval

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
10 years agodwfl_core_file_report: Fix core files for re-prelink-ed files
Jan Kratochvil [Thu, 7 Nov 2013 15:47:19 +0000 (16:47 +0100)]
dwfl_core_file_report: Fix core files for re-prelink-ed files

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
10 years agodwfl_core_file_report: Code cleanup: Reindentation.
Jan Kratochvil [Thu, 7 Nov 2013 15:34:58 +0000 (16:34 +0100)]
dwfl_core_file_report: Code cleanup: Reindentation.

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
10 years agoconfigure.ac: Warn when --enable-dwz=no, but /usr/lib/debug/.dwz exists.
Mark Wielaard [Wed, 6 Nov 2013 13:57:33 +0000 (14:57 +0100)]
configure.ac: Warn when --enable-dwz=no, but /usr/lib/debug/.dwz exists.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoconfigure.ac: Add warning that --enable-thread-safety is experimental.
Mark Wielaard [Wed, 6 Nov 2013 11:21:32 +0000 (12:21 +0100)]
configure.ac: Add warning that --enable-thread-safety is experimental.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibelf: Write all section headers if elf flags contains ELF_F_DIRTY.
Mark Wielaard [Tue, 5 Nov 2013 15:27:32 +0000 (16:27 +0100)]
libelf: Write all section headers if elf flags contains ELF_F_DIRTY.

When ehdr e_shoff changes, elf flags is set dirty. This indicates that
the section header moved because sections were added/removed or changed
in size.

Reported-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoFix expansion of libdw_a_LIBADD
Michael Forney [Fri, 1 Nov 2013 07:51:05 +0000 (00:51 -0700)]
Fix expansion of libdw_a_LIBADD

At least with automake-1.14, libdw_a_LIBADD currently expands to:

    <snip>
    am__DEPENDENCIES_1 =
    libdw_a_DEPENDENCIES = $(addprefix ../libdwfl/,$(shell \
            $(am__DEPENDENCIES_1) t ../libdwfl/libdwfl.a))
    <snip>
    libdw_a_LIBADD = $(addprefix ../libdwfl/,$(shell $(AR) t ../libdwfl/libdwfl.a))

This leads to the spurious error message:

    make[2]: t: Command not found

Signed-off-by: Michael Forney <mforney@mforney.org>
10 years agoCheck for prefixed ar, readelf, and nm
Michael Forney [Fri, 1 Nov 2013 07:51:04 +0000 (00:51 -0700)]
Check for prefixed ar, readelf, and nm

Sometimes with cross-compile toolchains, the tools are prefixed with the
target arch. Using AC_CHECK_TOOL looks for tools named like this.

Signed-off-by: Michael Forney <mforney@mforney.org>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoreadelf: Solve comparison between signed and unsigned compiler warning.
Mark Wielaard [Tue, 5 Nov 2013 12:37:33 +0000 (13:37 +0100)]
readelf: Solve comparison between signed and unsigned compiler warning.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agotests: allfcts.c (main): Correct dwarf_getfuncs return value check.
Mark Wielaard [Tue, 5 Nov 2013 10:27:19 +0000 (11:27 +0100)]
tests: allfcts.c (main): Correct dwarf_getfuncs return value check.

The return value of dwarf_getfuncs is a ptrdiff_t that is zero on success,
or non-zero (an offset to continue the search) when the callback returned
DWARF_CB_ABORT or on error. When an error occurs dwarf_errno is set.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoREADME: Fix compatbile -> compatible typo.
Mark Wielaard [Mon, 4 Nov 2013 14:43:33 +0000 (15:43 +0100)]
README: Fix compatbile -> compatible typo.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoREADME: Document that tools and libraries should be upgraded together.
Mark Wielaard [Mon, 4 Nov 2013 14:19:32 +0000 (15:19 +0100)]
README: Document that tools and libraries should be upgraded together.

On some distributions it was possible to upgrade separate parts of elfutils
individually. That causes hard to debug issues since some tools (e.g. readelf)
and some libraries (e.g. libdw) depend on libelf internal data structures,
which could be different between versions (or when configured with different
flags). So explicitly document that they should always be upgraded together.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoFix executable_for_core for non-dwfl_standard_argp
Jan Kratochvil [Wed, 30 Oct 2013 09:48:20 +0000 (10:48 +0100)]
Fix executable_for_core for non-dwfl_standard_argp

./
2013-10-30  Jan Kratochvil  <jan.kratochvil@redhat.com>

* NEWS (Version 0.158): New.

libdw/
2013-10-30  Jan Kratochvil  <jan.kratochvil@redhat.com>

* libdw.map (ELFUTILS_0.158): New.

libdwfl/
2013-10-30  Jan Kratochvil  <jan.kratochvil@redhat.com>

* argp-std.c (parse_opt): Use executable parameter of
dwfl_core_file_report.
* core-file.c (dwfl_core_file_report): Add parameter executable.  Set
it to DWFL.  Add NEW_VERSION for it.
(_compat_without_executable_dwfl_core_file_report): New.  Twice.
* libdwfl.h (dwfl_core_file_report): Add parameter executable, update
the function comment.

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
10 years agolibdw: Handle dwz multi files correctly in dwarf_getfuncs.
Mark Wielaard [Thu, 10 Oct 2013 09:40:12 +0000 (11:40 +0200)]
libdw: Handle dwz multi files correctly in dwarf_getfuncs.

Don't use DIE offsets, but use their addresses to make sure they are unique.
Include test cases where main and alt file have subprograms at same offsets.

Reported-by: Josh Stone <jistone@redhat.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibdwfl: Don't report and abort on non-file mappings in maps.
Mark Wielaard [Tue, 15 Oct 2013 21:53:32 +0000 (23:53 +0200)]
libdwfl: Don't report and abort on non-file mappings in maps.

proc_maps_report, used for -p or -M, could report modules with names
that were not absolute file names (and not the special vdso marker).
dwfl_linux_proc_find_elf would abort on such names. This isn't a very
nice thing to do in a library. Make sure only real (absolute) file
mappings are reported and don't abort when unexpected file names are
found, just report failure.

Test case with some examples as found in Linux /proc/PID/maps added.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoar: Correct operation check when instance_specifed is set.
Mark Wielaard [Fri, 18 Oct 2013 08:37:53 +0000 (10:37 +0200)]
ar: Correct operation check when instance_specifed is set.

Reported-by: David Binderman <dcb314@hotmail.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoUpdate Ukrainian translation
Yuri Chornoivan [Wed, 9 Oct 2013 15:04:59 +0000 (18:04 +0300)]
Update Ukrainian translation

Signed-off-by: Yuri Chornoivan <yurchor@ukr.net>
10 years agobackends: ppc_abi_cfi reg1 use DW_CFA_val_offset not DW_CFA_val_expression.
Mark Wielaard [Sun, 6 Oct 2013 15:04:07 +0000 (17:04 +0200)]
backends: ppc_abi_cfi reg1 use DW_CFA_val_offset not DW_CFA_val_expression.

Register rules using expressions are stored using an offset from the
start of the .eh_frame or .debug_frame ELF section data. Since abi_cfi
rules aren't stored in those ELF sections they should use neither
DW_CFA_expression nor DW_CFA_val_expression. The only backend that used
DW_CFA_val_expression was ppc_cfi.c. It was easier to express the same
rule using DW_CFA_val_offset than to change the code to handle register
rules using expressions. On most architectures this did work by accident.
See the definition of struct dwarf_frame_register value in libdw/cfi.h to
see why. But on ia64 the abi_cfi data and actual frame data were placed
too far apart and caused a crash in tests/run-addrcfi.sh for ppc32.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibdw: Make sure that every debug_types sig8 is hashed
Josh Stone [Thu, 3 Oct 2013 19:38:25 +0000 (12:38 -0700)]
libdw: Make sure that every debug_types sig8 is hashed

When dwarf_formref_die can't find a sig8 in the hash, it walks
__libdw_intern_next_unit, and was then adding those to the hash.
However, if dwarf_offdie_types is called earlier, which also uses that
next_unit, then they are missed from the hash (and never revisited).

This patch makes __libdw_intern_next_unit do the sig8 hash insert, so no
type unit is ever missed.

Signed-off-by: Josh Stone <jistone@redhat.com>
10 years agoUpdate elf.h from glibc
Petr Machata [Tue, 1 Oct 2013 14:29:41 +0000 (16:29 +0200)]
Update elf.h from glibc

Signed-off-by: Petr Machata <pmachata@redhat.com>
10 years ago0.157 release updates for NEWS, elfutils.spec.in and .po files. elfutils-0.157
Mark Wielaard [Mon, 30 Sep 2013 11:50:26 +0000 (13:50 +0200)]
0.157 release updates for NEWS, elfutils.spec.in and .po files.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoShow contents NT_FILE core note in readelf
Petr Machata [Thu, 26 Sep 2013 19:02:22 +0000 (21:02 +0200)]
Show contents NT_FILE core note in readelf

Signed-off-by: Petr Machata <pmachata@redhat.com>
10 years agoShow contents NT_SIGINFO core note in readelf
Petr Machata [Wed, 25 Sep 2013 22:39:34 +0000 (00:39 +0200)]
Show contents NT_SIGINFO core note in readelf

Signed-off-by: Petr Machata <pmachata@redhat.com>
10 years agolibdw: Fix compiler warnings on 32-bit.
Mark Wielaard [Sun, 29 Sep 2013 22:39:07 +0000 (00:39 +0200)]
libdw: Fix compiler warnings on 32-bit.

Don't cast directly to/from Dwarf_Word (uint64_t) to/from pointers,
but use uintptr_t as intermediary to prevent cast to pointer from
integer of different size warnings.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoRecognize names of some new core note types in ebl_core_note_type_name
Petr Machata [Wed, 25 Sep 2013 22:38:37 +0000 (00:38 +0200)]
Recognize names of some new core note types in ebl_core_note_type_name

Signed-off-by: Petr Machata <pmachata@redhat.com>
10 years agoPrepare 0.157 release.
Mark Wielaard [Fri, 27 Sep 2013 12:02:26 +0000 (14:02 +0200)]
Prepare 0.157 release.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoUpdate elf.h from glibc
Petr Machata [Mon, 17 Jun 2013 21:52:27 +0000 (23:52 +0200)]
Update elf.h from glibc

Signed-off-by: Petr Machata <pmachata@redhat.com>
10 years agolibdw: Simplify __libdw_visit_scopes' tag checks
Josh Stone [Tue, 24 Sep 2013 22:52:05 +0000 (15:52 -0700)]
libdw: Simplify __libdw_visit_scopes' tag checks

The former classify_die() was splitting tags into more classes than
actually needed.

The one place that used the "imported" die_class now just compares to
DW_TAG_imported_unit directly.

The recursion check was squashing "match", "match_inline", and "walk"
into the same action.  Now that uses the new may_have_scopes(), which
just returns true for all tags that had those classifications.

The net result has no functional change, but performs better.

Signed-off-by: Josh Stone <jistone@redhat.com>
10 years agoeblsectionstripp.c (ebl_section_strip_p): Check shdr_l is not NULL.
Mark Wielaard [Wed, 25 Sep 2013 11:02:53 +0000 (13:02 +0200)]
eblsectionstripp.c (ebl_section_strip_p): Check shdr_l is not NULL.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agolibdw: Make dwarf_getfuncs find all (defining) DW_TAG_subprogram DIEs.
Mark Wielaard [Fri, 20 Sep 2013 13:50:42 +0000 (09:50 -0400)]
libdw: Make dwarf_getfuncs find all (defining) DW_TAG_subprogram DIEs.

dwarf_getfuncs used to return only the DW_TAG_subprogram DIEs that were
direct children of the given CU. This is normally how GCC outputs the
subprogram DIEs. But not always. For nested functions the subprogram DIE
is placed under the code construct DIE where it is nested. Other compilers
might output the defining subprogram DIE of a C++ class function under
the DW_TAG_namespace DIE where it was defined. Both such constructs seem
allowed by the DWARF specification. So just searching the CU DIE children
was wrong.

To find all (defining) subprogram DIEs in a CU dwarf_getfuncs should
use __libdw_visit_scopes to walk the tree for all DIEs that can contain
subprograms as children. The only tricky part is making sure the offset
returned and used when the callback returns DWARF_CB_ABORT is correct
and the search continues at the right spot in the CU DIE tree. This
operation now needs to rewalk the whole tree.

Two new testcases were added that fail without this patch. And the
allfcts test was tweaked so that it always returns DWARF_CB_ABORT
from its callback to make sure the offset handling is correct.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
10 years agoMake sure --enable-dwz code is also tested during make distcheck.
Mark Wielaard [Fri, 20 Sep 2013 12:48:00 +0000 (14:48 +0200)]
Make sure --enable-dwz code is also tested during make distcheck.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
11 years agolibdwfl: Fix memory leak in cu.c on bad DWARF.
Mark Wielaard [Thu, 12 Sep 2013 14:49:25 +0000 (16:49 +0200)]
libdwfl: Fix memory leak in cu.c on bad DWARF.

If libdw dwarf_offdie fails free cu structure.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
11 years agoFix memory leak and set libdw errno when intern_fde cannot parse start/end.
Mark Wielaard [Thu, 12 Sep 2013 13:49:47 +0000 (15:49 +0200)]
Fix memory leak and set libdw errno when intern_fde cannot parse start/end.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
11 years agolibdwfl: proc_maps_report should not fclose the given file.
Mark Wielaard [Thu, 12 Sep 2013 13:16:13 +0000 (15:16 +0200)]
libdwfl: proc_maps_report should not fclose the given file.

Calling fclose only on bad_report, but not on other errors or success
is confusing. The caller is always responsible for calling fclose on
the given file. Otherwise flcose might be called twice (e.g. in
dwfl_linux_proc_report).

Signed-off-by: Mark Wielaard <mjw@redhat.com>
11 years agoFix typo in dwfl_module_getdwarf.c (find_symtab).
Mark Wielaard [Thu, 12 Sep 2013 09:27:56 +0000 (11:27 +0200)]
Fix typo in dwfl_module_getdwarf.c (find_symtab).

Call elf_getdata with aux_xndxscn, not xndxscn, for aux_symxndxdata.
This was a copy/paste error from the code just above for symxndxdata.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
11 years agotests: Add new varlocs test for dwarf_getlocation* functions.
Mark Wielaard [Fri, 30 Aug 2013 22:52:12 +0000 (00:52 +0200)]
tests: Add new varlocs test for dwarf_getlocation* functions.

This tests the new dwarf_getlocations, dwarf_getlocation_attr and
dwarf_getlocation_die functions. But it is also an example of how
to handle location expressions and which libdw functions can be
used to access all information required to interpret each DW_OP.

It might make sense to extend this test/example into a program
that verifies various properties of DWARF expressions.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
11 years agolibdw: Add new functions dwarf_getlocation_attr and dwarf_getlocation_die.
Mark Wielaard [Fri, 30 Aug 2013 21:55:12 +0000 (23:55 +0200)]
libdw: Add new functions dwarf_getlocation_attr and dwarf_getlocation_die.

Some location expression operations have a DIE associated with them.
Examples are some of the new GNU typed DWARF extensions, DW_OP_GNU_convert,
DW_OP_GNU_reinterpret, DW_OP_GNU_const_type, DW_OP_GNU_regval_type and
DW_OP_GNU_deref_type. Others have (block) values associated with them,
like DW_OP_GNU_entry_value and DW_OP_GNU_const_type.

It is not always easy to access these values. The DIE offset is given in
various formats either as global offset or CU relative offset. The (block)
value might be constant or a location description. And the block might be
encoded with a uleb128 or ubyte length. The new functions help to easily
get at the DIE or attribute value.

In theory dwarf_getlocation_attr could be used for all cases, since
besides returning DW_AT_const_value or DW_AT_location, it could also
return an attribute referencing a DIE. But at least one operation,
DW_OP_GNU_const_type, has both a (type) DIE and a constant (block)
value associated with it. And directly getting the DIE when needed
is easier than first having to retrieve a (synthesized) attribute
and then getting the actual (type) DIE.

Expression operations that reference an actual DIE for the
DW_AT_location or DW_AT_const_value, like DW_OP_call2, DW_OP_call4,
DW_OP_callref and DW_OP_GNU_implicit_pointer can be used with both
dwarf_getlocation_attr and dwarf_getlocation_die.

DW_OP_implicit_value and DW_OP_GNU_implicit_pointer already had
their own special accessors (dwarf_getlocation_implicit_value
and dwarf_getlocation_implicit_pointer), but it seemed consistent
to include them in the new more generic accessors too.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
11 years agolibdw: Add new function dwarf_getlocations.
Mark Wielaard [Fri, 23 Aug 2013 14:12:37 +0000 (16:12 +0200)]
libdw: Add new function dwarf_getlocations.

Using dwarf_getlocation it is possible to get single location
descriptions and with dwarf_getlocation_addr it is possible to
get a location list covering a specific address.  But sometimes
it is more convenient to get all ranges covered by a location
list.  For example when a specific address isn't covered and
you want to find alternative addresses where a location
description is defined.

dwarf_getlocations is modelled after dwarf_ranges. It enumerates
the location ranges and descriptions covered by the given
attribute.  In the first call OFFSET should be zero and *BASEP
need not be initialized.  Returns -1 for errors, zero when
there are no more locations to report, or a nonzero OFFSET
value to pass to the next call.  Each subsequent call must
preserve *BASEP from the prior call.  Successful calls fill in
*STARTP and *ENDP with a contiguous address range and *EXPR with
a pointer to an array of operations with length *EXPRLEN.  If
the attribute describes a single location description and not a
location list the first call (with OFFSET zero) will return the
location description in *EXPR with *STARTP set to zero and *ENDP
set to minus one.

ptrdiff_t dwarf_getlocations (Dwarf_Attribute *attr, ptrdiff_t offset,
                              Dwarf_Addr *basep, Dwarf_Addr *startp,
                              Dwarf_Addr *endp, Dwarf_Op **expr,
                              size_t *exprlen);

Signed-off-by: Mark Wielaard <mjw@redhat.com>
11 years agobackends: Hook abi_cfi for arm.
Mark Wielaard [Mon, 2 Sep 2013 14:46:50 +0000 (16:46 +0200)]
backends: Hook abi_cfi for arm.

New arm_abi_cfi that defines initial CFA, rules for callee-saved regs,
including VFP ones and return register.

Note the DWARF abi extension for ARM says that "registers intentionally
unused" should also be initialized as if by DW_CFA_same_value.  The
example given is "an integer-only function might be included in one
executable file for targets with VFP and another for targets without".
We don't currently do this yet. See the DWARF and calling convention
documents:

DWARF for the ARM Architecture ABI r2.09
http://infocenter.arm.com/help/topic/com.arm.doc.ihi0040b/IHI0040B_aadwarf.pdf

Procedure Call Standard for the ARM Architecture ABI r2.09
http://infocenter.arm.com/help/topic/com.arm.doc.ihi0042e/IHI0042E_aapcs.pdf

Also adds addrcfi arm testcase.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
11 years agotests: Add s390 and s390x addrcfi testcases.
Mark Wielaard [Wed, 28 Aug 2013 19:54:58 +0000 (21:54 +0200)]
tests: Add s390 and s390x addrcfi testcases.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
11 years agotests: Add ppc32 and ppc64 addrcfi testcases.
Mark Wielaard [Wed, 28 Aug 2013 16:10:44 +0000 (18:10 +0200)]
tests: Add ppc32 and ppc64 addrcfi testcases.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
11 years agobackends: Hook abi_cfi for ppc and s390.
Jan Kratochvil [Tue, 27 Aug 2013 20:49:36 +0000 (22:49 +0200)]
backends: Hook abi_cfi for ppc and s390.

Signed-off-by: Jan Kratochvil <jan.kratochvil@redhat.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
11 years agotests: Add run-addrcfi.sh test for libdw cfi dwarf_frame_* functions.
Mark Wielaard [Tue, 27 Aug 2013 13:40:56 +0000 (15:40 +0200)]
tests: Add run-addrcfi.sh test for libdw cfi dwarf_frame_* functions.

We require architecture backends to implement the ebl abi_cfi hook
to provide the ABI's default CFI program as used by the libdw dwarf cfi
functions. There is the addrcfi test program that prints the return
address, cfa location expression and register states as returned by
various dwarf_cfi_* and dwarf_frame functions. But that has to be run
by hand. The new run-addrcfi.sh tests hooks addrcfi up to some existing
architecture specific test files and known addresses to more easily
(and automaticly) check that the default CFI program is implemented
correctly and to test the libdw cfi frame info functionality.

Only i386 and x86_64 are tested for now since other backends don't have
the abi_cfi hook yet.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
11 years agobackends: Always set *prefix to "" when not used in register_info hook.
Mark Wielaard [Wed, 28 Aug 2013 13:57:27 +0000 (15:57 +0200)]
backends: Always set *prefix to "" when not used in register_info hook.

For ia64 and tilegx *prefix was already set to the empty string, but
arm, ppc and sh used NULL to indicate no prefix preceded the register
name in the canonical assembler syntax. Consistently use the empty string
in all backends since dwfl_module_register_names says: 'a prefix used in
assembler syntax (such as "%" or "$", may be "")'. So users had to handle
the empty string already, and might forget to handle the NULL case
(like our own addrcfi testcase).

Signed-off-by: Mark Wielaard <mjw@redhat.com>
11 years agogelf.h: Fix typo in comment.
Namhyung Kim [Wed, 28 Aug 2013 14:39:00 +0000 (23:39 +0900)]
gelf.h: Fix typo in comment.

Signed-off-by: Namhyung Kim <namhyung@gmail.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
11 years agogelf_getauxv: Add missing whitespace.
Mark Wielaard [Tue, 27 Aug 2013 22:03:29 +0000 (00:03 +0200)]
gelf_getauxv: Add missing whitespace.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
11 years agogelf_getauxv: Remove unnecessary casts to char *.
Mark Wielaard [Tue, 27 Aug 2013 09:39:52 +0000 (11:39 +0200)]
gelf_getauxv: Remove unnecessary casts to char *.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
11 years agogelf_getauxv: Use memcpy, not pointer deref, to avoid alignment problems.
Kurt Roeckx [Sun, 25 Aug 2013 21:15:13 +0000 (23:15 +0200)]
gelf_getauxv: Use memcpy, not pointer deref, to avoid alignment problems.

Signed-off-by: Kurt Roeckx <kurt@roeckx.be>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
11 years agolibdwfl/linux-kernel-modules.c (report_kernel): Pass add_p_vaddr as true.
Mark Wielaard [Thu, 22 Aug 2013 11:45:16 +0000 (13:45 +0200)]
libdwfl/linux-kernel-modules.c (report_kernel): Pass add_p_vaddr as true.

On some architectures (e.g. x86_64) the vmlinux is ET_EXEC, while on
others (e.g. ppc64) it is ET_DYN.  In both cases the phdr p_vaddr will
be non-zero.  We want the image to be placed as if it was ET_DYN, so
pass true for add_p_vaddr which will do the right thing (in combination
with a zero base) in either case.

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