platform/upstream/elfutils.git
8 years agotests: Guard linux specific header includes with ifdef __linux__.
Mark Wielaard [Wed, 13 Jan 2016 21:49:02 +0000 (22:49 +0100)]
tests: Guard linux specific header includes with ifdef __linux__.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoconfigure: clarify zlib error message
Mike Frysinger [Thu, 14 Jan 2016 18:46:18 +0000 (13:46 -0500)]
configure: clarify zlib error message

Also drop the spurious quotes.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
8 years agogitignore: update
Mike Frysinger [Thu, 14 Jan 2016 18:46:12 +0000 (13:46 -0500)]
gitignore: update

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
8 years agolibelf: Add ELF compression types and defines to libelf.h for older glibc.
Mark Wielaard [Wed, 13 Jan 2016 16:16:48 +0000 (17:16 +0100)]
libelf: Add ELF compression types and defines to libelf.h for older glibc.

Older glibc elf.h might not define the new ELF compression defines and
types. If not just define them in libelf.h directly to make the libelf
headers work on older glibc systems.

Also include a testcase to check the libelf headers build against the
system elf.h.

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=810885

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoRegenerate .po files. elfutils-0.165
Mark Wielaard [Mon, 11 Jan 2016 10:11:44 +0000 (11:11 +0100)]
Regenerate .po files.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agolibebl: Fix missing brackets around if statement body.
Mark Wielaard [Sat, 9 Jan 2016 21:09:48 +0000 (22:09 +0100)]
libebl: Fix missing brackets around if statement body.

GCC6 [will have] a nice new warning that showed a real bug:

elfutils/libebl/eblobjnote.c: In function ‘ebl_object_note’:
elfutils/libebl/eblobjnote.c:135:5: error: statement is indented as if it were guarded by... [-Werror=misleading-indentation]
     switch (type)
     ^~~~~~

elfutils/libebl/eblobjnote.c:45:3: note: ...this ‘if’ clause, but it is not
   if (! ebl->object_note (name, type, descsz, desc))
   ^~

And indeed, it should have been under the if, but wasn't because of missing
brackets. Added brackets (and reindent).

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agotests: Fix parentheses in elfputzdata strncmp test.
Mark Wielaard [Fri, 8 Jan 2016 20:55:58 +0000 (21:55 +0100)]
tests: Fix parentheses in elfputzdata strncmp test.

We were checking strlen () == 0 instead of strncmp () == 0. Oops.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoFix build on 32bit systems.
Mark Wielaard [Fri, 8 Jan 2016 15:45:12 +0000 (16:45 +0100)]
Fix build on 32bit systems.

size_t has a different size on 32 and 64 bit systems.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoPrepare 0.165 release.
Mark Wielaard [Fri, 8 Jan 2016 13:44:49 +0000 (14:44 +0100)]
Prepare 0.165 release.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoSimplify code and build now that zlib support is no longer optional.
Mark Wielaard [Fri, 8 Jan 2016 12:35:33 +0000 (13:35 +0100)]
Simplify code and build now that zlib support is no longer optional.

Now that we always require zlib support we don't need to conditionally
build or compile code that depends on it.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoUpdated Polish translation
Piotr Drąg [Thu, 7 Jan 2016 14:46:50 +0000 (15:46 +0100)]
Updated Polish translation

Signed-off-by: Piotr Drąg <piotrdrag@gmail.com>
8 years agoUpdated Polish translation
Piotr Drąg [Thu, 24 Dec 2015 13:16:15 +0000 (14:16 +0100)]
Updated Polish translation

Signed-off-by: Piotr Drąg <piotrdrag@gmail.com>
8 years agoelfcompress: New utility.
Mark Wielaard [Tue, 1 Dec 2015 13:55:07 +0000 (14:55 +0100)]
elfcompress: New utility.

Usage: elfcompress [OPTION...] FILE...
Compress or decompress sections in an ELF file.

 -f, --force              Force compression of section even if it would
                          become larger
 -n, --name=SECTION       SECTION name to (de)compress, SECTION is an
                          extended wildcard pattern (defaults to
                          '.?(z)debug*')
 -o, --output=FILE        Place (de)compressed output into FILE
 -p, --permissive         Relax a few rules to handle slightly broken ELF
                          files
 -q, --quiet              Be silent when a section cannot be compressed
 -t, --type=TYPE          What type of compression to apply. TYPE can be
                          'none' (decompress), 'zlib' (ELF ZLIB compression,
                          the default, 'zlib-gabi' is an alias) or
                          'zlib-gnu' (.zdebug GNU style compression, 'gnu'
                          is an alias)
 -v, --verbose            Print a message for each section being
                          (de)compressed
 -?, --help               Give this help list
     --usage              Give a short usage message
 -V, --version            Print program version

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoelflint: Recognize and check SHF_COMPRESSED section flag.
Mark Wielaard [Fri, 18 Dec 2015 14:51:37 +0000 (15:51 +0100)]
elflint: Recognize and check SHF_COMPRESSED section flag.

SHF_COMPRESSED is a valid section flag, it can optionally be on any special
section, but it cannot be used on NOBITS sections or together with SHF_ALLOC.
A section that has SHF_COMPRESSED set must have a valid Chdr.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agolibelf: Make elf_strptr index correctly into compressed section data.
Mark Wielaard [Wed, 30 Dec 2015 00:39:29 +0000 (01:39 +0100)]
libelf: Make elf_strptr index correctly into compressed section data.

elf_strptr indexes into the section data. This is defined as index into
the uncompressed data of the section. If the section is compressed make
sure the uncompressed data is available, but don't really decompress the
section header (elf_getdata will still return compressed data).

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoreadelf: Handle compressed sections and extend -z to cover -x and -p.
Mark Wielaard [Tue, 20 Oct 2015 23:30:44 +0000 (01:30 +0200)]
readelf: Handle compressed sections and extend -z to cover -x and -p.

When printing a (non-string, non-data) section use uncompressed data when
possible. For dumping hex and string sections (-x and -p) -z will dump the
uncompressed data (otherwise the compressed data is dumped).

-z, --decompress           Show compression information for compressed
                           sections (when used with -S); decompress section
                           before dumping data (when used with -p or -x)

Includes test cases for ET_REL files using compressed relocation (target)
debug sections to test libdwfl transparent uncompression of sections.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agolibdwfl: Use elf_compress[_gnu] to decompress string, symbol and reloc data.
Mark Wielaard [Wed, 30 Dec 2015 13:39:18 +0000 (14:39 +0100)]
libdwfl: Use elf_compress[_gnu] to decompress string, symbol and reloc data.

This makes usage of the libdwfl symbol functions work out of the box even
when some sections (string, symbol or xndx) are compressed. For ET_REL
files this makes relocations just work by making sure the target section
is decompressed first before relocations are applied.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agolibdw: Use elf_compress[_gnu] to uncompress debug section data.
Mark Wielaard [Wed, 30 Dec 2015 13:18:40 +0000 (14:18 +0100)]
libdw: Use elf_compress[_gnu] to uncompress debug section data.

libdw used its own code for decompressing GNU style .zdebug sections.
Using elf_compress and elf_compress_gnu instead makes it possible to
transparently use either GNU style or ELF style compressed data.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agolibelf: Add elf_compress and elf_compress_gnu.
Mark Wielaard [Sat, 19 Dec 2015 00:29:54 +0000 (01:29 +0100)]
libelf: Add elf_compress and elf_compress_gnu.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoreadelf: Add -z,--decompress option.
Mark Wielaard [Fri, 16 Oct 2015 20:21:23 +0000 (22:21 +0200)]
readelf: Add -z,--decompress option.

  -z, --decompress           Show compression information for compressed
                             sections (when used with -S).

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agolibelf: Add elf32_getchdr, elf64_getchdr and gelf_getchdr.
Mark Wielaard [Thu, 19 Nov 2015 23:12:37 +0000 (00:12 +0100)]
libelf: Add elf32_getchdr, elf64_getchdr and gelf_getchdr.

Elf_Data of a compressed section has type ELF_T_CHDR. This type can be
xlated to the file or memory representation. This will make sure the Chdr
is in the correct endianess. The compressed data following the Chdr isn't
translated.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agolibdwelf: Add dwelf_scn_gnu_compressed_size.
Mark Wielaard [Tue, 17 Nov 2015 22:52:39 +0000 (23:52 +0100)]
libdwelf: Add dwelf_scn_gnu_compressed_size.

Helper function to get the size of a GNU compressed zdebug section.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoconfig: Add libelf and libdw pkg-config files.
Mark Wielaard [Mon, 4 Jan 2016 20:41:52 +0000 (21:41 +0100)]
config: Add libelf and libdw pkg-config files.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoelflint: Add _edata and _end to the list of possibly dangling gnuld symbols.
Mark Wielaard [Thu, 31 Dec 2015 22:16:28 +0000 (23:16 +0100)]
elflint: Add _edata and _end to the list of possibly dangling gnuld symbols.

gnuld might keep dangling/unused symbols around (see sourceware PR13621).
Add _edata (end of initialized data address) and _end (end of uninitialized
data address) to that list. They might have been added by gnuld even if
there is no such [un]initialized data. Also add the double underscore
variants which are used on some architectures.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agotests: elfstrmerge warn about STT_SECTION symbol for shstrhndx.
Mark Wielaard [Thu, 31 Dec 2015 22:03:20 +0000 (23:03 +0100)]
tests: elfstrmerge warn about STT_SECTION symbol for shstrhndx.

Old linkers might have created an STT_SECTION symbol for the section
header string table section, which isn't actually used.  For now just
warn about such symbols. If such a symbol would actually really be used
(but why?) then we would have to handle it by removing it and rewriting
the symbol table.

This is a testsuite only change, but includes an extra test with files
that have such STT_SECTION symbols to make sure it will be handled in
case we "upgrade" the elfstrmerge test to a real utility.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoMake make more silent.
Mark Wielaard [Thu, 31 Dec 2015 21:08:23 +0000 (22:08 +0100)]
Make make more silent.

Silent rules already are the default, but automake and make both still
tell which directory is being entered/build. Disable printing from make.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoMove nested functions in linux-proc-maps.c to file scope.
Chih-Hung Hsieh [Wed, 18 Nov 2015 19:04:52 +0000 (11:04 -0800)]
Move nested functions in linux-proc-maps.c to file scope.

* Move nested function 'report' to file scope to compile with clang.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
8 years agoMove nested functions in core-file.c to file scope.
Chih-Hung Hsieh [Wed, 18 Nov 2015 18:38:19 +0000 (10:38 -0800)]
Move nested functions in core-file.c to file scope.

* Move nested functions 'fail', 'update_end', and 'more' to file scope.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
8 years agoMove nested functions check64 and check32 in link_map.c to file scope.
Chih-Hung Hsieh [Tue, 17 Nov 2015 22:45:15 +0000 (14:45 -0800)]
Move nested functions check64 and check32 in link_map.c to file scope.

* In libdwfl/link_map.c, nested functions check64, check32, are moved
  to file scope to compile with clang.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agobackends: sparc: support for live backtraces
Jose E. Marchesi [Tue, 8 Dec 2015 18:10:43 +0000 (19:10 +0100)]
backends: sparc: support for live backtraces

This patch implements the set_initial_registers_tid hook for sparc.
It works in both sparcv9-*-* and sparc64-*-* targets.

Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
8 years agobackends: sparc: support for core backtraces
Jose E. Marchesi [Tue, 8 Dec 2015 18:10:42 +0000 (19:10 +0100)]
backends: sparc: support for core backtraces

This patch adds sparc support to the unwinder, providing a default CFI
program that works in both sparcv9-*-* and sparc64-*-* targets.

Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agolibdwfl: make the unwinder aware of the backend defined ra_offset.
Jose E. Marchesi [Tue, 8 Dec 2015 18:10:41 +0000 (19:10 +0100)]
libdwfl: make the unwinder aware of the backend defined ra_offset.

Ebl backends can define an offset that must be applied to the value of
the "return address register" defined in the CFI ABI information.
This patch makes the unwinder to use that offset when reading the RA
CFI register.

Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
8 years agolibebl: new backend attribute ra_offset.
Jose E. Marchesi [Tue, 8 Dec 2015 18:10:40 +0000 (19:10 +0100)]
libebl: new backend attribute ra_offset.

Some backends need to fine-tune the return address as fetched from the
corresponding CFI register.  This patch adds a new backend attribute
ra_offset and the corresponding ebl_ra_offset getter function.

Signed-off-by: Jose E. Marchesi <jose.marchesi@oracle.com>
8 years agotests: Use valgrind --leak-check=full.
Mark Wielaard [Wed, 2 Dec 2015 16:27:18 +0000 (17:27 +0100)]
tests: Use valgrind --leak-check=full.

When --enable-valgrind is given run the testsuite with --leak-check=full
treating any memory leak as a failure. Also disable valgrind for those
tests that trigger a valgrind bug.
https://bugs.kde.org/show_bug.cgi?id=327427

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agolibdw: Don't leak duplicate FDEs.
Mark Wielaard [Wed, 2 Dec 2015 16:07:40 +0000 (17:07 +0100)]
libdw: Don't leak duplicate FDEs.

Although it isn't supposed to happen there could be FDEs that cover the
same address range. Don't leak such FDEs and use an existing FDE for
consistency.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agonm: If the file is ET_REL and we need Dwarf use libdwfl to get it relocated.
Mark Wielaard [Wed, 2 Dec 2015 15:57:44 +0000 (16:57 +0100)]
nm: If the file is ET_REL and we need Dwarf use libdwfl to get it relocated.

If we need Dwarf and the file is ET_REL use the same trick as in readelf
to get a relocated Dwarf. Otherwise lots of references in the debug_info
will come out as zero.

This also explains the "bogus" Dwarf seen that caused the memory leak in
the local_root that was fixed previously.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agonm: Don't leak duplicate Dwarf local names.
Mark Wielaard [Wed, 2 Dec 2015 15:44:42 +0000 (16:44 +0100)]
nm: Don't leak duplicate Dwarf local names.

Badly formed DWARF can have duplicate local names. In which case we do
want to detect those so we don't leak the memory.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agounstrip: Don't leak new section data.
Mark Wielaard [Wed, 2 Dec 2015 14:44:10 +0000 (15:44 +0100)]
unstrip: Don't leak new section data.

When we copy elided sections some section data is newly allocated.
Track those allocations so we can free them when done.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agolibdw: Don't use a FDE if it doesn't actually cover a real code range.
Mark Wielaard [Tue, 1 Dec 2015 23:21:07 +0000 (00:21 +0100)]
libdw: Don't use a FDE if it doesn't actually cover a real code range.

If the FDE end <= start then it doesn't actually cover a valid code range.
Don't use and cache such FDEs (it will cause memory leaks if there is
another FDE that has the same start address and a valid code range).

Such FDEs have been seen in the backtrace.ppc.exec testfile.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agolibdwfl: Fix memory leak in link_map.c dwfl_link_map_report.
Mark Wielaard [Tue, 1 Dec 2015 22:11:55 +0000 (23:11 +0100)]
libdwfl: Fix memory leak in link_map.c dwfl_link_map_report.

The phdrs buffer could come from the core file or through the executable.
dwfl_link_map_report would leak the buffer if it came from the executable.
Track where the buffer came from and free appropriately.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agolibdwfl: Don't leak core Elf and core file descriptor from argp-std.
Mark Wielaard [Tue, 1 Dec 2015 21:16:00 +0000 (22:16 +0100)]
libdwfl: Don't leak core Elf and core file descriptor from argp-std.

Our argp helper would leak the core Elf and core file descriptor when
given by the user. Store both in the Dwfl as a new Dwfl_User_Core so
they get cleaned up by dwfl_end.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agotests: Fix some memory leaks in testcases.
Mark Wielaard [Tue, 1 Dec 2015 14:55:08 +0000 (15:55 +0100)]
tests: Fix some memory leaks in testcases.

Make sure all structures allocated in the testcases are disposed so
running them under valgrind will show no memory leaks.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agolibdw: Don't leak fake_loc_cu.
Mark Wielaard [Tue, 1 Dec 2015 14:21:55 +0000 (15:21 +0100)]
libdw: Don't leak fake_loc_cu.

The fake_loc_cu is used when synthesizing attributes for Dwarf_Ops that
came from a location list entry in dwarf_getlocation_attr. Make sure
we remove the loc cache stored in it when disposing of the fake_loc_cu.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoelfcmp: Fix leaking Ebl handles.
Mark Wielaard [Tue, 1 Dec 2015 14:02:23 +0000 (15:02 +0100)]
elfcmp: Fix leaking Ebl handles.

open_file () explicitly gets Ebl handles for both Elf files to compare.
Make sure to close those when done.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoMove nested functions in dwfl_module_getdwarf.c to file scope.
Chih-Hung Hsieh [Tue, 17 Nov 2015 01:16:50 +0000 (17:16 -0800)]
Move nested functions in dwfl_module_getdwarf.c to file scope.

* In dwfl_module_getdwarf.c, nested functions 'consider_shdr'
  and 'translate_offs' are moved to file scope to compile with clang.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoMove nested functions in dwfl_module_addrsym.c to file scope.
Chih-Hung Hsieh [Tue, 17 Nov 2015 00:05:01 +0000 (16:05 -0800)]
Move nested functions in dwfl_module_addrsym.c to file scope.

* Move nested functions 'same_section', 'binding_value',
  'try_sym_value', and 'search_table'.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
8 years agoMove nested functions in dwarf_entry_breakpoints.c to file scope.
Chih-Hung Hsieh [Wed, 14 Oct 2015 19:30:11 +0000 (12:30 -0700)]
Move nested functions in dwarf_entry_breakpoints.c to file scope.

No nested functions to compile with clang/llvm.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
8 years agoMove nested functions in libdw_visit_scopes.c to file scope.
Chih-Hung Hsieh [Wed, 14 Oct 2015 19:23:34 +0000 (12:23 -0700)]
Move nested functions in libdw_visit_scopes.c to file scope.

* No nested functions to compile with clang/llvm.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agolibdw: Make sure Ebl is always freed from cfi frame cache.
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>
8 years agolibdw: initialize state early in read_srclines
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>
8 years agoNo nested functions in dwarf_getsrclines.
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>
8 years agoMove nested functions in gzip.c to file scope.
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>
8 years agoNo nested function in dwarf_getscopevar to file scope.
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>
8 years agoMove nested functions in dwfl_module_getsrc_file.c.
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>
8 years agoMove nested functions in frame_unwind.c.
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>
8 years agoMove nested functions in dwfl_module.c
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>
8 years agoMove nested functions in backends to file scope.
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>
8 years agoMake zlib mandatory.
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>
8 years agoelf.h: Update from glibc. Add section compression constants and structures.
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>
8 years agolibelf: use the right size when preading in[0].sh_size
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>
8 years agoMove nested functions in libdw/cfi.c to file scope.
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>
8 years agoMove nested functions in libdwelf.
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>
8 years agoMove nested functions in libelf.
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>
8 years agoelflint: Don't check shdr or TLS symbol offsets against debuginfo phdrs.
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>
8 years agoRegenerate .po files. elfutils-0.164
Mark Wielaard [Fri, 16 Oct 2015 11:28:03 +0000 (13:28 +0200)]
Regenerate .po files.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
8 years agoelflint: Reject mergable string sections as relocation target.
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>
8 years agoppc: ppc_check_special_symbol): Also allow _SDA_BASE_ in .data section.
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>
8 years agotests: Add AM_LDFLAGS to dwfl_proc_attach_LDFLAGS.
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>
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>