summaryrefslogtreecommitdiffstats
path: root/libdwfl
Commit message (Collapse)AuthorAgeFilesLines
* Merge tag 'elfutils-0.169'QtCreator4.5.1QtCreator4.5.0-rc1QtCreator4.5.0QtCreator4.4.1QtCreator4.4.0-rc1QtCreator4.4.0-beta1QtCreator4.4.04.54.4Ulf Hermann2017-05-083-21/+27
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: ChangeLog backends/ChangeLog config/ChangeLog lib/ChangeLog libasm/ChangeLog libcpu/ChangeLog libdw/ChangeLog libdwfl/ChangeLog libdwfl/derelocate.c libdwfl/linux-kernel-modules.c libebl/ChangeLog libelf/ChangeLog src/ChangeLog tests/ChangeLog Change-Id: I3b7ced947c6498290aaae27443985b84531f0bcd
| * Make elf section sorting more deterministicUlf Hermann2017-05-032-1/+13
| | | | | | | | | | | | | | | | | | At least one test (dwfl-addr-sect) depends on the order of elf sections with equal addresses. This is not guaranteed by the code. Compare also by end address and section index to tell entries apart. Signed-off-by: Ulf Hermann <ulf.hermann@qt.io> Signed-off-by: Mark Wielaard <mark@klomp.org>
| * Don't look for kernel version if not running on linuxUlf Hermann2017-05-022-0/+13
| | | | | | | | | | | | | | We don't want to use it, even if it exists. Signed-off-by: Ulf Hermann <ulf.hermann@qt.io> Signed-off-by: Mark Wielaard <mark@klomp.org>
| * Avoid double-including config.hUlf Hermann2017-05-0257-3/+278
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | config.h doesn't have include guards, so including it twice is bad. We deal with this by checking for PACKAGE_NAME, but only in some places. Once we start using gnulib, we will need to include config.h before any gnulib-generated headers. This is problematic if we include it transitively through our own private headers. In order to set a clear rule about inclusion of config.h, it is now included in every .c file as first header, but not in any header. This will definitely avoid double-inclusion and satisfy the condition that it has to be included before gnulib headers. It comes at the price of adding some redundancy, but there is no clean way to avoid this. Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
| * Make __attribute__ conditional in all installed headersUlf Hermann2017-05-022-1/+5
| | | | | | | | | | | | | | | | | | | | __attribute__ is a GNU extension. If we want to link against the libraries using a different compiler, it needs to be disabled. It was already disabled in libdw.h, and this patch extends this to the other headers. We move the defines to libelf.h as that is included in all the others. Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
| * Avoid signed/unsigned comparisonUlf Hermann2017-04-272-1/+5
| | | | | | | | | | | | | | | | | | | | | | Some compilers implicitly cast the result of uint_fast16_t * uint_fast16_t to something signed and then complain about the comparison to (unsigned) size_t. Casting phnum to size_t is a good idea anyway as 16bit multiplication can easily overflow and we are not checking for this. Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
| * Protect against integer overflow on shnumUlf Hermann2017-04-272-8/+15
| | | | | | | | | | | | | | If shnum is 0, the many "shnum - 1" would result in an overflow. Check it for 0, and only subtract once, rather than on every usage. Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
| * Clean up linux-specific system includesUlf Hermann2017-04-264-4/+10
| | | | | | | | | | | | We only include them where we actually need them and only on linux. Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
| * Include sys/types.h before fts.hUlf Hermann2017-04-252-1/+9
| | | | | | | | | | | | | | The bad fts not only needs to be included before config.h, but also requires various special types without including sys/types.h. Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
* | Adapt debug info fstat check for windowsUlf Hermann2017-05-082-0/+14
| | | | | | | | | | | | | | | | | | | | | | On windows the resulting ino and dev entries are always 0, so the file would always be discarded. We apply a heuristic instead: If the ctime, mtime, mode and size of the two files are all equal then we consider them to be the same. It's exceedingly unlikely to produce two different files for which that holds by chance. Change-Id: I491c95ab8b90fc3c1b786cceae242e142b5a491f Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
* | Use OS-specific pathsUlf Hermann2017-05-086-55/+75
| | | | | | | | | | | | | | | | | | | | In general we need to use ';' as path separator and '\' and directory separator on windows. The shell will automatically translate paths to some extent, but we have to call "pwd -W" rather than plain "pwd" to get something useful. Change-Id: I1a117d219a2aa00c1f77ae7d3a1d92b9bae526db Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
* | Open files in O_BINARYUlf Hermann2017-05-0812-28/+43
| | | | | | | | | | | | | | | | | | If O_BINARY is not defined, define it to 0, so that the change has no effect then. Some systems have separate binary and text modes for files, and we don't want the text mode to be used. Change-Id: If7efb5bd448c2a1c7d1eb5dab276849b1b15a3ce Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
* | Check for existence of GNU-style strerror_rUlf Hermann2017-05-052-0/+9
| | | | | | | | | | | | | | | | If we don't have it, we don't translate system error codes to strings in dwfl_error.c. Change-Id: I829616cfba787d778c3273f2042512739df91d81 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
* | Drop handrolled or #ifdef'ed libc replacementsUlf Hermann2017-04-282-1/+4
| | | | | | | | | | | | | | | | | | mempcpy, memrchr, rawmemchr, and argp are provided by gnulib now. We don't need to define them locally and we don't need to search for an external libargp. Change-Id: I131ca4bc2d77c597b99c296c28259a3600e5d1b5 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
* | Make elf section sorting more deterministicUlf Hermann2017-04-262-6/+16
| | | | | | | | | | | | | | | | | | At least one test (dwfl-addr-sect) depends on the order of elf sections with equal addresses. This is not guaranteed by the code. Compare also by end address and name to tell entries apart. Change-Id: I0e85e7b86a0489b6bc85f45f9a359c68a04f635a Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
* | Avoid signed/unsigned comparisonUlf Hermann2017-04-262-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | Some compilers implicitly cast the result of uint_fast16_t * uint_fast16_t to something signed and then complain about the comparison to (unsigned) size_t. Casting phnum to size_t is a good idea anyway as 16bit multiplication can easily overflow and we are not checking for this. Change-Id: I073202d433d75b540ca042d15c364187a08fec6c Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
* | Avoid double-including config.hUlf Hermann2017-04-2657-3/+278
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | config.h doesn't have include guards, so including it twice is bad. We deal with this by checking for PACKAGE_NAME, but only in some places. Once we start using gnulib, we will need to include config.h before any gnulib-generated headers. This is problematic if we include it transitively through our own private headers. In order to set a clear rule about inclusion of config.h, it is now included in every .c file as first header, but not in any header. This will definitely avoid double-inclusion and satisfy the condition that it has to be included before gnulib headers. It comes at the price of adding some redundancy, but there is no clean way to avoid this. Change-Id: Ib78dd7e058ef8ac93cd379dcd14a2ffbc86c1988 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
* | Don't look for kernel version if not running on linuxUlf Hermann2017-04-262-0/+9
| | | | | | | | | | Change-Id: Ia74c04e2590d2d918fb7d5227a106de789551843 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
* | Protect against integer overflow on shnumUlf Hermann2017-04-262-8/+15
| | | | | | | | | | | | | | | | If shnum is 0, the many "shnum - 1" would result in an overflow. Check it for 0, and only subtract once, rather than on every usage. Change-Id: I37a9e5d4e012a501d5ec98762ec0a435c743e25f Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
* | Make __attribute__ conditional in all installed headersUlf Hermann2017-04-212-1/+5
| | | | | | | | | | | | | | | | | | | | | | __attribute__ is a GNU extension. If we want to link against the libraries using a different compiler, it needs to be disabled. It was already disabled in libdw.h, and this patch extends this to the other headers. We move the defines to libelf.h as that is included in all the others. Change-Id: I6e22674641f19f5a8820e2c7c7ec46f2fd70a8af Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
* | Clean up linux-specific system includesUlf Hermann2017-04-214-4/+10
| | | | | | | | | | | | | | We only include them where we actually need them and only on linux. Change-Id: Ic3065ffab67ba1177f63204fb91a92c5f4336dbb Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
* | Include sys/types.h before fts.hUlf Hermann2017-04-212-1/+9
|/ | | | | | | | The bad fts not only needs to be included before config.h, but also requires various special types without including sys/types.h. Change-Id: I31ac8d2aadcf7ffb3efb63583b2745991bfd6f90 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
* Use the empty string for note names with zero size (without any data).Mark Wielaard2017-04-032-3/+12
| | | | | | | | | | ELF notes can have a zero sized name. In which case there is no data at all (so also no zero terminator). Make sure to use the empty string for such notes if the code does not otherwise explicitly check n_namesz. https://sourceware.org/bugzilla/show_bug.cgi?id=21300 Signed-off-by: Mark Wielaard <mark@klomp.org>
* Check for existence of mempcpyUlf Hermann2017-02-172-0/+5
| | | | | | If it doesn't exist, provide a definition based on memcpy. Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
* Always use the same method to query the system page sizeUlf Hermann2017-02-153-2/+7
| | | | | | | This makes it easier to write a replacement for it on systems where sysconf(3) doesn't exist. Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
* Fix TEMP_FAILURE_RETRY definition when not defined.Luiz Angelo Daros de Luca2016-12-304-1/+8
| | | | | | https://sourceware.org/bugzilla/show_bug.cgi?id=21001 Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
* Only workaround fts.h if we have a bad version that doesn't handle LFS.Mark Wielaard2016-11-232-8/+19
| | | | | | | | | | Older versions of glibc included an fts implementation that didn't have Large File System support. We worked around that in linux-kernel-modules.c by including it early before config.h and then redefining some symbols to get the 64-bit versions. This is somewhat fragile and not necessary with newer glibc. If possible we want the 64bit fts version always. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* Add GCC7 -Wimplicit-fallthrough support/fixes.Mark Wielaard2016-11-101-1/+1
| | | | | | | | | | | GCC7 will have a new -Wimplicit-fallthrough warning. It did catch one small buglet in elflint option procession. So it seems useful to enable to make sure all swatch case fallthroughs are deliberate. Add configure check to detect whether gcc support -Wimplicit-fallthrough and enable it. Add fixes and explicit fallthrough comments where necessary. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* lib: Provide MAX and MIN in system.hAkihiko Odaki2016-10-126-18/+13
| | | | | | | | | | This change also creates a new header file libeu.h to provide the prototypes for the function of libeu. That hides the definition of function crc32, which can conflict with zlib, from libelf. It also prevents mistakes to refer those functions from a component which doesn't link with libeu, such as libelf. Signed-off-by: Akihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp>
* libdwfl: Fix assert and set in.d_size in dwfl_link_map_report.Mark Wielaard2016-08-152-2/+9
| | | | | | | | | | | | When reading the phdrs from a core file segment fails we would try to read them from the exec. This fallback path contained a faulty assert that the requested size of the phdrs was still setup. But the core file reading callback might have reset the d_size value to zero on error. So explicitly set the number of bytes we want to read again instead of asserting the size. https://bugzilla.redhat.com/show_bug.cgi?id=1365812 Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdwfl: Fix memory leak in dwfl_module_getsrc_file on invalid DWARF.Mark Wielaard2016-04-142-0/+7
| | | | | | | If we allocated the match results array ourselves, then free it when we detect invalid DWARF and return an error. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdwfl: Fix memory leak in proc_maps_report on bad file mapping.Mark Wielaard2016-04-142-1/+9
| | | | | | | Normally last_file is freed inside report(), but in the case of a bad file mapping we don't call report. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdwfl: clean up non-Linux GNU platforms codeSteven Chamberlain2016-03-022-63/+7
| | | | | | | | | | | | | | | | | | | For non-Linux GNU platforms (like kFreeBSD, Hurd), linux-pid-attach.c had some stub functions that are not used or exported. Since gcc-6, having these caused compiler errors due to -Wall -Werror: linux-pid-attach.c:479:36: error: 'pid_thread_callbacks' defined but not used [-Werror=unused-const-variable=] linux-pid-attach.c:474:1: error: 'pid_thread_detach' defined but not used [-Werror=unused-function] linux-pid-attach.c:461:1: error: 'pid_detach' defined but not used [-Werror=unused-function] linux-pid-attach.c:452:1: error: 'pid_set_initial_registers' defined but not used [-Werror=unused-function] linux-pid-attach.c:441:1: error: 'pid_memory_read' defined but not used [-Werror=unused-function] linux-pid-attach.c:420:1: error: 'pid_getthread' defined but not used [-Werror=unused-function] linux-pid-attach.c:410:1: error: 'pid_next_thread' defined but not used [-Werror=unused-function] This part of the source file is guarded by #ifndef __linux__ Signed-off-by: Steven Chamberlain <steven@pyro.eu.org>
* libdwfl: Check for kernel debuginfo file without .debug extension as wellRavi Bangoria2016-02-223-9/+36
| | | | | | | | | | | | | | | | | | | | | Elfutils, looking for kernel debuginfo file, tries to find it at various places. If elfutils finds /boot/vmlinu*x* file, it checks for debufginfo section. If debuginfo is not present, it saves it as 'main elf' and continue looking for debuginfo file having .debug extension i.e. vmlinux-RELEASE.debug. 'Ubuntu on powerpc' installs kernel as /boot/vmlinux and installs debuginfo without any extension as /usr/lib/debug/boot/vmlinux-RELEASE and hence, elfutils is not able to find the debuginfo file. Here is the launchpad bug for the same: https://bugs.launchpad.net/ubuntu/+source/systemtap/+bug/1537125 This patch adds functionality to search for a kernel or debuginfo file both with and without .debug extension. Signed-off-by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com> Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdwfl: Don't leak memory in proc_maps_report when ENOEXEC.Mark Wielaard2016-02-222-1/+6
| | | | | | We forgot to free last_file on error. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdwfl: Don't crash on out of memory when frame unwinding.Mark Wielaard2016-02-222-5/+24
| | | | | | | new_unwound didn't check whether malloc was successful. Check that we could allocate memory before use and return DWFL_E_NOMEM otherwise. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdwfl: Check result of gelf_get* calls in relocate.cMark Wielaard2016-02-182-6/+26
| | | | | | | | For corrupted ELF files gelf_get calls might fail in which case it is better to immediately return an error instead of using the NULL result and crashing. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdwfl: Check result of gelf_update_* calls in relocate_section.Mark Wielaard2016-02-182-6/+16
| | | | | | | | For corrupted ELF files the gelf_update calls might fail in which case it is better to immediately return an error message instead of (silently) continuing. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* Simplify code and build now that zlib support is no longer optional.Mark Wielaard2016-01-084-20/+13
| | | | | | | Now that we always require zlib support we don't need to conditionally build or compile code that depends on it. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdwfl: Use elf_compress[_gnu] to decompress string, symbol and reloc data.Mark Wielaard2016-01-063-31/+194
| | | | | | | | | This makes usage of the libdwfl symbol functions work out of the box even when some sections (string, symbol or xndx) are compressed. For ET_REL files this makes relocations just work by making sure the target section is decompressed first before relocations are applied. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* Move nested functions in linux-proc-maps.c to file scope.Chih-Hung Hsieh2016-01-032-14/+22
| | | | | | * Move nested function 'report' to file scope to compile with clang. Signed-off-by: Chih-Hung Hsieh <chh@google.com>
* Move nested functions in core-file.c to file scope.Chih-Hung Hsieh2016-01-032-42/+59
| | | | | | * Move nested functions 'fail', 'update_end', and 'more' to file scope. Signed-off-by: Chih-Hung Hsieh <chh@google.com>
* Move nested functions check64 and check32 in link_map.c to file scope.Chih-Hung Hsieh2016-01-032-47/+58
| | | | | | | | * In libdwfl/link_map.c, nested functions check64, check32, are moved to file scope to compile with clang. Signed-off-by: Chih-Hung Hsieh <chh@google.com> Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdwfl: make the unwinder aware of the backend defined ra_offset.Jose E. Marchesi2016-01-033-2/+16
| | | | | | | | | Ebl backends can define an offset that must be applied to the value of the "return address register" defined in the CFI ABI information. This patch makes the unwinder to use that offset when reading the RA CFI register. Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
* libdwfl: Fix memory leak in link_map.c dwfl_link_map_report.Mark Wielaard2016-01-022-2/+12
| | | | | | | | The phdrs buffer could come from the core file or through the executable. dwfl_link_map_report would leak the buffer if it came from the executable. Track where the buffer came from and free appropriately. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* libdwfl: Don't leak core Elf and core file descriptor from argp-std.Mark Wielaard2016-01-027-17/+82
| | | | | | | | Our argp helper would leak the core Elf and core file descriptor when given by the user. Store both in the Dwfl as a new Dwfl_User_Core so they get cleaned up by dwfl_end. Signed-off-by: Mark Wielaard <mjw@redhat.com>
* Move nested functions in dwfl_module_getdwarf.c to file scope.Chih-Hung Hsieh2016-01-022-148/+165
| | | | | | | | * In dwfl_module_getdwarf.c, nested functions 'consider_shdr' and 'translate_offs' are moved to file scope to compile with clang. Signed-off-by: Chih-Hung Hsieh <chh@google.com> Signed-off-by: Mark Wielaard <mjw@redhat.com>
* Move nested functions in dwfl_module_addrsym.c to file scope.Chih-Hung Hsieh2016-01-022-148/+193
| | | | | | | * Move nested functions 'same_section', 'binding_value', 'try_sym_value', and 'search_table'. Signed-off-by: Chih-Hung Hsieh <chh@google.com>
* libdw: Make sure Ebl is always freed from cfi frame cache.Mark Wielaard2015-11-272-4/+25
| | | | | | | | | | | | | | 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 <mjw@redhat.com>
* Move nested functions in gzip.c to file scope.Chih-Hung Hsieh2015-11-132-120/+153
| | | | | | | | * libdwfl/gzip.c should now compile with clang. All local variables used by nested functions are passed in an unzip_state structure. Signed-off-by: Chih-Hung Hsieh <chh@google.com>