Mark Wielaard [Thu, 19 Nov 2015 11:37:08 +0000 (12:37 +0100)]
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>
Dmitry V. Levin [Mon, 16 Nov 2015 15:11:23 +0000 (18:11 +0300)]
libdw: initialize state early in read_srclines
Starting with commit
f8443bd09f8a8d3d84a63e5ce206a218e57dff7a,
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>
Chih-Hung Hsieh [Tue, 13 Oct 2015 22:26:14 +0000 (15:26 -0700)]
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>
Chih-Hung Hsieh [Fri, 13 Nov 2015 19:48:07 +0000 (11:48 -0800)]
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>
Chih-Hung Hsieh [Tue, 13 Oct 2015 22:26:14 +0000 (15:26 -0700)]
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>
Chih-Hung Hsieh [Wed, 21 Oct 2015 22:44:56 +0000 (15:44 -0700)]
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>
Chih-Hung Hsieh [Thu, 22 Oct 2015 00:12:44 +0000 (17:12 -0700)]
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>
Chih-Hung Hsieh [Wed, 21 Oct 2015 22:44:56 +0000 (15:44 -0700)]
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>
Chih-Hung Hsieh [Wed, 21 Oct 2015 21:36:25 +0000 (14:36 -0700)]
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>
Mark Wielaard [Fri, 16 Oct 2015 21:07:12 +0000 (23:07 +0200)]
Make zlib mandatory.
Explicitly link libelf and libdw with -lz.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 14 Oct 2015 15:19:19 +0000 (17:19 +0200)]
elf.h: Update from glibc. Add section compression constants and structures.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Jose E. Marchesi [Tue, 20 Oct 2015 14:22:08 +0000 (16:22 +0200)]
libelf: use the right size when preading in[0].sh_size
Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
Chih-Hung Hsieh [Wed, 14 Oct 2015 18:59:53 +0000 (11:59 -0700)]
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>
Chih-Hung Hsieh [Wed, 14 Oct 2015 17:15:48 +0000 (10:15 -0700)]
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>
Chih-Hung Hsieh [Wed, 14 Oct 2015 02:06:21 +0000 (19:06 -0700)]
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>
Mark Wielaard [Fri, 16 Oct 2015 19:19:05 +0000 (21:19 +0200)]
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>
Mark Wielaard [Fri, 16 Oct 2015 11:28:03 +0000 (13:28 +0200)]
Regenerate .po files.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 16 Oct 2015 11:15:01 +0000 (13:15 +0200)]
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>
Mark Wielaard [Fri, 16 Oct 2015 10:26:27 +0000 (12:26 +0200)]
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>
Mark Wielaard [Fri, 16 Oct 2015 10:06:34 +0000 (12:06 +0200)]
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
Mark Wielaard [Tue, 22 Sep 2015 12:20:45 +0000 (14:20 +0200)]
Update dl-hash.h from glibc.
Our dl-hash.h implementation originally came from, or was written at the
same time as, the glibc implementation. At some point (around 9 years ago)
they diverged and the elfutils version got an updated copyright header.
The glibc version saw various updates/optimizations. Just treat the file
like we do for elf.h and copy it whenever the glibc version is updated.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 15 Sep 2015 08:55:10 +0000 (10:55 +0200)]
libdw: Don't reassign result pointer in dwarf_peel_type.
GCC6 will warn about the reassignement of the nonnull result pointer.
The reassignment is indeed a little questionable. The compiler cannot
see that the pointer will not actually be reassigned since the function
will just return the same pointer value except when the dwarf_formref_die
function fails. In which case we don't use the result anymore. So the
compiler has to pessimistically assume the pointer will need to be
reloaded in the loop every time. Help the compiler generate slightly
better code by just checking whether the function fails directly instead
of reusing the pointer value for this.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Chih-Hung Hsieh [Wed, 9 Sep 2015 19:32:07 +0000 (12:32 -0700)]
Remove redundant NULL tests.
GCC6 and Clang give warnings on redundant NULL tests of parameters
that are declared with __nonnull_attribute__.
Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 7 Sep 2015 10:52:12 +0000 (12:52 +0200)]
libdwfl: Make dwfl_linux_proc_attach work even without any Dwfl_Modules.
dwfl_linux_proc_attach depended on a Dwfl_Module with the correct
ELF header already being available. That isn't really necessary since
when we attach we have the main exe ELF file available. Just use that
to make dwfl_linux_proc_attach always work.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Chih-Hung Hsieh [Wed, 9 Sep 2015 20:59:19 +0000 (13:59 -0700)]
Initialize variable before use.
Some compiler does not know that error function never returns.
Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Chih-Hung Hsieh [Fri, 4 Sep 2015 19:04:11 +0000 (12:04 -0700)]
libdwfl: Replace abs with llabs for int64_t values.
Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Chih-Hung Hsieh [Fri, 4 Sep 2015 19:04:11 +0000 (12:04 -0700)]
tests: Init local variable enctype before use in print_base_type varlocs.c.
clang compiler static analysis failed.
Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Chih-Hung Hsieh [Fri, 4 Sep 2015 19:04:11 +0000 (12:04 -0700)]
tests: Remove unused static const variables in md5-sha1-test.c.
Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Chih-Hung Hsieh [Fri, 4 Sep 2015 19:04:11 +0000 (12:04 -0700)]
libdw: Add const declaration to getlocations_addr locs.
And change K&R C function definition to ansi, which prevented GCC from
seeing that callers passed in const arguments.
Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Chih-Hung Hsieh [Fri, 4 Sep 2015 19:04:11 +0000 (12:04 -0700)]
Replace some K&R function definitions with ansi-C definitions.
Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Chih-Hung Hsieh [Fri, 4 Sep 2015 17:13:02 +0000 (10:13 -0700)]
Replace printf %Z length modifier with %z.
%Z is a GNU extension predating the ISO C99 %z modifier supported by
libc5 and no longer recommended.
Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 3 Sep 2015 10:50:54 +0000 (12:50 +0200)]
backends: Use ebl->class consistently in sparc backend.
sparc_init would check the ELF class to register to correct core_note
handler. But sparc_register_info would check the ELF machine to determine
whether the register set was 32 or 64 bits. This caused some confusion
and assertion failures in readelf when printing core notes where the
sparc machine and class didn't seem to match up. Check the ELF class
in both sparc_unit and sparc_register_info to give consistent results.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 3 Sep 2015 08:50:58 +0000 (10:50 +0200)]
readelf: handle_core_item large right shift triggers undefined behaviour.
The problem is this:
int n = ffs (w);
w >>= n;
The intent is to shift away up to (and including) the first least
significant bit in w. But w is an unsigned int, so 32 bits. And the
least significant bit could be bit 32 (ffs counts from 1). Unfortunately
a right shift equal to (or larger than) the length in bits of the left
hand operand is undefined behaviour. We expect w to be zero afterwards.
Which would terminate the while loop in the function. But since it is
undefined behaviour anything can happen. In this case, what will actually
happen is that w is unchanged, causing an infinite loop...
gcc -fsanitize=undefined will catch and warn about this when w = 0x80000000
https://bugzilla.redhat.com/show_bug.cgi?id=1259259
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 25 Aug 2015 13:11:01 +0000 (15:11 +0200)]
libdw: Add DW_LANG_Haskell.
See http://www.dwarfstd.org/ShowIssue.php?issue=120218.1
GHC emits this language code (0x18).
Also updated https://fedorahosted.org/elfutils/wiki/DwarfExtensions
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 11 Aug 2015 22:11:26 +0000 (00:11 +0200)]
elflint: Add gnuld check when a NOBITS section falls inside a segment.
gnuld has a really bad bug where it can place a NOBITS section inside
a PT_LOAD segment. Normally that would not work. But it also makes sure
that the contents of the file is all zeros. So in practice it is actually
a PROGBITS section with all zero data. Except that other tools will think
there is an unused gap in the ELF file after the NOBITS section.
Recognize and check this pattern in elflint when --gnu is given.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Fri, 14 Aug 2015 13:50:12 +0000 (15:50 +0200)]
tests: Add a testcase for dwfl debuginfo-path with separate bin/debug dirs.
Reuse the run-addr2line-i-test.sh testfile-inlines testfile, but
first strip the debuginfo and put the binary and separate debuginfo
file in different roots. Check that --debuginfo-path still finds
the debug file.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Dodji Seketeli [Thu, 13 Aug 2015 13:59:41 +0000 (15:59 +0200)]
Fix finding split debug info files not located by the build-id mechanism
[This bug has been found by using elfutils in the context of
libabigail. The initial bug report is
https://sourceware.org/bugzilla/show_bug.cgi?id=18792. The
interesting comments start at is
https://sourceware.org/bugzilla/show_bug.cgi?id=18792#c4]
suppose we have a debug info file that is located at a
/prefix1/usr/lib/debug/prefix2/libfoo.so. Suppose also that the debug
info describes a binary that is located at /prefix1/prefix2/libfoo.so
Suppose the debug_link property inside the binary
/prefix1/prefix2/libfoo.so correctly contains the string "libfoo.so"
that designates the name of the debug info file.
The problem is, when find_debuginfo_in_path() is called with its
file_name parameter set to "/prefix1/prefix2/libfoo.so" and
mod->dwfl->callbacks->debuginfo_path set to
"/prefix1/lib/debug/", it fails to locate the debug
info file libfoo.so under "/prefix1/usr/lib/debug/prefix2/".
This patch fixes the issue by making find_debuginfo_in_path() try all
the sub-strings of "/prefix1/prefix2/libfoo.so "under"
"/prefix1/usr/lib/debug/", to find libfoo.so. That is, it tries, in
order:
- /prefix1/usr/lib/debug/prefix1/prefix2/libfoo.so
- /prefix1/usr/lib/debug/prefix2/libfoo.so <-- and boom, it finds it!
Note that the patch tries the variations between the two candidates
above too.
The patch uses a goto. I dislike gotos like anyone else, but then
here, not using this would imply a bigger change of the logic of that
function. So I am proposing the scheme based on the goto instead.
* libdwfl/find-debuginfo.c (find_debuginfo_in_path): Try to locate
the debug info file named debuglink_file under
mod->dwfl->callbacks->debuginfo_path, by looking at the set of
sub-trees under mod->dwfl->callbacks->debuginfo_path which is
common to the set of non-absolute parent trees of file_name.
https://bugzilla.redhat.com/show_bug.cgi?id=1253367
Signed-off-by: Dodji Seketeli <dodji@seketeli.org>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 4 Aug 2015 10:20:20 +0000 (12:20 +0200)]
spec: Provide default-yama-scope.
When yama is enabled in the kernel it might be used to filter any user
space access which requires PTRACE_MODE_ATTACH like ptrace attach, access
to /proc/PID/{mem,personality,stack,syscall}, and the syscalls
process_vm_readv and process_vm_writev which are used for interprocess
services, communication and introspection (like synchronisation, signaling,
debugging, tracing and profiling) of processes.
These are precisely the things that libdw dwfl and ebl backends rely on.
So make sure they don't mysteriously fail in such cases by providing the
default yama scope sysctl value.
This is implemented as a separate subpackage that just provides this
functionality so other packages that don't directly rely on elfutils-libs
can also just Requires: default-yama-scope to function properly.
https://bugzilla.redhat.com/show_bug.cgi?id=1209492#c69
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 29 Jul 2015 15:51:27 +0000 (17:51 +0200)]
unstrip: Handle debuginfo files with missing SHF_INFO_LINK section flags.
With GCC 5 there might be a .rela.plt section with SHF_INFO_LINK set.
Buggy binutils objdump might strip it from the section in the debug file.
Ignore such differences for relocation sections and put the flag back
if necessary.
Also improve the error message a little by only discarding the already
matched sections if there is an prelink undo section. Otherwise we will
report all sections as not matching if the file wasn't prelinked instead
of just the non-matching sections.
New testfiles generated by gcc5 and binutils objdump added.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mike Frysinger [Wed, 29 Jul 2015 14:36:02 +0000 (10:36 -0400)]
ignore more generated files
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Pino Toscano [Sat, 11 Jul 2015 07:55:40 +0000 (09:55 +0200)]
Fix/improve .gitignore
Fill the .gitignore with more generated files, such as:
- test executables
- results of the automake testing framework (*.log and *.trs)
- sources generated by flex and bison
- generated *.mnemonics files in libcpu
- the helper libcpu/i386_gendis tool
- *.so.1 symlinks
Also, anchor existing filenames to their location when
builddir==srcdir.
Signed-off-by: Pino Toscano <toscano.pino@tiscali.it>
Pino Toscano [Sat, 27 Jun 2015 17:23:01 +0000 (19:23 +0200)]
tests: skip run-deleted.sh when dwfl_linux_proc_attach is not implemented
If the current OS does not implement dwfl_linux_proc_attach (which
currently only Linux does) then skip this test, as "stack" uses that
API for attaching to a running process.
Signed-off-by: Pino Toscano <toscano.pino@tiscali.it>
Pino Toscano [Sat, 27 Jun 2015 16:33:37 +0000 (18:33 +0200)]
tests: dwfl-bug-fd-leak: Guard against null module addresses
Do not crash if there is no module for the given address.
Signed-off-by: Pino Toscano <toscano.pino@tiscali.it>
Pino Toscano [Sat, 27 Jun 2015 16:07:01 +0000 (18:07 +0200)]
strings: Define MAP_POPULATE if not defined already
Currently it is available on Linux only, and it is more an hint.
Signed-off-by: Pino Toscano <toscano.pino@tiscali.it>
Mark Wielaard [Sat, 27 Jun 2015 20:07:01 +0000 (22:07 +0200)]
nm: First call elf_getdata, then allocate memory.
This catches bogus data early before we might try to allocate giant
amounts of memory.
Reported-by: Hanno Böck <hanno@hboeck.de>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Pino Toscano [Fri, 26 Jun 2015 18:38:31 +0000 (20:38 +0200)]
tests: Mark an unused argument as such
Signed-off-by: Pino Toscano <toscano.pino@tiscali.it>
Pino Toscano [Fri, 26 Jun 2015 18:36:01 +0000 (20:36 +0200)]
Reduce scope of some includes
Use some includes only according to the #ifdef block of the respective
code, or matching the fact they are Linux-only. This way, includes
potentially unportable are not unconditionally used.
Signed-off-by: Pino Toscano <toscano.pino@tiscali.it>
Mark Wielaard [Fri, 19 Jun 2015 11:43:58 +0000 (13:43 +0200)]
Prepare 0.163 release.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 21:43:39 +0000 (23:43 +0200)]
findtextrel: Don't leak memory in process_file.
When a files do contain textrels we fail to release the segments searched
and valgrind will show:
2,560 bytes in 16 blocks are definitely lost in loss record 1 of 1
at 0x40281B5: malloc (in vgpreload_memcheck-x86-linux.so)
by 0x804AE63: process_file (findtextrel.c:322)
by 0x804909B: main (findtextrel.c:149)
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 18:24:39 +0000 (20:24 +0200)]
readelf: Make sure phdr2_mem lifetime/scope equals phdr2 pointer.
We dont' want GCC to dispose or reuse phdr2_mem stack memory while phdr2
is pointing to it.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 14:17:40 +0000 (16:17 +0200)]
libdwfl: Don't leak fname if file is main file by another name in try_open.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 08:57:53 +0000 (10:57 +0200)]
readelf: Don't leak memory on failure path in handle_gnu_hash.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 08:50:19 +0000 (10:50 +0200)]
libelf: Don't leak memory on failure paths in elf_updatefile.
When something goes wrong during the update make sure to always free any
temporary allocated memory (shdr_data and/or scns).
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 10:50:47 +0000 (12:50 +0200)]
elflint: Only check the PT_TLS phdr if it actually exists, warn otherwise.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 09:50:50 +0000 (11:50 +0200)]
libdw: Make sure the default page size is big enough to hold a Dwarf.
Just assert early that the page size isn't unreasonable small instead of
corrupting memory later.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 09:07:41 +0000 (11:07 +0200)]
nm: Fix typo in size check to determine whether we stack allocated memory.
We allocate GElf_SymX entries, which are larger than plain GElf_Sym structs.
The check to see whether we could use stack allocation used the correct
sizeof (GElf_SymX), but the check to see if we needed to free was using
the incorrect sizeof (GElf_Sym). Which could cause us to leak memory.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 09:00:51 +0000 (11:00 +0200)]
strings: Handle failure of getting section name on bogus section data.
If there is something wrong with getting the section data it is likely
we won't be able to get the actual section name because the file is
somehow corrupted. Try to get the name, but handle failure gracefully.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 08:54:29 +0000 (10:54 +0200)]
libelf: Check symbol section header exists before use in nlist.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 08:46:20 +0000 (10:46 +0200)]
libdwfl: Check symbol section exists and has a sane entsize in find_symtab.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 08:41:42 +0000 (10:41 +0200)]
libdw: Not leak memory on error in dwarf_getpubnames.
When there is an error with the first entry we might already have allocated
the memory but not yet set cnt to 1. Just always free the memory on error.
free (NULL) is a nop anyway and doesn't matter on a failure path.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 18 Jun 2015 08:38:12 +0000 (10:38 +0200)]
libdw: Detect dwarf_formudata errors in dwarf_getmacros.
dwarf_formudata can return an error for bad DWARF. Don't ignore it.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 16 Jun 2015 12:05:35 +0000 (14:05 +0200)]
libelf: Always call ftruncate before posix_fallocate to set the right size.
When elf_update.c (write_file) doesn't know the current maximum file length
it might have to reduce the file size. posix_fallocate can only extend the
file. So always call ftruncate before that to set the file size and making
sure the backing store is fully there. Add test cases for checking strip
in place (eu-strip without -o) actually reduces the file size. But only
for non-ET_REL files. We might not be able to strip ET_REL files (except
when they are kernel modules) because they might contain "dangling" symbol
table entries.
https://bugzilla.redhat.com/show_bug.cgi?id=1232206
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Sun, 14 Jun 2015 22:06:27 +0000 (00:06 +0200)]
po/*.po: Regenerate.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Piotr Drąg [Sat, 13 Jun 2015 13:34:53 +0000 (15:34 +0200)]
Updated Polish translation
Signed-off-by: Piotr Drąg <piotrdrag@gmail.com>
Piotr Drąg [Sat, 13 Jun 2015 11:16:13 +0000 (13:16 +0200)]
Updated POTFILES.in
Signed-off-by: Piotr Drąg <piotrdrag@gmail.com>
Mark Wielaard [Fri, 12 Jun 2015 10:50:14 +0000 (12:50 +0200)]
libebl: SHT_(INIT|FINI|PREINIT)_ARRAY are valid targets for relocation.
Seen in run-elflint-self.sh for size.o when build with --enable-gcov.
https://bugzilla.redhat.com/show_bug.cgi?id=1230798
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Thu, 11 Jun 2015 11:22:16 +0000 (13:22 +0200)]
elfutils.spec.in (devel): Include known-dwarf.h and version.h.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Wed, 10 Jun 2015 15:44:42 +0000 (17:44 +0200)]
Prepare 0.162 release.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 9 Jun 2015 22:22:58 +0000 (00:22 +0200)]
addr2line: Fix memory leak in print_dwarf_function.
Always free the scopes returned by dwarf_getscopes () when done.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Tue, 9 Jun 2015 14:26:16 +0000 (16:26 +0200)]
strip: Just admit we don't support stripping ar archives for now.
We try to handle (in-place) stripping of ar archives, but since elf_clone
doesn't really support cloning ar members and we don't handle reducing
the size of the members, moving the offsets of other members. This causes
crashes or writing garbage. Better to just admit that for now we don't
support stripping archives. Call error when we see an ELF_K_AR file.
https://bugzilla.redhat.com/show_bug.cgi?id=766156
https://lists.fedorahosted.org/pipermail/elfutils-devel/2009-August/000567.html
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 8 Jun 2015 22:31:25 +0000 (00:31 +0200)]
libdw: Initialize dirarray early in read_srclines.
We might jump to "out" early on error. Help gcc see that isn't an issue
by initializing dirarray to dirstack early.
Signed-off-by: Mark Wielaard <mjw@redhat.com>
Mark Wielaard [Mon, 8 Jun 2015 22:28:13 +0000 (00:28 +0200)]
configure: Add check for gcc -Wstack-usage.
Some older gcc versions don't support -Wstack-usage. Only use it when
accepted by the compiler.
Signed-off-by: Mark Wielaard <mjw@redhat.com>