platform/upstream/elfutils.git
8 years agoPrepare 0.164 release.
Mark Wielaard [Thu, 15 Oct 2015 16:28:34 +0000 (18:28 +0200)]
Prepare 0.164 release.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agolibelf: Use int64_t for offsets in libelf.h
Josh Stone [Sat, 10 Oct 2015 00:32:52 +0000 (17:32 -0700)]
libelf: Use int64_t for offsets in libelf.h

Some systems don't have loff_t, like FreeBSD where off_t always supports
large files.  We need a standardized 64-bit signed type for the public
header, without depending on configuration... OK, just use int64_t.

Signed-off-by: Josh Stone <jistone@redhat.com>
8 years agoDo not rely on ebl_check_special_section when checking debuginfo files.
Jose E. Marchesi [Tue, 13 Oct 2015 16:39:15 +0000 (18:39 +0200)]
Do not rely on ebl_check_special_section when checking debuginfo files.

The test run-strip-strmerge.sh is failing in sparc targets.  This is
because it does an `elflint -d' in a debuginfo file, and this fails
with:

  section [21] '.plt' is both executable and writable

elflint uses the ebl_check_special_section hook (implemented only by
the alpha and sparc backends) in order to determine whether an
executable+writable section must be flagged or not.  In both cases the
hook will fail analyzing eu-strip debuginfo files (as they should,
because debuginfo files are broken ;).

This patch just modifies elflint to not use the hook when -d is
specified in the command-line.  This fixes the test in sparc-* and
sparc64-* targets (and presumably in alpha* targets too).

Additionaly, the patch checks that the type of WE sections in
debuginfo files is NOBITS.

Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
8 years agoelflint: Check relro flags are a subset of the load segment.
Mark Wielaard [Tue, 13 Oct 2015 14:02:10 +0000 (16:02 +0200)]
elflint: Check relro flags are a subset of the load segment.

If the RELRO segment doesn't fully overlap with the load segment then the
load segment might have more flags sets. This happens for example on sparc
when the .plt, which is executable, is also part of the load segment that
RELRO covers.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agolibelf: Only use posix_fallocate when using mmap. Ignore unsupported errors.
Mark Wielaard [Mon, 5 Oct 2015 15:32:29 +0000 (17:32 +0200)]
libelf: Only use posix_fallocate when using mmap. Ignore unsupported errors.

Don't use posix_fallocate when not using mmap. It is enough to ftruncate
the file to the right size. pwrite will report an error if there is no
disk space left. And on file systems that don't support fallocate it
might duplicate writes in that case. When using posix_fallocate do ignore
most errors. Other libc implementations don't guarantee the call actually
works always and even with glibc there might be an unexpected error from
the fallback code when the file system doesn't support fallocate. That is
pretty nasty since we might get a SIGBUS in that case when writing to the
mmapped memory. But the chance of that happening is very small.  And will
normally never happen with glibc. So only report an error when
posix_fallocate reports ENOSPC.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoldlex: Fix sign-compare warning, suppress -Wstack-usage.
Mark Wielaard [Wed, 7 Oct 2015 11:58:26 +0000 (13:58 +0200)]
ldlex: Fix sign-compare warning, suppress -Wstack-usage.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoconfig: Use ARFLAGS 'cr'.
Mark Wielaard [Wed, 7 Oct 2015 11:43:32 +0000 (13:43 +0200)]
config: Use ARFLAGS 'cr'.

By default automake uses ARFLAGS cru. 'u' is an optimization that
makes sure files are only added to the archive when they are newer
than the version already in the .a file. This optimization doesn't
work when ar is deterministic by default because then it doesn't
record timestamps in the archive. Deterministic ar is the default
now on various distributions causing multiple warnings like:

  ar: `u' modifier ignored since `D' is the default (see `U')

To suppress these warnings drop the 'u' flag.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoconfigure.ac: Add AM_SILENT_RULES([yes])
Mark Wielaard [Wed, 7 Oct 2015 11:37:56 +0000 (13:37 +0200)]
configure.ac: Add AM_SILENT_RULES([yes])

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoTrust AC_SYS_LARGEFILE to provide large file support
Josh Stone [Fri, 9 Oct 2015 17:10:37 +0000 (10:10 -0700)]
Trust AC_SYS_LARGEFILE to provide large file support

AC_SYS_LARGEFILE defines _FILE_OFFSET_BITS in config.h if needed for
LFS, and this automatically maps things like open to open64.  But quite
a few places used explicit 64-bit names, which won't work on platforms
like FreeBSD where off_t is always 64-bit and there are no foo64 names.
It's better to just trust that AC_SYS_LARGEFILE is doing it correctly.

But we can verify this too, as some file could easily forget to include
config.h.  The new tests/run-lfs-symbols.sh checks all build targets
against lfs-symbols (taken from lintian) to make sure everything was
implicitly mapped to 64-bit variants when _FILE_OFFSET_BITS is set.

Signed-off-by: Josh Stone <jistone@redhat.com>
8 years agoUse seek+read instead of pread to read from /dev/$$/mem files.
Jose E. Marchesi [Fri, 9 Oct 2015 10:35:27 +0000 (12:35 +0200)]
Use seek+read instead of pread to read from /dev/$$/mem files.

pread[64] always returns EINVAL when negative offsets are used.
read+seek allows us to read in-memory vdso objects mapped high in the
address space.

Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
8 years agoMove recursive nested function to file scope.
Chih-Hung Hsieh [Thu, 8 Oct 2015 18:05:23 +0000 (11:05 -0700)]
Move recursive nested function to file scope.

Prepare src/ld.c to compile with clang.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
8 years agotests: Rename argument from check to statement in elfshphehdr.c.
Mark Wielaard [Fri, 9 Oct 2015 10:07:27 +0000 (12:07 +0200)]
tests: Rename argument from check to statement in elfshphehdr.c.

Some older compilers warn about a function and argument name being equal.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agostrip: Only sanity check symbols to not discarded sections for debug file.
Mark Wielaard [Sun, 4 Oct 2015 21:47:47 +0000 (23:47 +0200)]
strip: Only sanity check symbols to not discarded sections for debug file.

We can only sanity check the symbols to discarded sections when creating a
debug file. Otherwise we won't keep track of debug_data. This can trigger
erroneously when there are relocation symbols in the symtab for a .debug
section but we are not putting those symbols in a separate .debug file.

Adjust run-strip-test.sh to always run in-place strip size check even
for ET_REL files. Before this fix the sanity check would trigger for
some ET_REL files because they contained such relocation symbols to
.debug sections (but debug_data would be NULL because -f wasn't used).

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoAllocate exact amount of bytes for phdrs and shdrs.
Mark Wielaard [Wed, 7 Oct 2015 22:16:03 +0000 (00:16 +0200)]
Allocate exact amount of bytes for phdrs and shdrs.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoDo without union of variable length arrays.
Chih-Hung Hsieh [Tue, 6 Oct 2015 22:53:15 +0000 (15:53 -0700)]
Do without union of variable length arrays.

Prepare to compile with clang.

A union like
  { T32 a32[n]; T64 a64[n]; } u;
is expanded to
  size_t nbytes = n * MAX(sizeof(T32), sizeof(T64));
  void *data = malloc(nbytes);
  T32 (*a32)[n] = data;
  T64 (*a64)[n] = data;

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
8 years agoImprove AM_SILENT_RULES coverage
Josh Stone [Mon, 5 Oct 2015 18:04:15 +0000 (11:04 -0700)]
Improve AM_SILENT_RULES coverage

Note, elfutils does not explicitly enable AM_SILENT_RULES.  It's only
available starting from automake 1.11, but starting from automake 1.13
silent rules are always generated, defaulting to verbose.  $(AM_V_foo)
additions should be no-ops on systems that don't support silent rules.

To be silent, use "./configure --enable-silent-rules" or "make V=0".

Signed-off-by: Josh Stone <jistone@redhat.com>
8 years agosparc: support for the check_object_attribute ebl hook.
Jose E. Marchesi [Tue, 6 Oct 2015 14:20:40 +0000 (16:20 +0200)]
sparc: support for the check_object_attribute ebl hook.

This makes elfutils based utilities to be aware of the ELF attribute
tags defined in sparc targets.

Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
8 years agoUse -fPIC instead of -fpic when generating PIC code.
Jose E. Marchesi [Mon, 5 Oct 2015 15:36:30 +0000 (17:36 +0200)]
Use -fPIC instead of -fpic when generating PIC code.

This avoids relocation overflows in sparc/sparc64 targets while
linking,  where the reachable data using -fpic is only 4kb.

Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
8 years agoUse -fPIC instead of -fpic when generating PIC code.
Jose E. Marchesi [Mon, 5 Oct 2015 15:36:30 +0000 (17:36 +0200)]
Use -fPIC instead of -fpic when generating PIC code.

This avoids relocation overflows in sparc/sparc64 targets while
linking,  where the reachable data using -fpic is only 4kb.

Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
8 years agosparc: fix the extraction of relocation IDs from r_type fields.
Jose E. Marchesi [Mon, 5 Oct 2015 15:36:33 +0000 (17:36 +0200)]
sparc: fix the extraction of relocation IDs from r_type fields.

This patch adds support for a RELOC_TYPE_ID transform macros that
backends can use before including common-reloc.c.  The sparc backend
uses this in order to extract the relocation IDs from r_type fields.
In this target the most significative 24 bits of r_type are used to
store an additional addend in some relocation types.

Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
8 years agosparc: add some missing relocation types.
Jose E. Marchesi [Mon, 5 Oct 2015 15:36:32 +0000 (17:36 +0200)]
sparc: add some missing relocation types.

This adds three missing relocation types in sparc targets: WDISP10,
JMP_IREL and IRELATIVE.

Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
8 years agounstrip: Update sh_info when SH_INFO_LINK_P not just when SHF_INFO_LINK set
Mark Wielaard [Fri, 2 Oct 2015 14:31:36 +0000 (16:31 +0200)]
unstrip: Update sh_info when SH_INFO_LINK_P not just when SHF_INFO_LINK set

SHF_INFO_LINK is not consistently set when sh_info is actually a section
index reference. Use SH_INFO_LINK_P to check whether to update the sh_info
value. SH_INFO_LINK_P also checks the section type to know whether or not
sh_info is meant as section index.

Found by run-strip-strmerge.sh test with older binutils.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoHandle merged strtab/shstrtab string tables in strip and unstrip.
Mark Wielaard [Tue, 11 Aug 2015 19:38:38 +0000 (21:38 +0200)]
Handle merged strtab/shstrtab string tables in strip and unstrip.

ELF files can share the section header string table (e_shstrndx) with
the symtab .strtab section. That might in some cases save a bit of space
since symbols and sections might share some (sub)strings. To handle that
eu-strip just needs to not unconditionally remove the .shstrtab section
(it will be properly marked as used/unused as needed). eu-unstrip needs
to make sure the section names are added to the strtab if it decides to
rewrite that section. Also makes sure that eu-strip won't move around
a SHT_NOBITS section that has SHF_ALLOC set. Although it is allowed to
move such sections around, there is no benefit. And some tools might
expect no allocated section to move around, not even a nobits section.
It also makes it harder to do "roundtripping" sanity checks that make
sure splitting a file with eu-strip and then reconstructed with eu-unstrip
produce the same ELF file (as is done in the new run-strip-strmerge.sh).

Introduces a somewhat large test generator elfstrmerge.c that will
hopefully turn into a more generic string table merger program.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agolibelf: Always update e_version and e_shentsize in elf_update.
Mark Wielaard [Tue, 29 Sep 2015 15:04:11 +0000 (17:04 +0200)]
libelf: Always update e_version and e_shentsize in elf_update.

When e_version is EV_NONE we should set it to EV_CURRENT like we do for
the EI_VERSION and like we set EI_DATA to the correct byte order when set
to ELFDATANONE.  Likewise we should always set e_shentsize like we do for
e_phentsize, not just when ELF_F_LAYOUT isn't set.

Add a new elfshphehdr testcase to check the above.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoMove 4 libdwfl nested functions.
Chih-Hung Hsieh [Fri, 18 Sep 2015 18:25:13 +0000 (11:25 -0700)]
Move 4 libdwfl nested functions.

Now they should compile with clang.

Used local variables are passed to new file scope functions
as constant parameters, or pointers, or embedded in a
'state' structure.

One simple function "report" is changed to a macro.
It triggers a gcc false positive -Werror=maybe-uninitialized,
so the local variables are explicitly initialized.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
8 years agoUpdate Ukrainian translation
Yuri Chornoivan [Sat, 26 Sep 2015 13:52:35 +0000 (16:52 +0300)]
Update Ukrainian translation

https://bugzilla.redhat.com/show_bug.cgi?id=1266682

Signed-off-by: Yuri Chornoivan <yurchor@ukr.net>
8 years agoProperly mark all internal function definitions.
Mark Wielaard [Wed, 23 Sep 2015 18:44:06 +0000 (20:44 +0200)]
Properly mark all internal function definitions.

Since we banned old style function definitions GCC is able to diagnose
function definitions that don't match the function declaration:

  elf32_getehdr.c:78: error: conflicting types for ‘__elf64_getehdr_wrlock’
  libelfP.h:498: note: previous declaration of ‘__elf64_getehdr_wrlock’

This happens on i386 because there internal functions are marked with:

  # define internal_function __attribute__ ((regparm (3), stdcall))

Make sure all internal function declarations and definitions are marked
with internal_function.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoRemove old-style function definitions.
Mark Wielaard [Tue, 22 Sep 2015 20:27:01 +0000 (22:27 +0200)]
Remove old-style function definitions.

We already require -std=gnu99 and old-style function definitions might
hide some compiler warnings.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoUpdate dl-hash.h from glibc.
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>
8 years agolibdw: Don't reassign result pointer in dwarf_peel_type.
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>
8 years agoRemove redundant NULL tests.
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>
8 years agolibdwfl: Make dwfl_linux_proc_attach work even without any Dwfl_Modules.
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>
8 years agoInitialize variable before use.
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>
8 years agolibdwfl: Replace abs with llabs for int64_t values.
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>
8 years agotests: Init local variable enctype before use in print_base_type varlocs.c.
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>
8 years agotests: Remove unused static const variables in md5-sha1-test.c.
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>
8 years agolibdw: Add const declaration to getlocations_addr locs.
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>
8 years agoReplace some K&R function definitions with ansi-C definitions.
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>
8 years agoReplace printf %Z length modifier with %z.
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>
8 years agobackends: Use ebl->class consistently in sparc backend.
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>
8 years agoreadelf: handle_core_item large right shift triggers undefined behaviour.
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>
8 years agolibdw: Add DW_LANG_Haskell.
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>
8 years agoelflint: Add gnuld check when a NOBITS section falls inside a segment.
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>
8 years agotests: Add a testcase for dwfl debuginfo-path with separate bin/debug dirs.
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>
8 years agoFix finding split debug info files not located by the build-id mechanism
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>
8 years agospec: Provide default-yama-scope.
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>
8 years agounstrip: Handle debuginfo files with missing SHF_INFO_LINK section flags.
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>
9 years agoignore more generated files
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>
9 years agoFix/improve .gitignore
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>
9 years agotests: skip run-deleted.sh when dwfl_linux_proc_attach is not implemented
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>
9 years agotests: dwfl-bug-fd-leak: Guard against null module addresses
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>
9 years agostrings: Define MAP_POPULATE if not defined already
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>
9 years agonm: First call elf_getdata, then allocate memory.
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>
9 years agotests: Mark an unused argument as such
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>
9 years agoReduce scope of some includes
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>
9 years agoPrepare 0.163 release. elfutils-0.163
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>
9 years agofindtextrel: Don't leak memory in process_file.
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>
9 years agoreadelf: Make sure phdr2_mem lifetime/scope equals phdr2 pointer.
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>
9 years agolibdwfl: Don't leak fname if file is main file by another name in try_open.
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>
9 years agoreadelf: Don't leak memory on failure path in handle_gnu_hash.
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>
9 years agolibelf: Don't leak memory on failure paths in elf_updatefile.
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>
9 years agoelflint: Only check the PT_TLS phdr if it actually exists, warn otherwise.
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>
9 years agolibdw: Make sure the default page size is big enough to hold a Dwarf.
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>
9 years agonm: Fix typo in size check to determine whether we stack allocated memory.
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>
9 years agostrings: Handle failure of getting section name on bogus section data.
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>
9 years agolibelf: Check symbol section header exists before use in nlist.
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>
9 years agolibdwfl: Check symbol section exists and has a sane entsize in find_symtab.
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>
9 years agolibdw: Not leak memory on error in dwarf_getpubnames.
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>
9 years agolibdw: Detect dwarf_formudata errors in dwarf_getmacros.
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>
9 years agolibelf: Always call ftruncate before posix_fallocate to set the right size.
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>
9 years agopo/*.po: Regenerate.
Mark Wielaard [Sun, 14 Jun 2015 22:06:27 +0000 (00:06 +0200)]
po/*.po: Regenerate.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
9 years agoUpdated Polish translation
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>
9 years agoUpdated POTFILES.in
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>
9 years agolibebl: SHT_(INIT|FINI|PREINIT)_ARRAY are valid targets for relocation.
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>
9 years agoelfutils.spec.in (devel): Include known-dwarf.h and version.h. elfutils-0.162
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>
9 years agoPrepare 0.162 release.
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>
9 years agoaddr2line: Fix memory leak in print_dwarf_function.
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>
9 years agostrip: Just admit we don't support stripping ar archives for now.
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>
9 years agolibdw: Initialize dirarray early in read_srclines.
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>
9 years agoconfigure: Add check for gcc -Wstack-usage.
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>
9 years agolibdwfl: Fix memory leak in find_debuginfo_in_path.
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>
9 years agolibdwfl: Fix memory leak in cache_sections.
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>
9 years agolibelf: Make sure elf_getdata_rawchunk returns aligned data.
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>
9 years agolibelf: Make sure conversion functions work on aligned data for type.
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>
9 years agoUkrainian translation update
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>
9 years agoUkrainian translation update
Yuri Chornoivan [Tue, 9 Sep 2014 16:57:00 +0000 (19:57 +0300)]
Ukrainian translation update

Signed-off-by: Yuri Chornoivan <yurchor@ukr.net>
9 years agolibdw: Initialize filelist early in read_srclines.
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>
9 years agolibdwfl: Report core module segment even when NT_FILE build-id doesn't match.
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>
9 years agolibelf: Check e_shoff alignment before direct access of Elf(32|64)_Shdr.
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>
9 years agolibelf: Split checks for ehdr and shdr, drop phdr check in file_read_elf.
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>
9 years agolibdwfl: Fix memory leak in __libdwfl_open_by_build_id.
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>
9 years agoDefine MODVERSION in a more reproducable way.
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>
9 years agoFix sanitize-undefined config check. Don't ALLOW_UNALIGNED when checking.
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>
9 years agolibdwfl: Don't assume auxv or r_debug data is properly aligned in link_map.
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>
9 years agolibelf: Fix possible unbounded stack usage in load_shdr_wrlock.
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>
9 years agolibelf: Fix possible unbounded stack usage in getphdr_wrlock.
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>
9 years agolibelf: Fix unbounded stack usage in elf_getarsym for !ALLOW_UNALIGNED case.
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>
9 years agoelfcmp: Don't call memcmp with possible NULL d_buf.
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>
9 years agolibelf: Don't call memmove with possible NULL buffer.
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>
9 years agolibelf: Don't call mempcpy with possible NULL d_buf.
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>