Mark Wielaard [Tue, 22 Sep 2015 12:20:45 +0000 (14:20 +0200)]
Update dl-hash.h from glibc.
Our dl-hash.h implementation originally came from, or was written at the
same time as, the glibc implementation. At some point (around 9 years ago)
they diverged and the elfutils version got an updated copyright header.
The glibc version saw various updates/optimizations. Just treat the file
like we do for elf.h and copy it whenever the glibc version is updated.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 15 Sep 2015 08:55:10 +0000 (10:55 +0200)]
libdw: Don't reassign result pointer in dwarf_peel_type.
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 <mjw@redhat.com>
Chih-Hung Hsieh [Wed, 9 Sep 2015 19:32:07 +0000 (12:32 -0700)]
Remove redundant NULL tests.
GCC6 and Clang give warnings on redundant NULL tests of parameters
that are declared with __nonnull_attribute__.
Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 7 Sep 2015 10:52:12 +0000 (12:52 +0200)]
libdwfl: Make dwfl_linux_proc_attach work even without any Dwfl_Modules.
dwfl_linux_proc_attach depended on a Dwfl_Module with the correct
ELF header already being available. That isn't really necessary since
when we attach we have the main exe ELF file available. Just use that
to make dwfl_linux_proc_attach always work.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Chih-Hung Hsieh [Wed, 9 Sep 2015 20:59:19 +0000 (13:59 -0700)]
Initialize variable before use.
Some compiler does not know that error function never returns.
Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Chih-Hung Hsieh [Fri, 4 Sep 2015 19:04:11 +0000 (12:04 -0700)]
libdwfl: Replace abs with llabs for int64_t values.
Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Chih-Hung Hsieh [Fri, 4 Sep 2015 19:04:11 +0000 (12:04 -0700)]
tests: Init local variable enctype before use in print_base_type varlocs.c.
clang compiler static analysis failed.
Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Chih-Hung Hsieh [Fri, 4 Sep 2015 19:04:11 +0000 (12:04 -0700)]
tests: Remove unused static const variables in md5-sha1-test.c.
Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Chih-Hung Hsieh [Fri, 4 Sep 2015 19:04:11 +0000 (12:04 -0700)]
libdw: Add const declaration to getlocations_addr locs.
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 <chh@google.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Chih-Hung Hsieh [Fri, 4 Sep 2015 19:04:11 +0000 (12:04 -0700)]
Replace some K&R function definitions with ansi-C definitions.
Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Chih-Hung Hsieh [Fri, 4 Sep 2015 17:13:02 +0000 (10:13 -0700)]
Replace printf %Z length modifier with %z.
%Z is a GNU extension predating the ISO C99 %z modifier supported by
libc5 and no longer recommended.
Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 3 Sep 2015 10:50:54 +0000 (12:50 +0200)]
backends: Use ebl->class consistently in sparc backend.
sparc_init would check the ELF class to register to correct core_note
handler. But sparc_register_info would check the ELF machine to determine
whether the register set was 32 or 64 bits. This caused some confusion
and assertion failures in readelf when printing core notes where the
sparc machine and class didn't seem to match up. Check the ELF class
in both sparc_unit and sparc_register_info to give consistent results.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 3 Sep 2015 08:50:58 +0000 (10:50 +0200)]
readelf: handle_core_item large right shift triggers undefined behaviour.
The problem is this:
int n = ffs (w);
w >>= n;
The intent is to shift away up to (and including) the first least
significant bit in w. But w is an unsigned int, so 32 bits. And the
least significant bit could be bit 32 (ffs counts from 1). Unfortunately
a right shift equal to (or larger than) the length in bits of the left
hand operand is undefined behaviour. We expect w to be zero afterwards.
Which would terminate the while loop in the function. But since it is
undefined behaviour anything can happen. In this case, what will actually
happen is that w is unchanged, causing an infinite loop...
gcc -fsanitize=undefined will catch and warn about this when w = 0x80000000
https://bugzilla.redhat.com/show_bug.cgi?id=1259259
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 25 Aug 2015 13:11:01 +0000 (15:11 +0200)]
libdw: Add DW_LANG_Haskell.
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 <mjw@redhat.com>
Mark Wielaard [Tue, 11 Aug 2015 22:11:26 +0000 (00:11 +0200)]
elflint: Add gnuld check when a NOBITS section falls inside a segment.
gnuld has a really bad bug where it can place a NOBITS section inside
a PT_LOAD segment. Normally that would not work. But it also makes sure
that the contents of the file is all zeros. So in practice it is actually
a PROGBITS section with all zero data. Except that other tools will think
there is an unused gap in the ELF file after the NOBITS section.
Recognize and check this pattern in elflint when --gnu is given.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 14 Aug 2015 13:50:12 +0000 (15:50 +0200)]
tests: Add a testcase for dwfl debuginfo-path with separate bin/debug dirs.
Reuse the run-addr2line-i-test.sh testfile-inlines testfile, but
first strip the debuginfo and put the binary and separate debuginfo
file in different roots. Check that --debuginfo-path still finds
the debug file.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Dodji Seketeli [Thu, 13 Aug 2015 13:59:41 +0000 (15:59 +0200)]
Fix finding split debug info files not located by the build-id mechanism
[This bug has been found by using elfutils in the context of
libabigail. The initial bug report is
https://sourceware.org/bugzilla/show_bug.cgi?id=18792. The
interesting comments start at is
https://sourceware.org/bugzilla/show_bug.cgi?id=18792#c4]
suppose we have a debug info file that is located at a
/prefix1/usr/lib/debug/prefix2/libfoo.so. Suppose also that the debug
info describes a binary that is located at /prefix1/prefix2/libfoo.so
Suppose the debug_link property inside the binary
/prefix1/prefix2/libfoo.so correctly contains the string "libfoo.so"
that designates the name of the debug info file.
The problem is, when find_debuginfo_in_path() is called with its
file_name parameter set to "/prefix1/prefix2/libfoo.so" and
mod->dwfl->callbacks->debuginfo_path set to
"/prefix1/lib/debug/", it fails to locate the debug
info file libfoo.so under "/prefix1/usr/lib/debug/prefix2/".
This patch fixes the issue by making find_debuginfo_in_path() try all
the sub-strings of "/prefix1/prefix2/libfoo.so "under"
"/prefix1/usr/lib/debug/", to find libfoo.so. That is, it tries, in
order:
- /prefix1/usr/lib/debug/prefix1/prefix2/libfoo.so
- /prefix1/usr/lib/debug/prefix2/libfoo.so <-- and boom, it finds it!
Note that the patch tries the variations between the two candidates
above too.
The patch uses a goto. I dislike gotos like anyone else, but then
here, not using this would imply a bigger change of the logic of that
function. So I am proposing the scheme based on the goto instead.
* libdwfl/find-debuginfo.c (find_debuginfo_in_path): Try to locate
the debug info file named debuglink_file under
mod->dwfl->callbacks->debuginfo_path, by looking at the set of
sub-trees under mod->dwfl->callbacks->debuginfo_path which is
common to the set of non-absolute parent trees of file_name.
https://bugzilla.redhat.com/show_bug.cgi?id=1253367
Signed-off-by: Dodji Seketeli <dodji@seketeli.org>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 4 Aug 2015 10:20:20 +0000 (12:20 +0200)]
spec: Provide default-yama-scope.
When yama is enabled in the kernel it might be used to filter any user
space access which requires PTRACE_MODE_ATTACH like ptrace attach, access
to /proc/PID/{mem,personality,stack,syscall}, and the syscalls
process_vm_readv and process_vm_writev which are used for interprocess
services, communication and introspection (like synchronisation, signaling,
debugging, tracing and profiling) of processes.
These are precisely the things that libdw dwfl and ebl backends rely on.
So make sure they don't mysteriously fail in such cases by providing the
default yama scope sysctl value.
This is implemented as a separate subpackage that just provides this
functionality so other packages that don't directly rely on elfutils-libs
can also just Requires: default-yama-scope to function properly.
https://bugzilla.redhat.com/show_bug.cgi?id=1209492#c69
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 29 Jul 2015 15:51:27 +0000 (17:51 +0200)]
unstrip: Handle debuginfo files with missing SHF_INFO_LINK section flags.
With GCC 5 there might be a .rela.plt section with SHF_INFO_LINK set.
Buggy binutils objdump might strip it from the section in the debug file.
Ignore such differences for relocation sections and put the flag back
if necessary.
Also improve the error message a little by only discarding the already
matched sections if there is an prelink undo section. Otherwise we will
report all sections as not matching if the file wasn't prelinked instead
of just the non-matching sections.
New testfiles generated by gcc5 and binutils objdump added.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mike Frysinger [Wed, 29 Jul 2015 14:36:02 +0000 (10:36 -0400)]
ignore more generated files
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Pino Toscano [Sat, 11 Jul 2015 07:55:40 +0000 (09:55 +0200)]
Fix/improve .gitignore
Fill the .gitignore with more generated files, such as:
- test executables
- results of the automake testing framework (*.log and *.trs)
- sources generated by flex and bison
- generated *.mnemonics files in libcpu
- the helper libcpu/i386_gendis tool
- *.so.1 symlinks
Also, anchor existing filenames to their location when
builddir==srcdir.
Signed-off-by: Pino Toscano <toscano.pino@tiscali.it>
Pino Toscano [Sat, 27 Jun 2015 17:23:01 +0000 (19:23 +0200)]
tests: skip run-deleted.sh when dwfl_linux_proc_attach is not implemented
If the current OS does not implement dwfl_linux_proc_attach (which
currently only Linux does) then skip this test, as "stack" uses that
API for attaching to a running process.
Signed-off-by: Pino Toscano <toscano.pino@tiscali.it>
Pino Toscano [Sat, 27 Jun 2015 16:33:37 +0000 (18:33 +0200)]
tests: dwfl-bug-fd-leak: Guard against null module addresses
Do not crash if there is no module for the given address.
Signed-off-by: Pino Toscano <toscano.pino@tiscali.it>
Pino Toscano [Sat, 27 Jun 2015 16:07:01 +0000 (18:07 +0200)]
strings: Define MAP_POPULATE if not defined already
Currently it is available on Linux only, and it is more an hint.
Signed-off-by: Pino Toscano <toscano.pino@tiscali.it>
Mark Wielaard [Sat, 27 Jun 2015 20:07:01 +0000 (22:07 +0200)]
nm: First call elf_getdata, then allocate memory.
This catches bogus data early before we might try to allocate giant
amounts of memory.
Reported-by: Hanno Böck <hanno@hboeck.de>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Pino Toscano [Fri, 26 Jun 2015 18:38:31 +0000 (20:38 +0200)]
tests: Mark an unused argument as such
Signed-off-by: Pino Toscano <toscano.pino@tiscali.it>
Pino Toscano [Fri, 26 Jun 2015 18:36:01 +0000 (20:36 +0200)]
Reduce scope of some includes
Use some includes only according to the #ifdef block of the respective
code, or matching the fact they are Linux-only. This way, includes
potentially unportable are not unconditionally used.
Signed-off-by: Pino Toscano <toscano.pino@tiscali.it>
Mark Wielaard [Fri, 19 Jun 2015 11:43:58 +0000 (13:43 +0200)]
Prepare 0.163 release.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 21:43:39 +0000 (23:43 +0200)]
findtextrel: Don't leak memory in process_file.
When a files do contain textrels we fail to release the segments searched
and valgrind will show:
2,560 bytes in 16 blocks are definitely lost in loss record 1 of 1
at 0x40281B5: malloc (in vgpreload_memcheck-x86-linux.so)
by 0x804AE63: process_file (findtextrel.c:322)
by 0x804909B: main (findtextrel.c:149)
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 18:24:39 +0000 (20:24 +0200)]
readelf: Make sure phdr2_mem lifetime/scope equals phdr2 pointer.
We dont' want GCC to dispose or reuse phdr2_mem stack memory while phdr2
is pointing to it.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 14:17:40 +0000 (16:17 +0200)]
libdwfl: Don't leak fname if file is main file by another name in try_open.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 08:57:53 +0000 (10:57 +0200)]
readelf: Don't leak memory on failure path in handle_gnu_hash.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 08:50:19 +0000 (10:50 +0200)]
libelf: Don't leak memory on failure paths in elf_updatefile.
When something goes wrong during the update make sure to always free any
temporary allocated memory (shdr_data and/or scns).
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 10:50:47 +0000 (12:50 +0200)]
elflint: Only check the PT_TLS phdr if it actually exists, warn otherwise.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 09:50:50 +0000 (11:50 +0200)]
libdw: Make sure the default page size is big enough to hold a Dwarf.
Just assert early that the page size isn't unreasonable small instead of
corrupting memory later.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 09:07:41 +0000 (11:07 +0200)]
nm: Fix typo in size check to determine whether we stack allocated memory.
We allocate GElf_SymX entries, which are larger than plain GElf_Sym structs.
The check to see whether we could use stack allocation used the correct
sizeof (GElf_SymX), but the check to see if we needed to free was using
the incorrect sizeof (GElf_Sym). Which could cause us to leak memory.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 09:00:51 +0000 (11:00 +0200)]
strings: Handle failure of getting section name on bogus section data.
If there is something wrong with getting the section data it is likely
we won't be able to get the actual section name because the file is
somehow corrupted. Try to get the name, but handle failure gracefully.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 08:54:29 +0000 (10:54 +0200)]
libelf: Check symbol section header exists before use in nlist.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 08:46:20 +0000 (10:46 +0200)]
libdwfl: Check symbol section exists and has a sane entsize in find_symtab.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 08:41:42 +0000 (10:41 +0200)]
libdw: Not leak memory on error in dwarf_getpubnames.
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 <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 08:38:12 +0000 (10:38 +0200)]
libdw: Detect dwarf_formudata errors in dwarf_getmacros.
dwarf_formudata can return an error for bad DWARF. Don't ignore it.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 16 Jun 2015 12:05:35 +0000 (14:05 +0200)]
libelf: Always call ftruncate before posix_fallocate to set the right size.
When elf_update.c (write_file) doesn't know the current maximum file length
it might have to reduce the file size. posix_fallocate can only extend the
file. So always call ftruncate before that to set the file size and making
sure the backing store is fully there. Add test cases for checking strip
in place (eu-strip without -o) actually reduces the file size. But only
for non-ET_REL files. We might not be able to strip ET_REL files (except
when they are kernel modules) because they might contain "dangling" symbol
table entries.
https://bugzilla.redhat.com/show_bug.cgi?id=1232206
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 14 Jun 2015 22:06:27 +0000 (00:06 +0200)]
po/*.po: Regenerate.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Piotr Drąg [Sat, 13 Jun 2015 13:34:53 +0000 (15:34 +0200)]
Updated Polish translation
Signed-off-by: Piotr Drąg <piotrdrag@gmail.com>
Piotr Drąg [Sat, 13 Jun 2015 11:16:13 +0000 (13:16 +0200)]
Updated POTFILES.in
Signed-off-by: Piotr Drąg <piotrdrag@gmail.com>
Mark Wielaard [Fri, 12 Jun 2015 10:50:14 +0000 (12:50 +0200)]
libebl: SHT_(INIT|FINI|PREINIT)_ARRAY are valid targets for relocation.
Seen in run-elflint-self.sh for size.o when build with --enable-gcov.
https://bugzilla.redhat.com/show_bug.cgi?id=1230798
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 11 Jun 2015 11:22:16 +0000 (13:22 +0200)]
elfutils.spec.in (devel): Include known-dwarf.h and version.h.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 10 Jun 2015 15:44:42 +0000 (17:44 +0200)]
Prepare 0.162 release.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 9 Jun 2015 22:22:58 +0000 (00:22 +0200)]
addr2line: Fix memory leak in print_dwarf_function.
Always free the scopes returned by dwarf_getscopes () when done.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 9 Jun 2015 14:26:16 +0000 (16:26 +0200)]
strip: Just admit we don't support stripping ar archives for now.
We try to handle (in-place) stripping of ar archives, but since elf_clone
doesn't really support cloning ar members and we don't handle reducing
the size of the members, moving the offsets of other members. This causes
crashes or writing garbage. Better to just admit that for now we don't
support stripping archives. Call error when we see an ELF_K_AR file.
https://bugzilla.redhat.com/show_bug.cgi?id=766156
https://lists.fedorahosted.org/pipermail/elfutils-devel/2009-August/000567.html
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 8 Jun 2015 22:31:25 +0000 (00:31 +0200)]
libdw: Initialize dirarray early in read_srclines.
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 <mjw@redhat.com>
Mark Wielaard [Mon, 8 Jun 2015 22:28:13 +0000 (00:28 +0200)]
configure: Add check for gcc -Wstack-usage.
Some older gcc versions don't support -Wstack-usage. Only use it when
accepted by the compiler.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 6 Jun 2015 21:40:42 +0000 (23:40 +0200)]
libdwfl: Fix memory leak in find_debuginfo_in_path.
commit c4f133 libdwfl: find_debuginfo_in_patch don't alloca/strdupa
strings of unknown size. Introduced a memory leak in the case nothing
was found. Make sure before returning all temporary strings are all
freed.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 6 Jun 2015 20:49:34 +0000 (22:49 +0200)]
libdwfl: Fix memory leak in cache_sections.
commit be1778 libdwfl: Fix possible unbounded stack usage in cache_sections.
introduced a memory leak. The refs pointers were copied to the sortrefs
array but never freed. Only the array was freed. Also free the elements.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 4 Jun 2015 14:25:37 +0000 (16:25 +0200)]
libelf: Make sure elf_getdata_rawchunk returns aligned data.
elf_getdata_rawchunk might return an unaligned buffer for the requested
ELF data type. Make sure the data is also correctly aligned when using
an mmapped file. Also add some missing alignments for ELF data types
for __libelf_type_align (the missing types could also make elf_getdata
to return unaligned data).
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 3 Jun 2015 16:50:40 +0000 (18:50 +0200)]
libelf: Make sure conversion functions work on aligned data for type.
The gelf_xlate conversion functions work on properly aligned ELF data
types. If elf_get data needs to do conversion and ! ALLOW_UNALIGNED
and the rawdata_base isn't aligned properly for the section type, then
provide an aligned copy of the data.
Found with --enable-sanitize-undefined in run-test-archive64.sh on x86_64.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Yuri Chornoivan [Mon, 8 Jun 2015 13:12:47 +0000 (15:12 +0200)]
Ukrainian translation update
https://bugzilla.redhat.com/show_bug.cgi?id=1139815
Signed-off-by: Yuri Chornoivan <yurchor@ukr.net>
Yuri Chornoivan [Tue, 9 Sep 2014 16:57:00 +0000 (19:57 +0300)]
Ukrainian translation update
Signed-off-by: Yuri Chornoivan <yurchor@ukr.net>
Mark Wielaard [Wed, 3 Jun 2015 15:42:38 +0000 (17:42 +0200)]
libdw: Initialize filelist early in read_srclines.
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 <mjw@redhat.com>
Mark Wielaard [Sat, 6 Jun 2015 13:06:22 +0000 (15:06 +0200)]
libdwfl: Report core module segment even when NT_FILE build-id doesn't match.
dwfl_segment_report_module can take the NT_FILE note contents to find
the matching file for the module on the file system from the core file.
If the file exists but the build-id didn't match we would not report the
module. But we should just report the module anyway, ignore the file,
and try to match the ELF image another way.
This issue can be replicated by building and running make check in
/tmp/elfutils with run-backtrace-core-aarch64.sh since that core file
includes a NT_FILE note pointing to /tmp/elfutils/tests/backtrace-child.
Which won't match if it was just recompiled.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 4 Jun 2015 11:51:27 +0000 (13:51 +0200)]
libelf: Check e_shoff alignment before direct access of Elf(32|64)_Shdr.
In get_shnum the check was whether the Elf(32|64)_Ehdr was correctly
aligned, but to access the Shdr directly we need to check whether the
address that points to the Elf(32|64)_Shdr structure is correctly aligned.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 2 Jun 2015 08:54:26 +0000 (10:54 +0200)]
libelf: Split checks for ehdr and shdr, drop phdr check in file_read_elf.
There are various places in the code that check whether mmapped structures
are correctly aligned (or ALLOW_UNALIGNED is set). Some of these checks
are asserts. Like the one in elf(32|64)_getshdr. We should not get into
that part of the code if the shdr scn structure was cached in elf_begin
because it was mmapped in and properly aligned.
These asserts could trigger because in elf_begin.c file_read_elf ()
all alignment checks were combined. So even though only one of the ehdr,
shdr or phdr structures were not properly aligned all structures would be
copied. Also the phdr structure was not even read in elf_begin, so the
alignment check was unnecessary.
This patch splits the alignment checks and reading of ehdr and shdr
structures into separate code paths. It also drops the phdr alignment
checks in elf_begin. Those phdr checks are done in elf(32|64)_getphdr
already.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 1 Jun 2015 15:07:26 +0000 (17:07 +0200)]
libdwfl: Fix memory leak in __libdwfl_open_by_build_id.
commit c57829 introduced a memory leak by passing the path string to
strsep. strsep will change the given pointer and set it to NULL eventually.
Causing the original pointer to leak. Fix by passing a copy of the pointer
to strsep.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 31 May 2015 21:03:30 +0000 (23:03 +0200)]
Define MODVERSION in a more reproducable way.
We define MODVERSION to make sure the libebl backend modules match the
elfutils build when we dlopen them. Using hostname and date makes it very
hard to create reproducable builds. Define them a little more reproducable
using LIBEBL_SUBDIR, eu_version and ac_cv_build.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 31 May 2015 20:37:19 +0000 (22:37 +0200)]
Fix sanitize-undefined config check. Don't ALLOW_UNALIGNED when checking.
The -fsanitize=undefined check need to use AC_LINK_IFELSE to make sure
libubsan is installed. When doing undefined checking we should disable
ALLOW_UNALIGNED memory accesses to catch issues where we do unaligned
accesses by accident.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 31 May 2015 18:49:23 +0000 (20:49 +0200)]
libdwfl: Don't assume auxv or r_debug data is properly aligned in link_map.
core file data isn't guaranteed to be alligned properly. Use
read_(4|8)ubyte_unaligned_noncvt to read values, types and addresses.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 31 May 2015 14:09:01 +0000 (16:09 +0200)]
libelf: Fix possible unbounded stack usage in load_shdr_wrlock.
When a copy needs to be made of the shdrs, allocate with malloc and free
after conversion instead of calling alloca.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 31 May 2015 14:05:34 +0000 (16:05 +0200)]
libelf: Fix possible unbounded stack usage in getphdr_wrlock.
When a copy needs to be made of the phdrs, allocate with malloc and free
after conversion instead of calling alloca.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 31 May 2015 13:58:20 +0000 (15:58 +0200)]
libelf: Fix unbounded stack usage in elf_getarsym for !ALLOW_UNALIGNED case.
The number of entries in the index can be large, don't use alloca to
read in temporary data, use malloc (which is freed after out).
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 30 May 2015 21:55:50 +0000 (23:55 +0200)]
elfcmp: Don't call memcmp with possible NULL d_buf.
When d_size is zero d_buf might be NULL.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 30 May 2015 21:50:14 +0000 (23:50 +0200)]
libelf: Don't call memmove with possible NULL buffer.
When size is zero the buffer src and dest buffers might be NULL.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 30 May 2015 21:43:11 +0000 (23:43 +0200)]
libelf: Don't call mempcpy with possible NULL d_buf.
When d_size is zero d_buf might be NULL. last_position doesn't need to be
updated in that case.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 30 May 2015 21:38:28 +0000 (23:38 +0200)]
libdwfl: Check file_name is not NULL before calling canonicalize_file_name.
canonicalize_file_name is marked as taking a nonnull argument.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 30 May 2015 21:00:40 +0000 (23:00 +0200)]
tests: Always print reason when skipping test.
Make sure the reason a test is SKIPPED is added to the test-suite.log.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 30 May 2015 20:50:37 +0000 (22:50 +0200)]
configure: Add check for bunzip2 and maintainer-mode tools.
Without bunzip2 make check cannot be run. To generate all files in
maintainer-mode flex and bison are needed. Otherwise check that
libdw/known-dwarf.h is already generated.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 27 May 2015 12:05:15 +0000 (14:05 +0200)]
libdw: Fix overflow in read_encoded_value for the DW_EH_PE_indirect case.
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 <mjw@redhat.com>
Mark Wielaard [Wed, 27 May 2015 12:05:15 +0000 (14:05 +0200)]
libdw: Fix overflow in read_encoded_value for the DW_EH_PE_indirect case.
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 <mjw@redhat.com>
Mark Wielaard [Sat, 23 May 2015 22:07:33 +0000 (00:07 +0200)]
libdwfl: Check mod is not NULL in check_module.
check_module is called from dwfl_module_relocate_address and from
dwfl_module_address_section. Both could take a NULL Dwfl_Module if
an earlier error had occured. Make check_module return immediately
indicating an issue in that case.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 23 May 2015 15:50:09 +0000 (17:50 +0200)]
config: Add -Wstack-usage=262144 (256K) warning check.
All library code now builds with this warning and -Werror enabled.
Add exceptions for most of the src tools (ldgeneric, readelf, nm, size,
strip, elflint, findtextrel, elfcmp objdump, ranlib, ar and unstrip).
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 22 May 2015 21:33:56 +0000 (23:33 +0200)]
libdw: Limit stack usage of temporary dir, file and line lists.
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 <mjw@redhat.com>
Mark Wielaard [Fri, 22 May 2015 16:31:58 +0000 (18:31 +0200)]
libdwfl: Don't allocate phdrs and dyn on stack in link_map.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 22 May 2015 16:01:34 +0000 (18:01 +0200)]
libdwfl: Don't allocate phdrs and dyn on stack in dwfl_segment_report_module.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 22 May 2015 14:01:02 +0000 (16:01 +0200)]
libdwfl: find_debuginfo_in_patch don't alloca/strdupa strings of unknown size.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 22 May 2015 12:18:11 +0000 (14:18 +0200)]
libdwfl: Reject very short or really large build-ids.
We cannot handle build-ids less than at least 3 or more than 64 bytes.
Very big build-ids, or very large debug search paths might have blown
up the stack.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 19 May 2015 11:39:39 +0000 (13:39 +0200)]
libdwfl: Don't allocate all phdrs on the stack in elf_from_remote_memory.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 19 May 2015 10:58:49 +0000 (12:58 +0200)]
libdwfl: Don't stack allocate alternate_name in dwfl_linux_kernel_find_elf.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 19 May 2015 10:40:30 +0000 (12:40 +0200)]
libdwfl: Minimize stack usage in dwfl_linux_kernel_report_offline.
Don't stack allocate module name. Also fixes a latent bug (if the module
file didn't have a suffix - which is very unlikely) and an inefficiency.
We only need to substitue chars up to the suffix.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 19 May 2015 09:52:58 +0000 (11:52 +0200)]
libdw: Fix possibly unbounded stack usage in __libdw_intern_expression.
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 <mjw@redhat.com>
Mark Wielaard [Mon, 18 May 2015 19:26:24 +0000 (21:26 +0200)]
libdwfl: Fix unbounded stack usage in find_prelink_address_sync.
Allocate phdr and shdr unions with malloc, not alloca. Free after use.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 18 May 2015 14:23:06 +0000 (16:23 +0200)]
libdwfl: Fix possible unbounded stack usage in cache_sections.
For modules with lots of sections cache_sections could blow up the stack
theoretically. Don't use alloca, but use malloc with explicit free.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 17 May 2015 18:07:56 +0000 (20:07 +0200)]
libebl: Don't blow up stack when processing large NT_GNU_ABI_TAG.
Normally an NT_GNU_ABI_TAG is large, just 4 words (16 bytes).
Only use stack allocated conversion buf for small (max 16 words) notes.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 17 May 2015 16:49:10 +0000 (18:49 +0200)]
libebl: Use static number for array stack allocation in openbackend.
Help the compiler see we stack allocate a small array. Add assert to check
no machine prefix is ever larger than 16. Current maximum number is 7.
This prevents gcc warning about possible unbounded stack usage with
-Wstack-usage.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 17 May 2015 08:30:57 +0000 (10:30 +0200)]
libelf: Fix possible unbounded stack usage in updatefile.
Allocate shdr_data and scns with malloc, not alloca. Free after writing
section headers.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 16 May 2015 20:41:36 +0000 (22:41 +0200)]
libelf: Fix possible unbounded stack usage in updatemmap.
Allocate temporary shdr storage with malloc, not alloca. Free after
writing section headers.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 16 May 2015 19:30:41 +0000 (21:30 +0200)]
libelf: Fix possible unbounded stack usage in elf_getarsym.
The number of entries in the index can be large, don't use alloca to
read in temporary data, use malloc (and free after out).
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 21 May 2015 14:05:18 +0000 (16:05 +0200)]
addr2line: Set scopes to NULL after free in handle_address.
If dwarf_getscopes_die () fails then scopes might not be reset and we
could cause a double free.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 20 May 2015 12:09:46 +0000 (14:09 +0200)]
addr2line: Add --pretty-print option to show all information on one line.
This adds an option --pretty-print to eu-addr2line to show all information
on one line and all inlines on a line of their own. This mimics the same
option from binutils addr2line, but without the short option variant -p.
Since we already use -p to select the process.
Example output:
eu-addr2line --pretty-print -s -i -f -C -p$(pidof firefox) 0x00007f368c6f8915
mozilla::ReentrantMonitor::Wait(unsigned int) at ReentrantMonitor.h:92
(inlined by) mozilla::ReentrantMonitorAutoEnter::Wait(unsigned int) at ReentrantMonitor.h:190
A couple of tests were added to check the output matches that of
binutils addr2line.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 20 May 2015 09:52:27 +0000 (11:52 +0200)]
addr2line: Add demangler support.
Makes the -C, --demangle option visible and implements it (ignoring the
demangle style argument). Adds a new test with sample output.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 19 May 2015 14:21:27 +0000 (16:21 +0200)]
addr2line: Add -a, --address. Print address before for each entry.
Adds test cases with sample output.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 19 May 2015 21:08:00 +0000 (23:08 +0200)]
addr2line: Always parse addresses as hex numbers.
We would sometimes interpret input addresses as decimal or octal.
That could be confusing and isn't what binutils addr2line does.
Be consistent and always treat input addresses as hex.
Signed-off-by: Mark Wielaard <mjw@redhat.com>