Ulrich Drepper [Thu, 18 Dec 2014 17:32:39 +0000 (12:32 -0500)]
avoid scary command output
The commands to check for invalid text relocations in the generated DSOs
shouldn't be displayed. They contain an echo which prints the text.
This patch suppresses the commands from being printed.
Mark Wielaard [Mon, 15 Dec 2014 18:43:02 +0000 (19:43 +0100)]
readelf: Warn, don't assert, if loclist or rangelist offset is too big.
We use a couple of bits to keep track of the addr size, dwarf size and
warning given for a loclist or rangelist offset. Normally offset won't
be that big and will fit in 61-bits easily. But if not, don't assert,
but just warn we don't handle such large offsets.
Mark Wielaard [Sun, 14 Dec 2014 20:48:23 +0000 (21:48 +0100)]
libdw: Add get_uleb128 and get_sleb128 bounds checking.
Both get_uleb128 and get_sleb128 now take an end pointer to prevent
reading too much data. Adjust all callers to provide the end pointer.
There are still two exceptions. "Raw" dwarf_getabbrevattr and
read_encoded_valued don't have a end pointer associated yet.
They will have to be provided in the future.
Mark Wielaard [Fri, 12 Dec 2014 15:43:04 +0000 (16:43 +0100)]
libdw: Make sure all attributes come with a (fake) CU for bound checks.
All attributes now have a reference to a (fake) CU that has startp and
endp set to the data section where the form data comes from. Use that
for bounds checking in __libdw_form_val_len and dwarf_formblock to make
sure data read doesn't overflow any data section. Remove libdwP.h cu_data
and use cu startp and endp directly where appropriate.
Mark Wielaard [Sat, 13 Dec 2014 23:09:29 +0000 (00:09 +0100)]
Guard against 64bit unsigned wrap around in (int) compare functions.
Dwarf_Adrr and Dwarf_Off are 64-bit unsigned, and comparison functions
used in qsort or tfind return int, it is possible for the difference to
be so large that it wraps around. Make sure to just return -1, 0 or 1
in compare_aranges and compare_cukey.
Mark Wielaard [Fri, 12 Dec 2014 20:51:27 +0000 (21:51 +0100)]
tests: Add an explicit -fasynchronous-unwind-tables for deleted-lib.so.
Some systems don't add a PT_GNU_EH_FRAME segment by default, but the
deleted test depends on it so that it can get at the .eh_frame_hdr table
through the phdrs from the remote memory ELF image. Request one explicitly
with -fasynchronous-unwind-tables.
Josh Stone [Fri, 12 Dec 2014 01:19:23 +0000 (17:19 -0800)]
tests: Test addr2line -i with lexical blocks present
This test is for the fix in commit aecdf2670c02, but it was hampered by
unlucky sorting of line records. With the new stable sort, the test now
gets the desired line numbers.
Josh Stone [Fri, 12 Dec 2014 00:23:46 +0000 (16:23 -0800)]
libdwfl: Search for the last matching address in lines
Now that libdw's srclines use a stable sort, we can reliably choose the
*last* matching line record for a given address, which should be the
innermost where inlines are concerned.
Josh Stone [Thu, 11 Dec 2014 02:33:34 +0000 (18:33 -0800)]
libdw: optimize dwarf_hasattr to just look at abbrev
To just check the presence of an attribute, we only need to look at the
abbreviation data. This optimization avoids reading over die data at all,
except possibly just to get the abbrev code.
Josh Stone [Wed, 10 Dec 2014 19:06:52 +0000 (11:06 -0800)]
addr2line: Iterate scopes for inline's parent function
The function which contains an inline might not be the immediate next
die scope. For instance, there may be a lexical scope in between.
Instead, iterate the remaining scopes until an appropriate tag is found.
Mark Wielaard [Sun, 7 Dec 2014 21:45:28 +0000 (22:45 +0100)]
readelf: DW_OP_call_ref and DW_OP_GNU_implicit_pointer are invalid for CFA.
print_cfa_program might call print_ops with zero offset size. We don't
need (and don't know) the DWARF offset size in that case. DW_OP_call_ref
and DW_OP_GNU_implicit_pointer need to know the offset size because they
reference a DIE. But they are invalid when used from CFA.
Mark Wielaard [Sun, 7 Dec 2014 19:48:43 +0000 (20:48 +0100)]
libdwfl: Check actually used ehsize, shentsize and phentsize in relocate.c
In relocate_section we check relocation sections don't overlap any of the
ELF headers. We should check against the actually used ehsize, shentsize
and phentsize. Not the possibly bogus values in the file ehdr itself.
Mark Wielaard [Sun, 7 Dec 2014 19:26:56 +0000 (20:26 +0100)]
libdwfl: Never relocate value against section zero (load address).
This really is just a robustify patch in case section zero got the
wrong section flags set. In that case __libdwfl_relocate_value might
call dwfl_offline_section_address which might assert (because it isn't
prepared to handle section zero). elf_nextscn will never see section zero.
So be explicit in dwfl_offline_section_address and immediately assert
when shndx is zero. And handle section zero immediately by not relocating
the value in __libdwfl_relocate_value.
Petr Machata [Tue, 2 Dec 2014 20:22:14 +0000 (21:22 +0100)]
Change calling convention of dwarf_getmacros to allow opcode 0xff
We now require callers to pass DWARF_GETMACROS_START to start the
iteration. 0 is still accepted, but signals to libdw that the
iteration request comes from an old-style caller, and that opcode 0xff
should be rejected when iterating .debug_macro, to avoid confusion.
Mark Wielaard [Sat, 29 Nov 2014 19:23:30 +0000 (20:23 +0100)]
libdwfl: Check relocations don't overlap ELF ehdr, shdrs or phdrs.
If either the section that needs the relocation applied, or the
section that the relocations come from overlap one of the ehdrs,
shdrs or phdrs data then refuse to do the relocations. We update
both section data. It isn't illegal for ELF section data to overlap
the header data, but updating the (relocation) data might corrupt
the in-memory libelf headers causing strange corruptions or errors.
Also check offset + size of a relocation doesn't overflow.
Mark Wielaard [Thu, 27 Nov 2014 22:53:30 +0000 (23:53 +0100)]
Add configure --disable-textrelcheck option to enable CC=afl-fuzz on 32bit.
Using american fuzzy lop has found a lot of issues. It would be nice to
make using it a bit easier. Our build files make sure that no shared
library uses text relocations, but afl-gcc will insert some on i686.
http://www.akkadia.org/drepper/textrelocs.html
Now CC=afl-gcc ./configure --disable-textrelcheck will allow them so
that afl can instrument the libraries.
Don't try to use or install them except with afl-fuzz. When selinux is
enabled it might prevent loading the libraries with DT_TEXTREL set.
Mark Wielaard [Thu, 27 Nov 2014 22:41:57 +0000 (23:41 +0100)]
libdw: Initialize variables in getcfi_gnu_eh_frame.
Some older GCCs are not clever enough to realize that when search_table
is NULL not only are search_table_entries and search_table_encoding not
initialized, they are also not used. Giving "may be used uninitialized"
errors.
Mark Wielaard [Sun, 23 Nov 2014 14:27:23 +0000 (15:27 +0100)]
libelf: Copy over any leftover data from src to dest in elf_cvt_note.
If any data is left then the data is likely part of the truncated note
name/desc. This probably means the note is corrupted, but it is better
to have the actual data in dest instead of random uninitialized memory.
Mark Wielaard [Fri, 21 Nov 2014 22:26:35 +0000 (23:26 +0100)]
readelf: print_attributes (-A) robustify and handle non-gnu attributes.
print_attributes wasn't robust against empty or broken attribute sections.
It also only handled GNU attributes. But the arm backend contains some
none-GNU attributes. The difference is in how to handle the tag arguments.
Adds a new test run-readelf-A.sh for both gnu (ppc32) and non-gnu (arm)
attributes.
Mark Wielaard [Sat, 22 Nov 2014 16:33:05 +0000 (17:33 +0100)]
libelf: elf_getphdrnum sanity check the returned phnum result.
The internal __elf_getphdrnum_rdlock might return an inconsistent phnum.
Return a sanitized value, or return an error to users that rely on phnum
to be consistent. That way iterating over all phdrs using elf_getphdr
will return consistent results.
Mark Wielaard [Mon, 24 Nov 2014 21:17:51 +0000 (22:17 +0100)]
dwarf.h: Add DW_LANG_C11, DW_LANG_C_plus_plus_11 and DW_LANG_C_plus_plus_14.
The following patch is needed to recognize the new DW_LANG constants
that GCC 5 might emit as implemented by this GCC patch:
https://gcc.gnu.org/ml/gcc-patches/2014-11/msg02852.html
Also added to https://fedorahosted.org/elfutils/wiki/DwarfExtensions
GCC 5 can emit these new DWARFv5 draft language constants. Handle them in
dwarf_aggregate_size and dwarf_getfuncs. Also handle DW_LANG_Go in
dwarf_aggregate_size (lower bound for array is zero for Go).
Mark Wielaard [Wed, 26 Nov 2014 16:51:28 +0000 (17:51 +0100)]
dwarf.h: Add DW_AT_noreturn.
DW_AT_noreturn is added by GCC5 for functions that don't return to their
caller. It is set on a DW_TAG_subprogram for the traditional GNU noreturn
attribute, the C11 _Noreturn keyword or C++11 [[noreturn]] attribute. It
is a new DWARF5 extension. This is a constant only addition to dwarf.h.
No other part of elfutils currently depends on this attribute.
Also added to https://fedorahosted.org/elfutils/wiki/DwarfExtensions
Mark Wielaard [Mon, 17 Nov 2014 22:35:28 +0000 (23:35 +0100)]
readelf: When the version chain ends, stop processing the entries.
The version definition, auxiliary version, version dependency and needed
version sections chain information together through "next" fields. When
the "next" field is zero there are no more information entries. Stop
processing when we see zero instead of repeatedly processing the same
entry (at offset zero from the current one).
Since elf_strptr can fail and return NULL we should always check the result
before usage. Debug sections are only handled by section name, so make sure
the name actually exists.
Mark Wielaard [Sun, 16 Nov 2014 23:33:36 +0000 (00:33 +0100)]
libelf: Fix handling of (extended) phnum.
If there is no e_phoff e_phnum cannot be trusted. Extended phnum can only
be gotten if we have an actual section table and a shdr for section zero,
Extended phnum can be too large to fit in the file (or a size_t).
Mark Wielaard [Sun, 16 Nov 2014 10:19:29 +0000 (11:19 +0100)]
libelf: getdata check 64bit values correctly on 32bit arch.
On 32bit arches size_t is too small to do size and overflow checks
of 64bit ELF files. Use the actual Elf64 types to make sure checks
on 64bit ELF files are done correctly on 32bit arches.
Mark Wielaard [Mon, 10 Nov 2014 13:49:20 +0000 (14:49 +0100)]
libdwfl: find_dynsym don't assume dynamic linker has adjusted DYNAMIC entries.
commit 037505 "Fix resolving ELF symbols for live PIDs with deleted files"
changed find_dynsym to assume the PT_DYNAMIC entries had been adjusted by
the dynamic linker. That is often a correct assumption when the ELF image
comes from remote memory. But we cannot rely on that. In the case of the
vdso image the DYNAMIC segment has not been adjusted for example.
There is no good way to determine whether the DYNAMIC segment has or
hasn't been adjusted already to the load address by the dynamic linker.
So we just try twice. Once without and if the fails again with assuming
adjustments being applied.
Includes a new vdsosyms testcase that fails on i686 before and succeeds
after the fix.
__libdw_getsrclines should have been marked as internal_function in
both libdwP.h and dwarf_getsrclines.c. Do address_size comparison as
uint8_t to avoid signedness warning.
Petr Machata [Fri, 17 Oct 2014 00:47:03 +0000 (02:47 +0200)]
Support .debug_macro
- This code is based on the following proposal:
http://www.dwarfstd.org/ShowIssue.php?issue=110722.1
- dwarf_getmacros serves either of .debug_macinfo or .debug_macro
transparently, but if the latter uses opcode 0xff, it bails out with
an error. The reason is that in .debug_macro, 0xff is a custom code
that can mean anything, while in .debug_macinfo there's fixed
semantics associated with 0xff.
- dwarf_getmacros_off is a new interface used for requesting iteration
through transparently included units.
- dwarf_macro_getparamcnt and dwarf_macro_param are new interfaces
used for requesting number of parameters of an opcode and individual
parameters. dwarf_macro_getsrcfiles is a new interface used for
requesting a file part of .debug_line unit associated with macro
unit that the opcode comes from.
- The existing interfaces dwarf_macro_opcode, dwarf_macro_param1 and
dwarf_macro_param2 remain operational for old- as well as new-style
Dwarf macro sections, if applicable.
- dwarf_getsrclines was made into a light wrapper around a worker
function that loads line unit given its offset. The worker also
caches loaded units in an offset-keyed search tree, so that we don't
end up re-reading units even though they were read in a different
domain (e.g. a macro unit request can prime cache for later CU
lookup). dwarf_macro_getsrcfiles calls the worker function under
covers.
Mark Wielaard [Mon, 6 Oct 2014 20:00:16 +0000 (22:00 +0200)]
libdw: Add dwarf_peel_type. Use it in dwarf_aggregate_size.
Add new function dwarf_peel_type. Some type annotations in DWARF are
specified by modifier tag type wrappers instead of attributes.
For type aliases (typedef) and qualifiers (const, volatile, restrict)
tags dwarf_peel_type follows the DW_AT_type attributes till it finds
a base, user-defined, reference or pointer type DIE.
Use this new function in the backends for return type DIEs (replacing
the existing dwarf_peel_type there) and in dwarf_aggregate_size so
it can provide the sizes for qualified types too. Add a new version
and testcase for the new dwarf_aggregate_size functionality.
Mark Wielaard [Sun, 5 Oct 2014 15:12:41 +0000 (17:12 +0200)]
dwarf.h: Add DW_AT_GNU_deleted.
DW_AT_GNU_deleted is added by G++ for C++11 deleted special member
functions (= delete;). This is a constant only addition to dwarf.h.
No other part of elfutils currently depends on this attribute.
Also added to https://fedorahosted.org/elfutils/wiki/DwarfExtensions