summaryrefslogtreecommitdiffstats
path: root/libdw
Commit message (Collapse)AuthorAgeFilesLines
* libdw: Use elf_compress[_gnu] to uncompress debug section data.Mark Wielaard2016-01-054-137/+63
| | | | | | | | 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]>
* libdwelf: Add dwelf_scn_gnu_compressed_size.Mark Wielaard2016-01-052-0/+9
| | | | | | Helper function to get the size of a GNU compressed zdebug section. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Don't leak duplicate FDEs.Mark Wielaard2016-01-022-1/+14
| | | | | | | | 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]>
* libdw: Don't use a FDE if it doesn't actually cover a real code range.Mark Wielaard2016-01-022-0/+12
| | | | | | | | | | 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]>
* libdw: Don't leak fake_loc_cu.Mark Wielaard2016-01-022-1/+9
| | | | | | | | 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]>
* Move nested functions in dwarf_entry_breakpoints.c to file scope.Chih-Hung Hsieh2016-01-022-51/+64
| | | | | | No nested functions to compile with clang/llvm. Signed-off-by: Chih-Hung Hsieh <[email protected]>
* Move nested functions in libdw_visit_scopes.c to file scope.Chih-Hung Hsieh2016-01-022-71/+95
| | | | | | | * No nested functions to compile with clang/llvm. Signed-off-by: Chih-Hung Hsieh <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Make sure Ebl is always freed from cfi frame cache.Mark Wielaard2015-11-272-1/+10
| | | | | | | | | | | | | | 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]>
* libdw: initialize state early in read_srclinesDmitry V. Levin2015-11-162-19/+24
| | | | | | | | 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]>
* No nested functions in dwarf_getsrclines.Chih-Hung Hsieh2015-11-132-105/+144
| | | | | | | 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]>
* No nested function in dwarf_getscopevar to file scope.Chih-Hung Hsieh2015-11-132-17/+27
| | | | | Signed-off-by: Chih-Hung Hsieh <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* Make zlib mandatory.Mark Wielaard2015-10-262-1/+5
| | | | | | Explicitly link libelf and libdw with -lz. Signed-off-by: Mark Wielaard <[email protected]>
* Move nested functions in libdw/cfi.c to file scope.Chih-Hung Hsieh2015-10-222-42/+50
| | | | | | * No nested functions to compile with clang/llvm. Signed-off-by: Chih-Hung Hsieh <[email protected]>
* Trust AC_SYS_LARGEFILE to provide large file supportJosh Stone2015-10-092-2/+7
| | | | | | | | | | | | | | | 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]>
* Improve AM_SILENT_RULES coverageJosh Stone2015-10-062-2/+6
| | | | | | | | | | | 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]>
* Use -fPIC instead of -fpic when generating PIC code.Jose E. Marchesi2015-10-062-1/+6
| | | | | | | 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]>
* Properly mark all internal function definitions.Mark Wielaard2015-09-235-0/+11
| | | | | | | | | | | | | | | | | 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]>
* Remove old-style function definitions.Mark Wielaard2015-09-2367-274/+114
| | | | | | | We already require -std=gnu99 and old-style function definitions might hide some compiler warnings. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Don't reassign result pointer in dwarf_peel_type.Mark Wielaard2015-09-152-3/+6
| | | | | | | | | | | | | | 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]>
* Remove redundant NULL tests.Chih-Hung Hsieh2015-09-144-13/+15
| | | | | | | | 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]>
* libdw: Add const declaration to getlocations_addr locs.Chih-Hung Hsieh2015-09-072-11/+11
| | | | | | | | 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]>
* Replace some K&R function definitions with ansi-C definitions.Chih-Hung Hsieh2015-09-073-14/+14
| | | | | Signed-off-by: Chih-Hung Hsieh <[email protected]> Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Add DW_LANG_Haskell.Mark Wielaard2015-08-252-0/+5
| | | | | | | | | 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]>
* libdw: Make sure the default page size is big enough to hold a Dwarf.Mark Wielaard2015-06-192-0/+6
| | | | | | | Just assert early that the page size isn't unreasonable small instead of corrupting memory later. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Not leak memory on error in dwarf_getpubnames.Mark Wielaard2015-06-192-0/+5
| | | | | | | | 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]>
* libdw: Detect dwarf_formudata errors in dwarf_getmacros.Mark Wielaard2015-06-192-2/+10
| | | | | | dwarf_formudata can return an error for bad DWARF. Don't ignore it. Signed-off-by: Mark Wielaard <[email protected]>
* libdw: Initialize dirarray early in read_srclines.Mark Wielaard2015-06-102-10/+14
| | | | | | | 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]>
* libdw: Initialize filelist early in read_srclines.Mark Wielaard2015-06-082-11/+16
| | | | | | | 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]>
* libdw: Fix overflow in read_encoded_value for the DW_EH_PE_indirect case.Mark Wielaard2015-06-012-3/+9
| | | | | | | 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]>
* libdw: Limit stack usage of temporary dir, file and line lists.Mark Wielaard2015-05-272-60/+98
| | | | | | | | | | | | | | | | 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]>
* libdw: Fix possibly unbounded stack usage in __libdw_intern_expression.Mark Wielaard2015-05-272-15/+36
| | | | | | | 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]>
* dwarf_begin_elf: new error for compression failureJonathan Lebon2015-05-134-61/+97
| | | | | | | | | | | 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]>
* dwarf_begin_elf: decouple section searching from readingJonathan Lebon2015-05-132-31/+36
| | | | | | | | | | | 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]>
* libdw: Detect line number overflow in dwarf_getsrclines on 32bit.Mark Wielaard2015-05-122-1/+7
| | | | | | | | | | 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]>
* libdw: dwarf_getaranges check there is enough data before reading.Mark Wielaard2015-05-122-2/+19
| | | | | | https://bugzilla.redhat.com/show_bug.cgi?id=1170810#c30 Signed-off-by: Mark Wielaard <[email protected]>
* Link against standalone argp libraryAnthony G. Basile2015-05-042-1/+6
| | | | | | | | | | | | | | 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]>
* libdw: Undefined behavior in get_sleb128_step.Mark Wielaard2015-04-282-4/+27
| | | | | | | | | | 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]>
* libdw: Don't overflow stack with user defined macro attributes array.Mark Wielaard2015-04-222-4/+31
| | | | | | | | | | | | 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]>
* Do not reject type units in dwarf_getsrcfiles and dwarf_getsrclinesPetr Machata2015-04-035-9/+32
| | | | Signed-off-by: Petr Machata <[email protected]>
* Publish known-dwarf.hPetr Machata2015-03-312-2/+7
| | | | | | | | | | | | | - 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]>
* libdw: Add DWARF5/GCC5 DW_LANG_Fortran03 and DW_LANG_Fortran08 support.Mark Wielaard2015-02-163-0/+10
| | | | | | | | | | | 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]>
* libdw: Add support for DWARF5/GCC5 DW_TAG_atomic_type.Mark Wielaard2015-02-164-2/+13
| | | | | | | | | | | 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]>
* libdw: ensure read_encoded_value's value is setJosh Stone2015-02-112-1/+5
| | | | | | | | | | | | 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]>
* dwarf_ranges: do not request base address attributes if not necessaryPetr Machata2015-02-112-9/+19
| | | | | | | | - 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]>
* libdw: Search for the last matching address with dwarf_getsrc_die.Mark Wielaard2015-01-162-25/+27
| | | | | | | | | | 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]>
* libdw: Robustify eh_frame_hdr and encoded-values reading.Mark Wielaard2015-01-155-23/+104
| | | | | | | | | 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]>
* libdw: Check DW_AT_sibling attribute offset is after current DIE.Mark Wielaard2015-01-152-2/+10
| | | | | | | | | | 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]>
* libdw: Check register number in CFI isn't insanely large.Mark Wielaard2015-01-152-1/+15
| | | | | | | | | | 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]>
* libdw: Add missing size check to parse_eh_frame_hdr.Mark Wielaard2015-01-152-8/+10
| | | | | | | | | | 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]>
* libdw: Handle NULL dbg for call_ref, GNU_implicit_pointer and addr DW_OPs.Mark Wielaard2015-01-152-10/+38
| | | | | | | | | | | | | 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]>