summaryrefslogtreecommitdiff
path: root/libdwfl
Commit message (Collapse)AuthorAgeFilesLines
...
* Improve building with LTOAlexander Miller2021-11-084-6/+13
| | | | | | | | | | | | | | Use symver attribute for symbol versioning instead of .symver assembler directive when available. Convert to use double @ syntax for default version in all cases (required when using the attribute). Add the attributes externally_visible, no_reorder if available when using assembler directives to improve the situation for < gcc-10. This is not 100% reliable, though; -flto-partition=none may still be needed in some cases. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=24498 Signed-off-by: Alexander Miller <alex.miller@gmx.de>
* Remove redundant casts of memory allocating functions returning void *Dmitry V. Levin2021-09-092-1/+6
| | | | | | | Return values of functions returning "void *", e.g. calloc, malloc, realloc, xcalloc, xmalloc, and xrealloc, do not need explicit casts. Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
* libdwfl: fix potential NULL pointer dereference when reading link mapOmar Sandoval2021-06-102-1/+5
| | | | | | | | | | | | When read_addrs() was moved into file scope, there was a mistake in converting "buffer" from a closure variable to a parameter: we are checking whether the pointer argument is NULL, not whether the buffer itself is NULL. This causes a NULL pointer dereference when we try to use the NULL buffer later. Fixes: 3bf41d458fb6 ("link_map: Pull read_addrs() into file scope") Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
* Come up with startswith function.Martin Liska2021-05-126-10/+26
| | | | | | | New function in system.h that returns true if a string has a given prefix, false otherwise. Use it in place of strncmp. Signed-off-by: Martin Liška <mliska@suse.cz>
* libdwfl: use GNU strerror_r only when available.Érico Rolim2021-02-052-1/+20
| | | | | | | | | | Some C libraries don't provide the GNU version of strerror_r, only the XSI-compliant one. We use the GNU version when available, since it fits the code better, and otherwise use the XSI-compliant one. https://sourceware.org/bugzilla/show_bug.cgi?id=21010 Signed-off-by: Érico Rolim <erico.erc@gmail.com>
* elf-from-memory: Refactor to get rid of nested functionTimm Bäder2021-01-282-65/+56
| | | | | | | Try to unify the 32/64 bit code paths and get rid of the nested handle_segment() this way. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* elf-from-memory: Restructure code to get rid of nested handle_segment()Timm Bäder2021-01-282-47/+41
| | | | | | | | Use one loop for both 32 and 64 bit case. This allows for only one call site of the old handle_segment(), which we can then inline into the for loop. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* Consistently define _(Str) using dgettext ("elfutils", Str)Dmitry V. Levin2020-12-163-6/+5
| | | | | | | | | | | | | | Move the definition of _(Str) macro to lib/eu-config.h which already provides a definition of N_(Str) macro. Since lib/eu-config.h is appended to config.h, it is included into every compilation unit and therefore both macros are now universally available. Remove all other definitions of N_(Str) and _(Str) macros from other files to avoid conflicts and redundancies. The next step is to replace all uses of gettext(Str) with _(Str). Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
* libdwfl: fix spelling typos in comments and ChangeLogDmitry V. Levin2020-12-125-11/+18
| | | | | | | | | | | | | | adresses -> addresses boundery -> boundary explictly -> explicitly fo -> for layed -> laid partical -> particular setion -> section substract -> subtract wil -> will Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
* link_map: Pull read_addrs() into file scopeTimm Bäder2020-12-102-47/+62
| | | | | | Get rid of a nested function this way. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* link_map: Pull release_buffer() into file scopeTimm Bäder2020-12-102-16/+37
| | | | | | | Get rid of a nested function this way. Add a memory_closure struct to keep the functions clean. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* libdwfl: switch to DEBUGINFOD_SONAME, remove libdebuginfod.so fallbackDmitry V. Levin2020-12-092-4/+7
| | | | | | | | | | Since DEBUGINFOD_SONAME is as good as ("libdebuginfod-" VERSION ".so") for dlopen, switch to use the name which is a part of the API. Given that DEBUGINFOD_SONAME is always available now, remove the no longer needed fall back to dlopen of "libdebuginfod.so". Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
* link_map: Inline consider_phdr() into only callerTimm Bäder2020-12-062-40/+37
| | | | | | This gets rid of the tested function and is shorter. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Use 64bit GElf_Addr instead of size_t to calculate address.Mark Wielaard2020-11-292-1/+6
| | | | | | size_t is too small on 32 bit systems to analyze a 64 bit core file. Signed-off-by: Mark Wielaard <mark@klomp.org>
* segment_report_module: Inline consider_notes() into only callerTimm Bäder2020-11-282-83/+89
| | | | | | Get rid of a nested function this way. Signed-off-by: Mark Wielaard <mark@klomp.org>
* segment_report_module: Pull read_portion() into file scopeTimm Bäder2020-11-282-30/+46
| | | | Signed-off-by: Mark Wielaard <mark@klomp.org>
* segment_report_module: Pull finish_portion() into file scopeTimm Bäder2020-11-282-10/+35
| | | | | | | Use a read_state struct here to minimize the amount of parameters we pass. Signed-off-by: Mark Wielaard <mark@klomp.org>
* segment_report_module: Inline consider_phdr() into only callerTimm Bäder2020-11-252-71/+69
| | | | | | Get rid of the nested function this way Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* segment_report_module: Inline consider_dyn() into only callerTimm Bäder2020-11-252-28/+17
| | | | Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* segment_report_module: Unify d32/d64 loopsTimm Bäder2020-11-252-14/+21
| | | | | | | Just like we did before, use only one loop here and check for 32/64 bit in the loop body. This way we only have one call site for consider_dyn Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* segment_report_module: Inline read_phdr() into only callerTimm Bäder2020-11-252-17/+15
| | | | | | | There is now only one caller for this nested function, so get rid of it by just inlining it there. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* segment_report_module: Use one loop for p32/p64 arraysTimm Bäder2020-11-252-25/+32
| | | | | | | | Do one loop check for 32/64 bit inside the loop, instead of outside. This way we have only one call site for the function called in the loop body. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* segment_report_module: Get rid of nested final_read() functionTimm Bäder2020-11-252-11/+23
| | | | Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* segment_report_module: Use a struct for build id informationTimm Bäder2020-11-252-23/+36
| | | | | | | Keep the three build id fields in a struct. This will be an important clean up later. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* segment_report_module: Remove nested release_buffer() functionTimm Bäder2020-11-252-10/+11
| | | | Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* segment_report_module: Get rid of segment_read()Timm Bäder2020-11-252-15/+16
| | | | | | Just inline the memory_callback call everywhere segmenty_read was used. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* IBM Z: Fix endianess problem in pid_memory_readAndreas Krebbel2020-11-192-1/+14
| | | | | | | The cached reads lack the big endian adjustments done in the fallback path. Signed-off-by: Andreas Krebbel <krebbel@linux.ibm.com>
* segment_report_module: Remove nested finish() functionTimm Bäder2020-11-192-27/+28
| | | | | | This works just as well with a goto-out style label. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* segment_report_module: Get rid of variable-length arraysTimm Bäder2020-11-192-18/+23
| | | | | | This prevents a jump which is needed in a later patch. Signed-off-by: Timm Bäder <tbaeder@redhat.com>
* libdwfl: Add ZSTD support.Mark Wielaard2020-09-217-2/+110
| | | | | | | | | | | | | | | Newer kernels might be compressed using ZSTD add support to libdwfl open so we can can automatically read ZSTD compressed files and kernel images. The support is very similar to the bzip2 and lzma support, but slightly different. With a bit more macros it could maybe have used the gzip.c USE_INFLATE code path. But I felt that the many macros didn't really help understand the code. So the unzip routine has a slightly different code path for ZSTD. https://sourceware.org/bugzilla/show_bug.cgi?id=26632 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: do not dlopen libdebuginfod.so in --disable-libdebuginfod modeDmitry V. Levin2020-08-316-2/+35
| | | | | | | | | | | debuginfod-client.c used to try to dlopen libdebuginfod.so even if libdebuginfod was completely disabled using --disable-libdebuginfod. Fix this by disabling build of debuginfod-client.c and disabling all __libdwfl_debuginfod_* invocations in --disable-libdebuginfod mode. Signed-off-by: Dmitry V. Levin <ldv@altlinux.org> Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl, src: Replace some asserts with proper check or error messages.Mark Wielaard2020-07-196-8/+32
| | | | | | | | | library code really shouldn't assert and for utilities a proper error message is better than crashing with an assert. https://sourceware.org/bugzilla/show_bug.cgi?id=26176 Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: read_address should use increasing address in intuit_kernel_boundsMark Wielaard2020-06-281-3/+7
| | | | | | | | | | | | | | | | In kernels from 4.14 up to 4.19 in /proc/kallsyms there are special __entry_SYSCALL_64_trampoline symbols. The problem is that they come after the last kernel address, but before the module addresses. And they are (much) smaller than the start address we found. This confuses intuit_kernel_bounds and makes it fail. Make sure to check read_address returns an increasing address when searching for the end. https://sourceware.org/bugzilla/show_bug.cgi?id=26177 Reported-by: Vitaly Chikunov <vt@altlinux.org> Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Flag an error if CIE return_address_register is invalid.Mark Wielaard2020-06-192-1/+10
| | | | | | | If the CIE return address register is invalid (unknown) for the architecture immediately flag an error and return. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: When we find a compressed image, use that, don't search for othersMark Wielaard2020-06-192-1/+6
| | | | | | | | We try to find a compressed vmlinux image ending with either .gz, bz2 or xz. Stop searching if we find one. Otherwise we will leak a file descriptor for an earlier one we opened. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Return failure from dwfl_standard_find_debuginfo for NULL module.Mark Wielaard2020-05-142-0/+8
| | | | | | | | | GCC10 -fanalyzer plus -flto notices that some functions called by dwfl_standard_find_debuginfo check that the given module isn't NULL, but others expect it to be non-NULL. Just return a failure immediately when a NULL mod is passed to dwfl_standard_find_debuginfo. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Cleanup user_core resources on failure in dwfl_core_file_report.Mark Wielaard2020-05-142-1/+22
| | | | | | | | | GCC10 -fanalyzer noticed that we allocate, but don't always cleanup the dwfl->user_core if it wasn't set yet on error. In theory dwfl_module_end should take care of it, but it is cleaner and less confusing to just do it here. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Handle debugaltlink in dwfl_standard_find_debuginfo.Mark Wielaard2020-05-012-2/+26
| | | | | | | | | | | | | | | | When we fall back to the debuginfod client then we need to do the same trick we do for local lookups in dwfl_build_id_find_debuginfo. If the debug file (dw) is already set, then we must be looking for the altfile. But we cannot use the actual file/path name given as hint. We'll have to lookup the alt file "build-id". Because the debuginfod client only handles build-ids. Previously we would use the build-id of the main file which meant the debuginfod client would give us another copy of the debug file, which would then be set as its own altfile. This caused lots of confusion... Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Fix double free on failure path in gzip.c.Mark Wielaard2020-04-262-1/+6
| | | | | | | | | | GCC10 -fanalyzer found a double free when openstream failed. When openstream fails __libdw_gunzip will call fail, which frees the state->buffer. But openstream can call zlib_fail, which will also call fail. Instead of calling zlib_fail, just return the error that zlib_fail would have returned. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Initialize bits to NULL in dwfl_standard_find_debuginfo for LTO.Mark Wielaard2020-04-162-1/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | GCC10 LTO is too smart (and somewhat cryptic): find-debuginfo.c: In function ‘dwfl_standard_find_debuginfo’: debuginfod-client.c:85:8: error: ‘bits’ may be used uninitialized in this function [-Werror=maybe-uninitialized] find-debuginfo.c:360:24: note: ‘bits’ was declared here lto1: all warnings being treated as errors So it inlines __libdwfl_debuginfod_find_debuginfo into dwfl_standard_find_debuginfo and since it cannot see into the function pointer (*fp_debuginfod_find_debuginfo), it assumes that build_id_bit (== bits in dwfl_standard_find_debuginfo) will be used by the called function and it might not be initialized. But if you read the code the there is a check for build_id_len > 0 to see whether bits is or isn't initialized before using bits. But gcc isn't smart enough to figure that out. Maybe that actually should be an heuristic gcc lto should use. If the callchain I am inlining is so deep that I cannot figure out maybe-uninitialized variables anymore I should stop inlining. For now just help GCC out and initialize bits to NULL. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Fix some GCC10 -Wnull-dereference issues.Mark Wielaard2020-02-062-3/+16
| | | | | | | | | GCC10 on some arches will warn about possible NULL derefences. In the libdwfl linux-kernel-modules.c cases it might be caught already by earlier calls to get_release (). But it is hard to see that will really always happen. So do an explicit NULL check just in case. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: remove broken coalescing logic in dwfl_report_segmentOmar Sandoval2019-12-184-43/+26
| | | | | | | | | | | | dwfl_report_segment has some logic that detects when a segment is contiguous with the previously reported segment, in which case it's supposed to coalesce them. However, in this case, it actually returns without updating the segment array at all. As far as I can tell, this has always been broken. It appears that no one uses the coalescing logic anyways, as they pass IDENT as NULL. Let's just get rid of the logic and add a test case. Signed-off-by: Omar Sandoval <osandov@fb.com>
* libdwfl: Find and handle compressed vmlinuz image.Mark Wielaard2019-12-092-0/+28
| | | | | | | | | | | | | | | | | Both the dwfl_linux_kernel_find_elf callback and the dwfl_linux_kernel_report_offline reporting function only handled vmlinix images possibly compressed with .gz, .bz2 or .xz extension. They did not find or handle the much more common vmlinuz compressed images. It is not completely clear why we didn't up to now. Support for compressed ELF files was added in 2009 and the code was updated to to try to find the .gz, .bz2 or .xz extension variants in 2011. But not the vmlinuz named variant. Reported-by: Aaron Merey <amerey@redhat.com> Tested-by: Frank Ch. Eigler <fche@redhat.com> Signed-off-by: Mark Wielaard <mark@klomp.org>
* debuginfod: add client contextMark Wielaard2019-11-236-53/+160
| | | | | | | | | | Add a mandatory debuginfod_begin()/_end() call pair to manage a client object that represents persistent but non-global state. From libdwfl, dlopen the debuginfod.so client library early on. This hopefully makes sure that the code (and the libcurl.so dependency) is loaded before the program goes into multi-threaded mode. Signed-off-by: Mark Wielaard <mark@klomp.org>
* debuginfod 1/2: client sideAaron Merey2019-11-224-5/+67
| | | | | | | | | | | | Introduce the debuginfod/ subdirectory, containing the client for a new debuginfo-over-http service, in shared-library and command-line forms. Two functions in libdwfl make calls into the client library to fetch elf/dwarf files by buildid, as a fallback. Instead of normal dynamic linking (thus pulling in a variety of curl dependencies), the libdwfl hooks use dlopen/dlsym. Server & tests coming in patch 2. Signed-off-by: Aaron Merey <amerey@redhat.com> Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
* libdwfl: only use thread->unwound for initial frameOmar Sandoval2019-10-293-31/+25
| | | | | | | | | | | thread->unwound is only used for set_initial_registers (via dwfl_thread_state_registers, dwfl_thread_state_register_pc, and a special case in core_set_initial_registers). At that point, thread->unwound is always the initial frame, so there's no need to update it as we unwind the stack. Let's set it to NULL after we do the initial setup. This simplifies the next change. Signed-off-by: Omar Sandoval <osandov@fb.com>
* libdwfl: don't bother freeing frames outside of dwfl_thread_getframesOmar Sandoval2019-10-292-15/+9
| | | | | | | | | dwfl_thread_getframes always frees the state before returning, so dwfl_getthreads and getthread don't need to do it. The only place we allocate the state is from dwfl_thread_getframes and we always free it before returning from that function. Signed-off-by: Omar Sandoval <osandov@fb.com>
* libdwelf: Make dwelf_elf_begin return NULL only when there is an error.Mark Wielaard2019-08-133-5/+18
| | | | | | | | | | | | | | | | | | | | | | | dwelf_elf_begin was slightly different from elf_begin in case the file turned out to not be an ELF file. elf_begin would return an Elf handle with ELF_K_NONE. But dwelf_elf_begin would return NULL. This made it impossible to tell the difference between a file or decompression error and a (decompressed) file not being an ELF file. Since dwelf_elf_begin could still return different kinds of ELF files (ELF_K_ELF or ELF_K_AR - and theoretically ELF_K_COFF) this was not really useful anyway. So make it so that dwelf_elf_begin always returns an Elf handle unless there was a real error reading or decompressing the file. Otherwise return NULL to make clear there was a real error. Make sure that the decompression function returns DWFL_E_BADELF only when the file isn't compressed. In which case the Elf handle won't be replaced and can be returned (as ELF_K_NONE). Add a new version to dwelf_elf_begin so programs can rely on it returning NULL only for real errors. Signed-off-by: Mark Wielaard <mark@klomp.org>
* libdwfl: Fix fd leak/closing wrong fd after dwfl_core_file_report()Omar Sandoval2019-08-092-0/+6
| | | | | | | | | | | | | | dwfl_segment_report_module() (used only by dwfl_core_file_report()) opens a file descriptor and/or an Elf handle, reports a module, and assigns mod->main.elf. However, it doesn't assign mod->main.fd, so it is left as 0. This causes two problems: 1. We leak the file descriptor for the module. 2. When we free the module, we close file descriptor 0 (stdin). Fix it by assigning mod->main.fd. Signed-off-by: Omar Sandoval <osandov@fb.com>
* libdwfl: Make sure to left shift a unsigned 64bit value in expr_eval.Mark Wielaard2019-04-282-1/+6
| | | | | | | | In frame_unwind.c expr_eval we left shift 1 up to 56 bits. We have to make sure we don't left shift a 32bit signed value (that would be undefined behavior). So shift a 1ULL value instead. Signed-off-by: Mark Wielaard <mark@klomp.org>