Mark Wielaard [Fri, 21 Oct 2016 13:24:34 +0000 (15:24 +0200)]
libelf: Sanity check offset and size before trying to malloc and read data.
Bad sh_off or sh_size could trigger a bad malloc or read. Sanity check
the header values first before trying to malloc a huge buffer or reading
any data that will certainly fail.
https://bugzilla.redhat.com/show_bug.cgi?id=1387584
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 26 Oct 2016 11:08:52 +0000 (13:08 +0200)]
libelf: Always set ELF maxsize when reading an ELF file for sanity checks.
There are various sanity checks that depend on knowing the file size
of the underlying ELF file which we only used when mmapping the ELF file.
Although we probably won't crash if we use pread to try to read from
the file, we still might return completely bogus data structures. This
could cause us to malloc insane amounts of memory.
Always try to get the maxsize when unknown in elf_begin.c (read_file).
https://bugzilla.redhat.com/show_bug.cgi?id=1388057
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 22 Oct 2016 17:18:51 +0000 (19:18 +0200)]
libdw: Correct spelling of DW_LANG_PLI in dwarf.h.
The name used in the standard and other DWARF implementations for
Programming Language One, PL/I, is DW_LANG_PLI (not DW_LANG_PL1).
Fix usage in dwarf_aggregate_size.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 2 Nov 2016 12:29:26 +0000 (13:29 +0100)]
Add GCC7 -Wimplicit-fallthrough support/fixes.
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>
Kevin Cernekee [Sun, 23 Oct 2016 17:25:56 +0000 (10:25 -0700)]
tests: unstrip: Add test for mismatched .strtab sections
Current unstrip test cases either have no .symtab/.strtab in the
stripped binary, or .strtab sections that are identical between the
stripped and debuginfo binaries. Add a test case where .symtab/.strtab
in the stripped binary contains a small subset of the full unstripped
data.
Signed-off-by: Kevin Cernekee <cernekee@chromium.org>
Kevin Cernekee [Sun, 23 Oct 2016 17:25:55 +0000 (10:25 -0700)]
unstrip: Don't try to use unstripped .symtab with stripped .strtab
Prematurely matching up the stripped and unstripped .strtab sections
in the "Match each debuginfo" loop can lead to a case where sec->outscn
gets populated for the stripped .strtab, which we normally want to
ignore. This causes the .strtab override in the "Make sure each main
file section" loop to be skipped, so the code winds up using indices
from the unstripped .symtab to look up strings in the stripped .strtab.
This returns incorrect strings for a little while, and then fails
catastrophically when it tries to read past the end of the (smaller)
stripped file's .strtab section:
eu-unstrip: invalid string offset in symbol [1589]
Fix this by adding logic to the "Match each debuginfo" loop to
treat the unstripped .strtab, .shstrtab, and .symtab sections
essentially the same way.
The new logic will break if the .strtab section shows up earlier than
the .symtab section. We will assume this never happens in practice.
Signed-off-by: Kevin Cernekee <cernekee@chromium.org>
Akihiko Odaki [Thu, 13 Oct 2016 00:16:48 +0000 (09:16 +0900)]
Do not depend on some non-POSIX features.
Define/open code memrchr, rawmemchr, powerof2 and TEMP_FAILURE_RETRY if
not available through system headers.
Signed-off-by: Akihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Akihiko Odaki [Tue, 11 Oct 2016 14:06:48 +0000 (23:06 +0900)]
lib: Provide MAX and MIN in system.h
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>
Mark Wielaard [Thu, 6 Oct 2016 14:06:32 +0000 (16:06 +0200)]
strip: Don't remove real symbols from allocated symbol tables.
Having a symbol in an allocated symbol table (like .dynsym) that
points to an unallocated section is wrong. Traditionally strip
has removed such symbols if they are section or group symbols.
But removing a real symbol from an allocate symbol table is hard
and probably a mistake. Really removing it means rewriting the
dynamic segment and hash sections. Since we don't do that, don't
remove the symbol (and corrupt the ELF file). Do warn and set
the symbol section to SHN_UNDEF.
https://bugzilla.redhat.com/show_bug.cgi?id=1380961
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 5 Sep 2016 09:15:50 +0000 (11:15 +0200)]
libcpu: Fix build of bpf_disasm.c for kernels < 3.20.
Before linux 3.20 the BPF_PSEUDO_MAP_FD constant wasn't defined.
Reported-by: Julian Ospald <hasufell@posteo.de>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 30 Aug 2016 11:42:31 +0000 (13:42 +0200)]
tests: Fix --enable-gcov tests build. Add libdw to LDADD for asm_tsts.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 26 Aug 2016 09:55:59 +0000 (11:55 +0200)]
Regenerate .po files.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 25 Aug 2016 15:17:23 +0000 (17:17 +0200)]
tests: Simplify backtrace-native tests. Drop raise jmp patching for x86_64.
The backtrace-native[-biarch] testcase was a little too clever in places
making it unreliable.
On x86_64 we tried to make an interesting backtrace by catching the
first signal and then replacing the pc with the address of the first
instruction of a function. Then we would raise a new signal, through
ptrace, to create a backtrace that went from a signal frame into a
frame at the start of a function. That way we could check that we were
trying to fetch the correct CFI for the (jmp) function even at the
first instruction (normally we would substract one from the return
address to get at the call address).
This works as long as the CFI for the jmp() function is identical to
the CFI for the raise() function that we "patched away". Unfortunately
on Fedora rawhide glibc has a rewritten raise() implementation that has
different CFI, in particular the CFA is calculated differently. Making
the testcase fail because we cannot properly unwind from jmp().
So this special x86_64 case has been disabled (the code is still there
in case we find another way to test this in a more reliable way).
On Ubuntu there have been spurious testcase failures because
see_exec_module found two Dwfl_Modules with the same path. This would
trigger an assert. Although this might indicate some issue (maybe we
are not parsing the proc/pid/map correctly?) it isn't clear that it
really is a bug. Since the assert is not very helpful finding any
actual bug and for the testcase it is only necessary that the first
Dwfl_Module that represents the executable is found we just pick that
Dwfl_Module and don't iterate through any of the others.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 25 Aug 2016 18:43:42 +0000 (20:43 +0200)]
strip: Use ELF_CHF_FORCE to recompress any sections that were uncompressed.
Older gcc might create small .debug_pubtype. If such a section is compressed
then strip should use ELF_CHF_FORCE to return it to compressed state after it
is done with the section. Found by the run-strip-reloc.sh testcase on rhel6.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 24 Aug 2016 17:42:31 +0000 (19:42 +0200)]
Regenerate .po files.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 24 Aug 2016 15:55:53 +0000 (17:55 +0200)]
tests: Add testfilesparc64attrs.o.bz2 to EXTRA_DIST.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Jose E. Marchesi [Wed, 24 Aug 2016 13:47:57 +0000 (06:47 -0700)]
sparc: fix the printing of hw capabilities object attributes.
The GNU_Sparc_HWCAPS and GNU_Sparc_HWCAPS2 object attributes comprise
a set of hardware capabilities that may (or not) be present in the
target machine for which the object was compiled. This patch adds the
support for printing a nicely formatted comma-separated list with the
selected hw capabilities.
Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
Piotr Drąg [Thu, 18 Aug 2016 13:33:54 +0000 (15:33 +0200)]
Updated Polish translation
https://bugzilla.redhat.com/show_bug.cgi?id=1368130
Signed-off-by: Piotr Drąg <piotrdrag@gmail.com>
Piotr Drąg [Thu, 18 Aug 2016 13:18:00 +0000 (15:18 +0200)]
Add --add-comments to XGETTEXT_OPTIONS in Makevars
So that translator comments show up in .po files.
https://bugzilla.redhat.com/show_bug.cgi?id=1368130
Signed-off-by: Piotr Drąg <piotrdrag@gmail.com>
Piotr Drąg [Thu, 18 Aug 2016 13:10:09 +0000 (15:10 +0200)]
Update POTFILES.in
https://bugzilla.redhat.com/show_bug.cgi?id=1368130
Signed-off-by: Piotr Drąg <piotrdrag@gmail.com>
Mark Wielaard [Fri, 12 Aug 2016 09:36:10 +0000 (11:36 +0200)]
libdwfl: Fix assert and set in.d_size in dwfl_link_map_report.
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>
Mark Wielaard [Sun, 7 Aug 2016 20:13:46 +0000 (22:13 +0200)]
libelf: Fix memory leak in elf_compress for mmapped ELF files.
The testcase added to run-strip-reloc.sh for strip-compressed.o showed
a memory leak when ran under valgrind (configure --enable-valgrind).
For a mmapped ELF file when existing section data was compressed
elf_end would fail to release the new compressed data buffer assigned
to rawdata_base. For non-mapped files rawdata_base is always freed.
For decompressed data rawdata_base is released together with zdata_base.
Use the Elf_Scn flag ELF_T_MALLOCED to track whether rawdata_base
points to malloced memory and free it in elf_end even for mmapped
ELF files.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 6 Aug 2016 13:13:19 +0000 (15:13 +0200)]
strip: Handle compressed relocation target sections.
binutils 2.27 assembler will create compressed sections for x86 ELF
targets. The linker will decompress them again and it doesn't do this
for any other target. This broke one of the run-strip-reloc.sh self tests.
Fix by checking if the target of a relocation section is compressed and
first decompressing it before applying relocations and then compressing
again if necessary.
Add explicit testcases for compressed and uncompressed ET_REL files
to run-strip-reloc.sh.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Richard Henderson [Wed, 10 Aug 2016 07:11:21 +0000 (12:41 +0530)]
Fix bpf disassembler for _FORTIFY_SOURCE
It's illegal to skip positional operands for printf. Rearrange the
printing of the instructions to use exactly the operands required.
Also, fix printing of mod operations: s/%/%%/ in the print format.
Also, fix printing of endian operations: remove extra spaces.
Mark Wielaard [Thu, 4 Aug 2016 11:36:34 +0000 (13:36 +0200)]
Prepare 0.167 release.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 8 Jul 2016 12:08:22 +0000 (14:08 +0200)]
dwelf: Add string table functions from ebl.
Move the strtab functions from libebl to libdw. Programs often want to
create ELF/DWARF string tables. We don't want (static) linking against
ebl since those are internal functions that might change.
This introduces dwelf_strtab_init, dwelf_strtab_add,
dwelf_strtab_add_len, dwelf_strtab_finalize, dwelf_strent_off,
dwelf_strent_str and dwelf_strtab_free. Documentation for each has
been added to libdwelf.h. The add fucntion got a variant that takes
the length explicitly and finalize was changed to return NULL on
out of memory instead of aborting. All code and tests now uses the
new functions.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 6 Jul 2016 16:27:54 +0000 (18:27 +0200)]
Remove eu-ld and unused code.
Nobody has hacked on eu-ld in a very long time. It didn't really work.
And we didn't install it by default in the spec file. Remove sources,
the build rules and any (now) unused code.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Andreas Schwab [Sun, 10 Jul 2016 15:36:38 +0000 (17:36 +0200)]
Add m68k tests
Signed-off-by: Andreas Schwab <schwab@linux-m68k.org>
Mark Wielaard [Wed, 6 Jul 2016 19:31:54 +0000 (21:31 +0200)]
unstrip: Fix off by one array access with unstripped_strent.
When configuring with --enable-sanitize-undefined the latest GCC found
an array out of bounds access when running the un-strip-strmerge.sh test.
We keep an array of section names. But skipped section zero, since it
didn't have a name. We should however not actually skip the first array
index (zero) when storing and reading the names.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 6 Jul 2016 13:27:56 +0000 (15:27 +0200)]
libelf: Allow updating phdrs for any e_type.
elf[32|64]_updatenull would sanity check the e_type before allowing to
update the phdrs. This prevents creating an ET_REL file with phdrs. It
also prevents creating any vendor specific ELF file having phdrs. We
only check this when updating/writing out the file. But we would just
read such files. Don't prevent people from creating unexpected ELF files.
elflint will warn for such files.
While writing a new testcase for this another bug was found that
prevented updating a just created phdr because elf_getphdrnum would
sanity check the phdr offset in the file (which doesn't exist yet).
Fix that by only doing such a sanity check if the phdrs haven't been
read in or created yet.
This second bug should have been found by the existing elfshphehdr
test, but that test contained a typo checking elf_getphdrnum.
It tested that the called failed when there were no phdrs, but then
elf_getphdrnum should simply succeed and return zero.
https://bugzilla.redhat.com/show_bug.cgi?id=1352232
Signed-off-by: Mark Wielaard <mjw@redhat.com>
John Ogness [Thu, 23 Jun 2016 14:03:58 +0000 (16:03 +0200)]
libelf: find 1st section instead of assuming
When getting section headers it is assumed that the first section
is on the first section list. However, it is possible that the
first section list only contains the zeroth section, in which
case either illegal memory access occurs or elf_nextscn()
erroneously returns NULL.
With this patch, checks are added to avoid the illegal memory
access and (if available) the second section list is looked at
to find the first section.
A new test emptyfile is added that tests adding a section to
and "empty" ELF file 32/64 class with ELF_C_RDWR[_MMAP].
Signed-off-by: John Ogness <john.ogness@linutronix.de>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Richard Henderson [Tue, 21 Jun 2016 22:10:10 +0000 (15:10 -0700)]
Add support for BPF
Signed-off-by: Richard Henderson <rth@redhat.com>
Richard Henderson [Tue, 21 Jun 2016 22:10:09 +0000 (15:10 -0700)]
Sync elf.h from glibc
Add lots of new EM_* definitions.
Add R_BPF_* definitions.
Signed-off-by: Richard Henderson <rth@redhat.com>
Mark Wielaard [Fri, 10 Jun 2016 12:03:15 +0000 (14:03 +0200)]
CONTRIBUTING: Extend patch, committer and maintainer guidelines.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Andreas Schwab [Fri, 20 May 2016 17:37:29 +0000 (19:37 +0200)]
Add support for m68k
Signed-off-by: Andreas Schwab <schwab@linux-m68k.org>
Filipe Brandenburger [Mon, 2 May 2016 20:26:13 +0000 (13:26 -0700)]
config: Pass the compiler -Werror during warning detection
Otherwise the compilation prints a warning but exits with 0 return code.
However, later during the compilation, when -Werror is enforced to about
every file, the unsupported options start breaking the builds.
Tested: Ran configure with clang-3.5 and built libelf/ tree with it.
$ autoreconf -i
$ ./configure CC=clang-3.5 ...
$ make -C libelf
Signed-off-by: Filipe Brandenburger <filbranden@google.com>
Filipe Brandenburger [Mon, 2 May 2016 19:18:47 +0000 (12:18 -0700)]
config: Fix check for argp_parse to pass &argv
Right now it's passing a char* when it expects a char** instead.
This usually produces a warning that may go unnoticed, but if CFLAGS
contains -Werror, that breaks the ./configure run with the following
error:
$ ./configure CFLAGS=-Werror
...
configure: WARNING: "libc does not have argp"
checking for argp_parse in -largp... no
configure: error: "no libargp found"
Tested: Checked that after this fix, running ./configure CFLAGS=-Werror
works as expected and argp_parse is correctly detected.
Signed-off-by: Filipe Brandenburger <filbranden@google.com>
Mark Wielaard [Thu, 14 Apr 2016 19:53:33 +0000 (21:53 +0200)]
libdwfl: Fix memory leak in dwfl_module_getsrc_file on invalid DWARF.
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>
Mark Wielaard [Thu, 14 Apr 2016 19:32:55 +0000 (21:32 +0200)]
libdwfl: Fix memory leak in proc_maps_report on bad file mapping.
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>
Mark Wielaard [Thu, 14 Apr 2016 19:02:39 +0000 (21:02 +0200)]
libelf: Fix memory leak when zlib deflateInit fails in elf_compress.
On error we return NULL, not out_buf. So make sure to not leak it.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
David Abdurachmanov [Mon, 11 Apr 2016 14:00:57 +0000 (16:00 +0200)]
elfcmp: fix self-comparison error with GCC 6
Noticed with Fedora 24 Alpha, gcc (GCC) 6.0.0
20160406
(Red Hat 6.0.0-0.20).
elfcmp.c: In function ‘main’:
elfcmp.c:364:199: error: self-comparison always evaluates
to false [-Werror=tautological-compare]
if (unlikely (name1 == NULL || name2 == NULL
Signed-off-by: David Abdurachmanov <davidlt@cern.ch>
Mark Wielaard [Thu, 31 Mar 2016 09:04:25 +0000 (11:04 +0200)]
Prepare 0.166 release.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 21 Mar 2016 15:01:02 +0000 (16:01 +0100)]
nm: Check for malloc size argument overflow in show_symbols.
Reported-by: Florian Weimer <fweimer@redhat.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 2 Mar 2016 14:04:43 +0000 (15:04 +0100)]
config: Use --program-prefix=eu- by default.
We want eu- as default program prefix if none was given by the user.
But if the user explicitly provided --program-prefix="" then pretend
it wasn't set at all (NONE).
This makes sure all tools will be installed as eu-<program>.
We want this default since most tools would normally conflict with
the GNU binutils variants that have similar names.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Steven Chamberlain [Tue, 1 Mar 2016 13:32:37 +0000 (13:32 +0000)]
libdwfl: clean up non-Linux GNU platforms code
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>
Jose E. Marchesi [Fri, 26 Feb 2016 18:30:30 +0000 (10:30 -0800)]
sparc: restore 32-bit build.
This patch provides a dummy sparc_set_initial_registers-tid for
sparc32. This fixes the build in sparcv9-*-* targets.
Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
Andreas Schwab [Fri, 26 Feb 2016 14:47:21 +0000 (15:47 +0100)]
Add support for DT_PPC_OPT
https://sourceware.org/ml/binutils/2013-10/msg00378.html
Signed-off-by: Andreas Schwab <schwab@suse.de>
Ravi Bangoria [Tue, 16 Feb 2016 16:21:35 +0000 (21:51 +0530)]
libdwfl: Check for kernel debuginfo file without .debug extension as well
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>
Mark Wielaard [Sat, 13 Feb 2016 19:00:37 +0000 (20:00 +0100)]
readelf: Warn when uncompressing fails and error when gelf_getshdr fails.
After decompressing we want to get the new shdr. This can theoretically
fail so we have to check. Also warn the user if a section couldn't be
uncompressed.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 13 Feb 2016 18:56:13 +0000 (19:56 +0100)]
elfcompress: -q should not imply --force.
We accidentally set force = true after handling -q and setting verbose--.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 13 Feb 2016 18:51:48 +0000 (19:51 +0100)]
libelf: Don't leak memory when out of memory in updatemmap.
We forgot to free scns when returning ELF_E_NOMEM.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 13 Feb 2016 18:48:57 +0000 (19:48 +0100)]
libdwfl: Don't leak memory in proc_maps_report when ENOEXEC.
We forgot to free last_file on error.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 13 Feb 2016 18:44:59 +0000 (19:44 +0100)]
libdwfl: Don't crash on out of memory when frame unwinding.
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>
Mark Wielaard [Sat, 13 Feb 2016 18:36:50 +0000 (19:36 +0100)]
libdw: Fix bad free on invalid data in dwarf_getsrclines.c.
If the last dir name wasn't zero terminated we goto invalid_data
and might free the wrong data because we believe ndirlist is valid.
Don't update ndirlist until we are sure we will use all dirs.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 13 Feb 2016 18:10:00 +0000 (19:10 +0100)]
config: Check for and use gcc -Wnull-dereference.
-Wnull-dereference is new in GCC6
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 12 Feb 2016 22:59:32 +0000 (23:59 +0100)]
Fix GCC6 -Wnull-dereference warnings.
asm_begin.c: In function ‘asm_begin’:
asm_begin.c:62:7: error: potential null pointer dereference [-Werror=null-dereference]
__fsetlocking (result->out.file, FSETLOCKING_BYCALLER);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We set result to NULL just before this call in case of error.
Fixed by only calling __fsetlocking when result is not NULL.
strip.c: In function ‘handle_elf.constprop’:
strip.c:1270:31: error: null pointer dereference [-Werror=null-dereference]
elf_assert ((versiondata->d_size / sizeof (Elf32_Word))
~~~~~~~~~~~^~~
src/strip.c:597:37: note: in definition of macro ‘elf_assert’
#define elf_assert(test) do { if (!(test)) goto illformed; } while (0)
^~~~
That is the wrong check, we want to check shndxdata, not versiondata here.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 28 Jan 2016 12:59:20 +0000 (13:59 +0100)]
Add new i386 and x86_64 relocation types.
Update elf.h from glibc and recognize R_386_GOT32X, R_X86_64_GOTPCRELX
and R_x86_64_REX_GOTPCRELX as non-dynamic relocations.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 11 Feb 2016 12:20:59 +0000 (13:20 +0100)]
libdwfl: Check result of gelf_get* calls in relocate.c
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>
Mark Wielaard [Thu, 11 Feb 2016 11:46:03 +0000 (12:46 +0100)]
libdwfl: Check result of gelf_update_* calls in relocate_section.
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>
Mark Wielaard [Tue, 9 Feb 2016 22:25:54 +0000 (23:25 +0100)]
readelf: Read and print (encoded) DW_CFA_set_loc op and update pc.
DW_CFA_set_loc takes an address as op, not an uleb128. Read and decode it.
Print the actual address and (updated) pc (address plus vma_base).
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 12 Feb 2016 17:04:30 +0000 (18:04 +0100)]
Add NT_ARM_SYSTEM_CALL aarch64 syscall regset.
Linux kernel 3.18 added the NT_ARM_SYSTEM_CALL regset for aarch64.
Recognize and print this new core item.
https://bugzilla.redhat.com/show_bug.cgi?id=1285613
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 12 Feb 2016 14:04:00 +0000 (15:04 +0100)]
libebl: Don't assume ELF notes are "GNU" when unknown, recognize "Go" notes.
We used to assume any unknown ELF note provider name was "GNU" and didn't
recognize any of the "Go" provider types. We now check the provider name
explictly in ebl_object_note_type_name and recognize the following Go
note names: PKGLIST, ABIHASH, DEPS and BUILDID. But there is no attempt
yet in ebl_object_note to decode the description of these notes.
https://bugzilla.redhat.com/show_bug.cgi?id=1295951
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 9 Feb 2016 15:10:22 +0000 (16:10 +0100)]
config: Check for and use gcc -Wlogical-op and -Wduplicated-cond.
Both -Wlogical-op and -Wduplicated-cond may produce useful warnings.
But we have to check them first. Older versions of gcc had a -Wlogical-op
that warned on some constructs using macros that are not erronious.
Only GCC6 has -Wduplicated-cond.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 9 Feb 2016 13:18:49 +0000 (14:18 +0100)]
elflint: Fix sh_entsize check when comparing SHT_HASH and SHT_GNU_HASH.
GCC6 -Wduplicated-cond found the following issue:
elflint.c: In function ‘compare_hash_gnu_hash’:
elflint.c:2483:34: error: duplicated ‘if’ condition [-Werror=duplicated-cond]
else if (hash_shdr->sh_entsize == sizeof (Elf64_Word))
~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
elflint.c:2448:29: note: previously used here
if (hash_shdr->sh_entsize == sizeof (Elf32_Word))
~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Which is correct, a Word in both Elf32 and Elf64 files is 4 bytes.
We meant to check for sizeof (Elf64_Xword) which is 8 bytes.
Also fix the section index and name in the error message.
The reason we probably didn't see this issue before is that SHT_HASH
sections really always should have sh_entsize of 4 even on 64bit arches.
There are however a couple of arches with mistakes in their sysv ABI.
See libelf/common.h. This also would only be triggered if on such an
architectures when the ELF file would have both a SHT_HASH and SHT_GNU_HASH
section and elflint would try to compare those sections.
Add an example testfile-s390x-hash-both to run-elflint-test.sh.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 4 Feb 2016 08:53:41 +0000 (09:53 +0100)]
libelf: elf_getdata should not adjust alignment for SHT_NOBITS sections.
In commit c0748e "libelf: More checking of valid sh_addralign values." we
adjusted bogus alignment of data buffers if they were greater than the
offset of the data in the file. This works OK, except when there is no
data in the file. So make sure to not adjust any NOBITS sections.
Also adds a test that shows the issue and makes sure elflint is called
with --gnu in run-strip-test.sh.
https://bugzilla.redhat.com/show_bug.cgi?id=1303845
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Chih-Hung Hsieh [Fri, 22 Jan 2016 18:04:33 +0000 (10:04 -0800)]
Move nested functions in elf_compress.c and elf_strptr.c.
* elf_compress.c (__libelf_compress): do_deflate_cleanup
* elf_strptr.c (elf_strptr): get_zdata
Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Mark Wielaard [Wed, 13 Jan 2016 22:06:33 +0000 (23:06 +0100)]
tests: Skip dwfl-bug-fd-leak test if dwfl_linux_proc_report is unsupported.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 13 Jan 2016 21:57:03 +0000 (22:57 +0100)]
elflint: Recognize ELFOSABI_FREEBSD which Debian kFreeBSD uses.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 13 Jan 2016 21:49:02 +0000 (22:49 +0100)]
tests: Guard linux specific header includes with ifdef __linux__.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mike Frysinger [Thu, 14 Jan 2016 18:46:18 +0000 (13:46 -0500)]
configure: clarify zlib error message
Also drop the spurious quotes.
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Mike Frysinger [Thu, 14 Jan 2016 18:46:12 +0000 (13:46 -0500)]
gitignore: update
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Mark Wielaard [Wed, 13 Jan 2016 16:16:48 +0000 (17:16 +0100)]
libelf: Add ELF compression types and defines to libelf.h for older glibc.
Older glibc elf.h might not define the new ELF compression defines and
types. If not just define them in libelf.h directly to make the libelf
headers work on older glibc systems.
Also include a testcase to check the libelf headers build against the
system elf.h.
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=810885
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 11 Jan 2016 10:11:44 +0000 (11:11 +0100)]
Regenerate .po files.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sat, 9 Jan 2016 21:09:48 +0000 (22:09 +0100)]
libebl: Fix missing brackets around if statement body.
GCC6 [will have] a nice new warning that showed a real bug:
elfutils/libebl/eblobjnote.c: In function ‘ebl_object_note’:
elfutils/libebl/eblobjnote.c:135:5: error: statement is indented as if it were guarded by... [-Werror=misleading-indentation]
switch (type)
^~~~~~
elfutils/libebl/eblobjnote.c:45:3: note: ...this ‘if’ clause, but it is not
if (! ebl->object_note (name, type, descsz, desc))
^~
And indeed, it should have been under the if, but wasn't because of missing
brackets. Added brackets (and reindent).
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 8 Jan 2016 20:55:58 +0000 (21:55 +0100)]
tests: Fix parentheses in elfputzdata strncmp test.
We were checking strlen () == 0 instead of strncmp () == 0. Oops.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 8 Jan 2016 15:45:12 +0000 (16:45 +0100)]
Fix build on 32bit systems.
size_t has a different size on 32 and 64 bit systems.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 8 Jan 2016 13:44:49 +0000 (14:44 +0100)]
Prepare 0.165 release.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 8 Jan 2016 12:35:33 +0000 (13:35 +0100)]
Simplify code and build now that zlib support is no longer optional.
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>
Piotr Drąg [Thu, 7 Jan 2016 14:46:50 +0000 (15:46 +0100)]
Updated Polish translation
Signed-off-by: Piotr Drąg <piotrdrag@gmail.com>
Piotr Drąg [Thu, 24 Dec 2015 13:16:15 +0000 (14:16 +0100)]
Updated Polish translation
Signed-off-by: Piotr Drąg <piotrdrag@gmail.com>
Mark Wielaard [Tue, 1 Dec 2015 13:55:07 +0000 (14:55 +0100)]
elfcompress: New utility.
Usage: elfcompress [OPTION...] FILE...
Compress or decompress sections in an ELF file.
-f, --force Force compression of section even if it would
become larger
-n, --name=SECTION SECTION name to (de)compress, SECTION is an
extended wildcard pattern (defaults to
'.?(z)debug*')
-o, --output=FILE Place (de)compressed output into FILE
-p, --permissive Relax a few rules to handle slightly broken ELF
files
-q, --quiet Be silent when a section cannot be compressed
-t, --type=TYPE What type of compression to apply. TYPE can be
'none' (decompress), 'zlib' (ELF ZLIB compression,
the default, 'zlib-gabi' is an alias) or
'zlib-gnu' (.zdebug GNU style compression, 'gnu'
is an alias)
-v, --verbose Print a message for each section being
(de)compressed
-?, --help Give this help list
--usage Give a short usage message
-V, --version Print program version
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 18 Dec 2015 14:51:37 +0000 (15:51 +0100)]
elflint: Recognize and check SHF_COMPRESSED section flag.
SHF_COMPRESSED is a valid section flag, it can optionally be on any special
section, but it cannot be used on NOBITS sections or together with SHF_ALLOC.
A section that has SHF_COMPRESSED set must have a valid Chdr.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 30 Dec 2015 00:39:29 +0000 (01:39 +0100)]
libelf: Make elf_strptr index correctly into compressed section data.
elf_strptr indexes into the section data. This is defined as index into
the uncompressed data of the section. If the section is compressed make
sure the uncompressed data is available, but don't really decompress the
section header (elf_getdata will still return compressed data).
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 20 Oct 2015 23:30:44 +0000 (01:30 +0200)]
readelf: Handle compressed sections and extend -z to cover -x and -p.
When printing a (non-string, non-data) section use uncompressed data when
possible. For dumping hex and string sections (-x and -p) -z will dump the
uncompressed data (otherwise the compressed data is dumped).
-z, --decompress Show compression information for compressed
sections (when used with -S); decompress section
before dumping data (when used with -p or -x)
Includes test cases for ET_REL files using compressed relocation (target)
debug sections to test libdwfl transparent uncompression of sections.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 30 Dec 2015 13:39:18 +0000 (14:39 +0100)]
libdwfl: Use elf_compress[_gnu] to decompress string, symbol and reloc data.
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>
Mark Wielaard [Wed, 30 Dec 2015 13:18:40 +0000 (14:18 +0100)]
libdw: Use elf_compress[_gnu] to uncompress debug section data.
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 <mjw@redhat.com>
Mark Wielaard [Sat, 19 Dec 2015 00:29:54 +0000 (01:29 +0100)]
libelf: Add elf_compress and elf_compress_gnu.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 16 Oct 2015 20:21:23 +0000 (22:21 +0200)]
readelf: Add -z,--decompress option.
-z, --decompress Show compression information for compressed
sections (when used with -S).
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 19 Nov 2015 23:12:37 +0000 (00:12 +0100)]
libelf: Add elf32_getchdr, elf64_getchdr and gelf_getchdr.
Elf_Data of a compressed section has type ELF_T_CHDR. This type can be
xlated to the file or memory representation. This will make sure the Chdr
is in the correct endianess. The compressed data following the Chdr isn't
translated.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 17 Nov 2015 22:52:39 +0000 (23:52 +0100)]
libdwelf: Add dwelf_scn_gnu_compressed_size.
Helper function to get the size of a GNU compressed zdebug section.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 4 Jan 2016 20:41:52 +0000 (21:41 +0100)]
config: Add libelf and libdw pkg-config files.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 31 Dec 2015 22:16:28 +0000 (23:16 +0100)]
elflint: Add _edata and _end to the list of possibly dangling gnuld symbols.
gnuld might keep dangling/unused symbols around (see sourceware PR13621).
Add _edata (end of initialized data address) and _end (end of uninitialized
data address) to that list. They might have been added by gnuld even if
there is no such [un]initialized data. Also add the double underscore
variants which are used on some architectures.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 31 Dec 2015 22:03:20 +0000 (23:03 +0100)]
tests: elfstrmerge warn about STT_SECTION symbol for shstrhndx.
Old linkers might have created an STT_SECTION symbol for the section
header string table section, which isn't actually used. For now just
warn about such symbols. If such a symbol would actually really be used
(but why?) then we would have to handle it by removing it and rewriting
the symbol table.
This is a testsuite only change, but includes an extra test with files
that have such STT_SECTION symbols to make sure it will be handled in
case we "upgrade" the elfstrmerge test to a real utility.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 31 Dec 2015 21:08:23 +0000 (22:08 +0100)]
Make make more silent.
Silent rules already are the default, but automake and make both still
tell which directory is being entered/build. Disable printing from make.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Chih-Hung Hsieh [Wed, 18 Nov 2015 19:04:52 +0000 (11:04 -0800)]
Move nested functions in linux-proc-maps.c to file scope.
* Move nested function 'report' to file scope to compile with clang.
Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Chih-Hung Hsieh [Wed, 18 Nov 2015 18:38:19 +0000 (10:38 -0800)]
Move nested functions in core-file.c to file scope.
* Move nested functions 'fail', 'update_end', and 'more' to file scope.
Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Chih-Hung Hsieh [Tue, 17 Nov 2015 22:45:15 +0000 (14:45 -0800)]
Move nested functions check64 and check32 in link_map.c to file scope.
* 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>
Jose E. Marchesi [Tue, 8 Dec 2015 18:10:43 +0000 (19:10 +0100)]
backends: sparc: support for live backtraces
This patch implements the set_initial_registers_tid hook for sparc.
It works in both sparcv9-*-* and sparc64-*-* targets.
Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
Jose E. Marchesi [Tue, 8 Dec 2015 18:10:42 +0000 (19:10 +0100)]
backends: sparc: support for core backtraces
This patch adds sparc support to the unwinder, providing a default CFI
program that works in both sparcv9-*-* and sparc64-*-* targets.
Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Jose E. Marchesi [Tue, 8 Dec 2015 18:10:41 +0000 (19:10 +0100)]
libdwfl: make the unwinder aware of the backend defined ra_offset.
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>