| Commit message (Collapse) | Author | Age | Files | Lines |
| |
|
|
|
|
|
|
| |
libdw used its own code for decompressing GNU style .zdebug sections.
Using elf_compress and elf_compress_gnu instead makes it possible to
transparently use either GNU style or ELF style compressed data.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
| |
Helper function to get the size of a GNU compressed zdebug section.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
| |
Although it isn't supposed to happen there could be FDEs that cover the
same address range. Don't leak such FDEs and use an existing FDE for
consistency.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
| |
If the FDE end <= start then it doesn't actually cover a valid code range.
Don't use and cache such FDEs (it will cause memory leaks if there is
another FDE that has the same start address and a valid code range).
Such FDEs have been seen in the backtrace.ppc.exec testfile.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
| |
The fake_loc_cu is used when synthesizing attributes for Dwarf_Ops that
came from a location list entry in dwarf_getlocation_attr. Make sure
we remove the loc cache stored in it when disposing of the fake_loc_cu.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
| |
No nested functions to compile with clang/llvm.
Signed-off-by: Chih-Hung Hsieh <[email protected]>
|
| |
|
|
|
|
|
| |
* No nested functions to compile with clang/llvm.
Signed-off-by: Chih-Hung Hsieh <[email protected]>
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
| |
libdwfl sets the Dwfl_Module Ebl for the eh_cfi and dwarf_cfi cache to
save a bit of memory. It also calls ebl_closebackend on the ebl to free
it. The Dwarf_CFI never frees the Ebl in the cache, even when it opened
one itself. This means that if only libdw calls are used to access the
Dwarf_CFI the Ebl might be leaked.
Always destroy the Dwarf_CFI cache Ebl in __libdw_destroy_frame_cache.
And in __libdwfl_module_free clear the Dwarf_CFI Ebl if it is the
Dwfl_Module Ebl before calling dwarf_cfi_end and dwarf_end.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
| |
Starting with commit f8443bd09f8a8d3d84a63e5ce206a218e57dff7a,
we might jump to "out" on error before initialization of "state".
Initialize "state" early to fix this issue.
Signed-off-by: Dmitry V. Levin <[email protected]>
|
| |
|
|
|
|
|
| |
Move nested functions in libdw/dwarf_getsrclines.c to file scope.
Signed-off-by: Chih-Hung Hsieh <[email protected]>
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
| |
Signed-off-by: Chih-Hung Hsieh <[email protected]>
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
| |
Explicitly link libelf and libdw with -lz.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
| |
* No nested functions to compile with clang/llvm.
Signed-off-by: Chih-Hung Hsieh <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
AC_SYS_LARGEFILE defines _FILE_OFFSET_BITS in config.h if needed for
LFS, and this automatically maps things like open to open64. But quite
a few places used explicit 64-bit names, which won't work on platforms
like FreeBSD where off_t is always 64-bit and there are no foo64 names.
It's better to just trust that AC_SYS_LARGEFILE is doing it correctly.
But we can verify this too, as some file could easily forget to include
config.h. The new tests/run-lfs-symbols.sh checks all build targets
against lfs-symbols (taken from lintian) to make sure everything was
implicitly mapped to 64-bit variants when _FILE_OFFSET_BITS is set.
Signed-off-by: Josh Stone <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
| |
Note, elfutils does not explicitly enable AM_SILENT_RULES. It's only
available starting from automake 1.11, but starting from automake 1.13
silent rules are always generated, defaulting to verbose. $(AM_V_foo)
additions should be no-ops on systems that don't support silent rules.
To be silent, use "./configure --enable-silent-rules" or "make V=0".
Signed-off-by: Josh Stone <[email protected]>
|
| |
|
|
|
|
|
| |
This avoids relocation overflows in sparc/sparc64 targets while
linking, where the reachable data using -fpic is only 4kb.
Signed-off-by: Jose E. Marchesi <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Since we banned old style function definitions GCC is able to diagnose
function definitions that don't match the function declaration:
elf32_getehdr.c:78: error: conflicting types for ‘__elf64_getehdr_wrlock’
libelfP.h:498: note: previous declaration of ‘__elf64_getehdr_wrlock’
This happens on i386 because there internal functions are marked with:
# define internal_function __attribute__ ((regparm (3), stdcall))
Make sure all internal function declarations and definitions are marked
with internal_function.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
| |
We already require -std=gnu99 and old-style function definitions might
hide some compiler warnings.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
| |
GCC6 will warn about the reassignement of the nonnull result pointer.
The reassignment is indeed a little questionable. The compiler cannot
see that the pointer will not actually be reassigned since the function
will just return the same pointer value except when the dwarf_formref_die
function fails. In which case we don't use the result anymore. So the
compiler has to pessimistically assume the pointer will need to be
reloaded in the loop every time. Help the compiler generate slightly
better code by just checking whether the function fails directly instead
of reusing the pointer value for this.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
| |
GCC6 and Clang give warnings on redundant NULL tests of parameters
that are declared with __nonnull_attribute__.
Signed-off-by: Chih-Hung Hsieh <[email protected]>
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
| |
And change K&R C function definition to ansi, which prevented GCC from
seeing that callers passed in const arguments.
Signed-off-by: Chih-Hung Hsieh <[email protected]>
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
| |
Signed-off-by: Chih-Hung Hsieh <[email protected]>
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
| |
See http://www.dwarfstd.org/ShowIssue.php?issue=120218.1
GHC emits this language code (0x18).
Also updated https://fedorahosted.org/elfutils/wiki/DwarfExtensions
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
| |
Just assert early that the page size isn't unreasonable small instead of
corrupting memory later.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
| |
When there is an error with the first entry we might already have allocated
the memory but not yet set cnt to 1. Just always free the memory on error.
free (NULL) is a nop anyway and doesn't matter on a failure path.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
| |
dwarf_formudata can return an error for bad DWARF. Don't ignore it.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
| |
We might jump to "out" early on error. Help gcc see that isn't an issue
by initializing dirarray to dirstack early.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
| |
We might jump to "out" early on error. Then filelist might not be set yet
and we might try to free garbage. Set it to the null_file early.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
| |
If we are going to dereference a pointer there should be at least enough
data to hold a pointer. Found by afl-fuzz.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| |
Limit stack usage of lines with MAX_STACK_LINES, files with MAX_STACK_LINES
and dirs with MAX_STACK_DIRS. Calculate number of dirs needed first, then
create dirarray directly, without needing the next field. Free not stack
allocated lines and files at the end.
Use preallocated stack arrays for all instead of calling alloca to help
compiler see actual stack usage.
The current stack allocation limits are 4096 lines, 1024 files in 256 dirs
per CU. For GCC 4.8 libstdc++.so has on average 512 lines per CU. With
these settings read_srclines uses max 228K of stack on x86_64.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
| |
Create a stack allocated array to hold locs. Allocate locs bigger than
the array with malloc and free them when done.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
| |
In order to provide better feedback to users, a distinction is made
between finding no dwarf info (E_NO_DWARF) and finding dwarf info but
which is compressed and failed to decompress (E_COMPRESSED_ERROR). This
can occur for example if elfutils was built without zlib support, or if
the compressed section is invalid.
Signed-off-by: Jonathan Lebon <[email protected]>
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
| |
To help legibility, we separate the section name matching from the
actual section reading. This also allows us to remove duplicate code in
cases of sections appearing twice or empty section data. There are no
changes in functionality. The indentation will be fixed in the next
commit, in the interest of keeping this commit easier to read.
Signed-off-by: Jonathan Lebon <[email protected]>
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
| |
We do check whether the values we store for the line fit our data
representation in add_new_line, but on 32bit systems we would fail
to notice line overflowing.
https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c32
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
| |
https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c30
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
|
|
|
| |
argp is not part of POSIX standards and not provided by uClibc or
some other standard C libraries. However, it is possible to link
against a breakout argp library. One is provided at
http://www.lysator.liu.se/~nisse/misc/
This patch tests if libc provides argp otherwise it adds the linker
flag -largp where needed in the build system.
Signed-off-by: Anthony G. Basile <[email protected]>
Signed-off-by: Max Filippov <[email protected]>
|
| |
|
|
|
|
|
|
|
|
| |
gcc -fsanitize=undefined pointed out that for too big sleb128 values we
could shift into the sign bit. So for sleb128 values that have to fit
in a (signed) int64_t variable reduce the max number of steps by one.
https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c29
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
|
| |
In theory user defined debug macros can have an arbitrary number of
arguments. Don't allocate them all on stack. If there are more than
8 (arbitrary number, but no sane macro should have more arguments),
then dynamically allocate and free the attributes.
Found by gcc -fsanitize=undefined. Which pointed out the nforms could
be zero, creating an empty vla (which could cause undefined behavior).
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
| |
Signed-off-by: Petr Machata <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
- Make the macro names properly scoped (DWARF_ALL_KNOWN_* and
DWARF_ONE_KNOWN_*).
- Simplify the calling convention: don't keep track of the comment
associated with the enumerator, always use the non-_DESC
DWARF_ONE_KNOWN_* callback.
- Install known-dwarf.h alongside libdw.h and others.
Signed-off-by: Petr Machata <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
| |
GCC5 adds support for the new Fortran 2003 and 2008 standard DWARF5
language codes. Add them to dwarf.h and handle them in dwarf_aggregate_size.
http://dwarfstd.org/ShowIssue.php?issue=141121.1
Also documented at https://fedorahosted.org/elfutils/wiki/DwarfExtensions
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
| |
GCC5 adds support for the new C11 _Atomic DWARF5 DW_TAG_atomic_type
qualifier. Add it to dwarf.h and handle it in dwarf_peel_type.
http://dwarfstd.org/ShowIssue.php?issue=131112.1
Also documented at https://fedorahosted.org/elfutils/wiki/DwarfExtensions
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
|
| |
With CFLAGS='-Og -g', F21 gcc hits -Werror=maybe-uninitialized in
read_encoded_value at "*result += value". It's fine with -O2/-O0.
In particular it seems to care about the __libdw_cfi_read_address_inc
calls. By my inspection, the only way those don't set value are for
error cases, which will then return immediately. This patch just sets
value = 0 to begin with, so gcc is always convinced it's fine.
Signed-off-by: Josh Stone <[email protected]>
|
| |
|
|
|
|
|
|
| |
- Instead of bailing out at iteration start, we remember the
base-address-selecting attributes were not seen, and then bail out
later if no base address selection entry has been seen.
Signed-off-by: Petr Machata <[email protected]>
|
| |
|
|
|
|
|
|
|
|
| |
In commit 7d9b5a dwfl_module_getsrc was changed so that it returns the last
line record <= addr, rather than returning immediately on a match. This
changes dwarf_getsrc_die to do the same. And it adds a new test that checks
this by comparing against the same results from eu-addr2line (which uses
dwfl_module_getsrc) using dwarf_addrdie and dwarf_getsrc_die instead.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
| |
Sanity check and keep track of binary_search_table data buffer length.
Add bounds check to encoded value reading. Also fix a bug when reading
the eh_frame header data from an other endian ELF image. Add a testcase
that would fail the new sanity checks because of the endian bug.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
| |
The sibling attribute should point after this DIE in the CU.
Otherwise various algorithms might loop or go into infinite recursion
walking the DIE tree.
Found by afl-fuzz.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
| |
Some cfi.c array size allocation calculations might overflow when trying
to accommodate insanely large number of registers. Don't allow register
numbers larger than INT32_MAX / sizeof (dwarf_frame_register).
Found by afl-fuzz.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
| |
afl-fuzz showed that when parse_eh_frame_hdr was called from
getcfi_scn_eh_frame invalid data could be read because of a missing size
check. That check was there when parse_eh_frame_hdr was called from
getcfi_gnu_eh_frame. Move the size check into parse_eh_frame. And add
an extra check to make sure d_buf is not NULL.
Signed-off-by: Mark Wielaard <[email protected]>
|
| |
|
|
|
|
|
|
|
|
|
|
|
| |
afl-fuzz pointed out that __libdw_intern_expression didn't handle CFI
containing DW_OP_call_ref, DW_OP_implicit_pointer or DW_OP_addr. Because
in that case the Dwarf dbg is NULL. Both DW_OP_call_ref and
DW_OP_implicit_pointer cannot be used in CFI. That is just an error.
But DW_OP_addr can be. Without a Dwarf dbg we'll need to read the address
argument directly. Don't use __libdw_read_address_inc which might do a
relocation of the value read. But in practice the relocation hook isn't
implemented anyway.
Signed-off-by: Mark Wielaard <[email protected]>
|