Commit Graph

1748 Commits

Author SHA1 Message Date
Mark Wielaard e2cf85cd35 libdw: Make sure Ebl is always freed from cfi frame cache.
libdwfl sets the Dwfl_Module Ebl for the eh_cfi and dwarf_cfi cache to
save a bit of memory. It also calls ebl_closebackend on the ebl to free
it. The Dwarf_CFI never frees the Ebl in the cache, even when it opened
one itself. This means that if only libdw calls are used to access the
Dwarf_CFI the Ebl might be leaked.

Always destroy the Dwarf_CFI cache Ebl in __libdw_destroy_frame_cache.
And in __libdwfl_module_free clear the Dwarf_CFI Ebl if it is the
Dwfl_Module Ebl before calling dwarf_cfi_end and dwarf_end.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2015-11-27 14:41:51 +01:00
Dmitry V. Levin b47fb2366f libdw: initialize state early in read_srclines
Starting with commit f8443bd09f,
we might jump to "out" on error before initialization of "state".
Initialize "state" early to fix this issue.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2015-11-16 17:11:34 +01:00
Chih-Hung Hsieh f8443bd09f No nested functions in dwarf_getsrclines.
Move nested functions in libdw/dwarf_getsrclines.c to file scope.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
2015-11-13 22:17:46 +01:00
Chih-Hung Hsieh 6bbea3de41 Move nested functions in gzip.c to file scope.
* libdwfl/gzip.c should now compile with clang.
  All local variables used by nested functions are
  passed in an unzip_state structure.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
2015-11-13 21:54:09 +01:00
Chih-Hung Hsieh b926e56b7a No nested function in dwarf_getscopevar to file scope.
Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
2015-11-13 18:06:12 +01:00
Chih-Hung Hsieh 3148f5cd3d Move nested functions in dwfl_module_getsrc_file.c.
* Nested functions in this file are moved to file scope
  to compile with clang. Extra parameters are added to pass
  local variables.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
2015-11-03 23:33:10 +01:00
Chih-Hung Hsieh ae09ca9af1 Move nested functions in frame_unwind.c.
* Nested functions 'pop' and 'push' in libdwfl/frame_unwind.c
  are moved to file scope. Used local variables are passed in
  struct eval_stack.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
2015-11-03 16:30:44 +01:00
Chih-Hung Hsieh 1ac2041156 Move nested functions in dwfl_module.c
* Nested functions in this file are moved to file scope
  to compile with clang. Extra parameters are added to pass
  local variables.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
2015-11-03 15:54:25 +01:00
Chih-Hung Hsieh 860d4312e6 Move nested functions in backends to file scope.
* backends/aarch64_regs.c and backends/ia64_retval.c
  should now compile with clang.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
2015-11-03 15:20:22 +01:00
Mark Wielaard 528cb45fc9 Make zlib mandatory.
Explicitly link libelf and libdw with -lz.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2015-10-26 13:52:31 +01:00
Mark Wielaard 5eb3e901f9 elf.h: Update from glibc. Add section compression constants and structures.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
2015-10-22 23:25:55 +02:00
Jose E. Marchesi 1ed7195ea8 libelf: use the right size when preading in[0].sh_size
Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
2015-10-22 23:09:56 +02:00
Chih-Hung Hsieh 34bb96a2c1 Move nested functions in libdw/cfi.c to file scope.
* No nested functions to compile with clang/llvm.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
2015-10-22 22:43:42 +02:00
Chih-Hung Hsieh 11659f2529 Move nested functions in libdwelf.
* Move nested functions to file scope
  in libdwelf/dwelf_elf_gnu_build_id.c
  to compile with clang.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
2015-10-22 22:43:42 +02:00
Chih-Hung Hsieh 239d859169 Move nested functions in libelf.
* Move nested functions to file scope
  in libelf/elf_begin.c and elf32_updatefile.c
  to compile with clang.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
2015-10-22 22:43:42 +02:00
Mark Wielaard a1e17a2551 elflint: Don't check shdr or TLS symbol offsets against debuginfo phdrs.
In debuginfo files the phdrs file offsets match those of the original ELF
file. So the section header file offsets and the TLS symbol value offset
in debuginfo files cannot be sanity checked against the phdrs file offset.

The issue can be triggered with run-strip-strmerge.sh test when configured
with --enable-gcov. Which will insert a .tbss section and TLS symbols that
trigger the above checks.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2015-10-16 21:19:05 +02:00
Mark Wielaard 0479e127b1 Regenerate .po files.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
2015-10-16 13:28:03 +02:00
Mark Wielaard 61c25a1c5b elflint: Reject mergable string sections as relocation target.
Mergable sections can be the target of a relocation, but only if they
contain items of the same size. So only reject mergable string sections
as target of a relocation section.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2015-10-16 13:15:01 +02:00
Mark Wielaard fd2e84cb31 ppc: ppc_check_special_symbol): Also allow _SDA_BASE_ in .data section.
The Small Data Area Base normally points to .sdata, in which case we
check it is at an offset of 0x8000.  It might however fall in the
.data section, in which case we cannot check the offset.  The size always
should be zero.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2015-10-16 13:11:32 +02:00
Mark Wielaard 9bcd3cbdbc tests: Add AM_LDFLAGS to dwfl_proc_attach_LDFLAGS.
We want to be sure the libelf.so under test is picked up.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
2015-10-16 12:06:38 +02:00
Mark Wielaard d11eea4add Prepare 0.164 release.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
2015-10-15 18:38:29 +02:00
Josh Stone b1d0b0fc7e 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>
2015-10-14 09:29:27 -07:00
Jose E. Marchesi bc119074c2 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>
2015-10-13 19:42:19 +02:00
Mark Wielaard b9be1434ff 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>
2015-10-13 16:02:10 +02:00
Mark Wielaard ae1e85ea0b 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>
2015-10-12 12:44:49 +02:00
Mark Wielaard 9b9666838e ldlex: Fix sign-compare warning, suppress -Wstack-usage.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
2015-10-12 12:22:59 +02:00
Mark Wielaard 7b74830ec6 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>
2015-10-12 12:22:59 +02:00
Mark Wielaard c04f491fa2 configure.ac: Add AM_SILENT_RULES([yes])
Signed-off-by: Mark Wielaard <mjw@redhat.com>
2015-10-12 12:22:59 +02:00
Josh Stone 3425454a10 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>
2015-10-09 10:10:37 -07:00
Jose E. Marchesi f17d101232 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>
2015-10-09 15:42:34 +02:00
Chih-Hung Hsieh 57fa86e08b Move recursive nested function to file scope.
Prepare src/ld.c to compile with clang.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
2015-10-09 12:19:42 +02:00
Mark Wielaard c53857b6a8 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>
2015-10-09 12:07:27 +02:00
Mark Wielaard 3a45dbbe7e 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>
2015-10-09 11:22:00 +02:00
Mark Wielaard 86ed7f7f53 Allocate exact amount of bytes for phdrs and shdrs.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
2015-10-08 08:43:42 +02:00
Chih-Hung Hsieh 7eff36d5da 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>
2015-10-07 22:44:41 +02:00
Josh Stone daee4714ee 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>
2015-10-06 17:50:10 -07:00
Jose E. Marchesi 0e3ce39c8f 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>
2015-10-06 23:54:57 +02:00
Jose E. Marchesi 6a20e20ea9 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>
2015-10-06 23:54:34 +02:00
Jose E. Marchesi 133509fa40 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>
2015-10-06 23:40:19 +02:00
Jose E. Marchesi 22843755fa 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>
2015-10-06 00:03:07 +02:00
Jose E. Marchesi ee00afbb2b 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>
2015-10-05 23:58:35 +02:00
Mark Wielaard 2e08450276 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>
2015-10-05 21:58:59 +02:00
Mark Wielaard df7dfab451 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>
2015-10-05 21:55:51 +02:00
Mark Wielaard 3adda3ce2a 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>
2015-10-05 21:50:51 +02:00
Chih-Hung Hsieh a3a76e3615 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>
2015-10-05 16:49:16 +02:00
Yuri Chornoivan 6d30e4b824 Update Ukrainian translation
https://bugzilla.redhat.com/show_bug.cgi?id=1266682

Signed-off-by: Yuri Chornoivan <yurchor@ukr.net>
2015-10-02 17:14:22 +02:00
Mark Wielaard d8698e55cb 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>
2015-09-23 20:49:54 +02:00
Mark Wielaard 1ccdfb683a 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>
2015-09-23 15:50:55 +02:00
Mark Wielaard e260d79d73 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>
2015-09-23 15:50:00 +02:00
Mark Wielaard dd8bd91f39 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>
2015-09-15 11:00:50 +02:00