platform/upstream/elfutils.git
6 years agoDon't overflow in __libdw_in_section and __libdw_offset_in_section.
Ulf Hermann [Tue, 9 May 2017 16:28:33 +0000 (18:28 +0200)]
Don't overflow in __libdw_in_section and __libdw_offset_in_section.

This exposes a bug in dwarf_formstring as detected by the dwarf-getmacros
test before we made sure to use the correct sec_idx for the CU.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agolibdw: Add explicit section index to struct Dwarf_CU.
Mark Wielaard [Wed, 20 Dec 2017 15:50:57 +0000 (16:50 +0100)]
libdw: Add explicit section index to struct Dwarf_CU.

The DIE (attribute) data might come from either the main .debug_info
section or for DWARFv4 from a separate .debug_types section. Or in
case of the fake_loc_cu from the .debug_loc section and in the case
of macros from the .debug_macinfo or .debug_macro section.

We didn't handle the last two "fake" CU cases correctly when sanity
checking offsets in __libdw_read_address and __libdw_read_offset.

Add an explicit sec_idx field to struct Dwarf_CU that is always set
to the actual section that the data came from.

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agoreadelf: Try to continue after encountering bogus ELF Note data.
Mark Wielaard [Mon, 18 Dec 2017 11:39:13 +0000 (12:39 +0100)]
readelf: Try to continue after encountering bogus ELF Note data.

There might be other sections or segments with ELF Notes that are
readable. Also adjust error message depending on whether or not we
actually got any data for the ELF Note segment or section.

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agolibdw: dwarf_aggregate_size should not peel the given DIE.
Mark Wielaard [Mon, 11 Dec 2017 22:58:34 +0000 (23:58 +0100)]
libdw: dwarf_aggregate_size should not peel the given DIE.

Reserve memory for a new DIE first. The caller might not care, but it
isn't really nice to change the DIE the caller gave us.

See also https://sourceware.org/bugzilla/show_bug.cgi?id=22546#c5

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agolibdw: dwarf_aggregate_size() works with multi-dimensional arrays
Dima Kogan [Fri, 8 Dec 2017 09:45:10 +0000 (01:45 -0800)]
libdw: dwarf_aggregate_size() works with multi-dimensional arrays

If we have a multidimensional array of dimensions (a,b,c) the number of elements
should be a*b*c, but prior to this patch dwarf_aggregate_size() would report
a+b+c instead.

This patch fixes the bug and adds a test that demonstrates the bug (the test
fails without the functional part of this patch).

Fixes: https://sourceware.org/bugzilla/show_bug.cgi?id=22546

Signed-off-by: Dima Kogan <dima@secretsauce.net>
6 years agoreadelf: Handle DW_OP_call2 and DW_OP_call4 correctly.
Mark Wielaard [Thu, 7 Dec 2017 15:31:54 +0000 (16:31 +0100)]
readelf: Handle DW_OP_call2 and DW_OP_call4 correctly.

DW_OP_call2 and DW_OP_call4 didn't correctly advance the data pointer.
This caused print_ops to produce garbage operands. Also format the
arguments as DIE offsets. That makes it easier to follow the call to the
actual dwarf_procedure DIE.

Testcase from https://sourceware.org/bugzilla/show_bug.cgi?id=22532

The testcase only checks the eu-readelf output is correct for the
byte_size attribute. But it might be interesting to write a full
expression parser to check the actual sizes.

 [    3e]    structure_type
             name                 (strp) "pck__rec"
             byte_size            (exprloc)
              [   0] push_object_address
              [   1] deref_size 1
              [   3] call4 [    95]
              [   8] plus_uconst 7
              [  10] const1s -4
              [  12] and

 [    95]    dwarf_procedure
             location             (exprloc)
              [   0] dup
              [   1] lit1
              [   2] ne
              [   3] bra 10
              [   6] lit4
              [   7] skip 31
              [  10] dup
              [  11] lit4
              [  12] ne
              [  13] bra 20
              [  16] lit0
              [  17] skip 31
              [  20] dup
              [  21] lit3
              [  22] eq
              [  23] bra 30
              [  26] lit0
              [  27] skip 31
              [  30] lit4
              [  31] swap
              [  32] drop

The "answer" depends on the Discr value (first byte at object address),
and is rounded up to 4 or 8 bytes.

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agoreadelf: Hook up -g, --section-groups to display the section groups.
Mark Wielaard [Wed, 29 Nov 2017 23:10:58 +0000 (00:10 +0100)]
readelf: Hook up -g, --section-groups to display the section groups.

It was already possible to display the section groups using -a, but
the argp options didn't yet have an -g, --section-groups entry to
just display the section groups.

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agoreadelf: Print CU, base address and unresolved .debug_loc entries.
Mark Wielaard [Wed, 29 Nov 2017 15:37:50 +0000 (16:37 +0100)]
readelf: Print CU, base address and unresolved .debug_loc entries.

Also adjust the formatting for the resolved addresses to print them
on separate lines so they nicely line up even when the addresses are
resolved to symbol+offset names. And print the operands starting on
a new line.

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agoreadelf: Print CU, base address and unresolved .debug_range entries.
Mark Wielaard [Wed, 29 Nov 2017 15:27:33 +0000 (16:27 +0100)]
readelf: Print CU, base address and unresolved .debug_range entries.

Also adjust the formatting for the resolved addresses to print them
on separate lines so they nicely line up even when the addresses are
resolved to symbol+offset names.

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agoreadelf: Print actual file for decl_file and call_file attributes.
Mark Wielaard [Wed, 29 Nov 2017 15:06:36 +0000 (16:06 +0100)]
readelf: Print actual file for decl_file and call_file attributes.

When we see a DW_AT_decl_file or DW_AT_call_file attribute print the
actual file name. The current interface gives us a full (absolute) patch,
but we only want to show the file name for now to not clutter the output
too much. This helps a lot when trying to determine where something was
declared if you are just looking at the DIE tree. Otherwise you'll have
to cross match the number by hand with the corresponding line table entry.

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agoreadelf: Print abbrev code for DIE with --debug-dump=info.
Mark Wielaard [Wed, 29 Nov 2017 14:58:40 +0000 (15:58 +0100)]
readelf: Print abbrev code for DIE with --debug-dump=info.

If there is anything wrong with a DIE it is useful to know what the abbrev
code was so you can lookup the abbrev description.

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agoreadelf: Adjust print_ops formatting.
Mark Wielaard [Wed, 29 Nov 2017 14:43:26 +0000 (15:43 +0100)]
readelf: Adjust print_ops formatting.

Use only 2 spaces for index (there are never 10000, the most seen in the
wild is 64). Adjust re-indenting after GNU_entry_value.

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agolibdwfl: Don't dereference possibly unaligned auxv entry pointer from core.
Mark Wielaard [Mon, 20 Nov 2017 13:11:02 +0000 (14:11 +0100)]
libdwfl: Don't dereference possibly unaligned auxv entry pointer from core.

The notes in a core file that contain the auxv entries might not be
naturally aligned. The code already tried to account for that, but
the GCC 8 undefined behaviour sanitizer found we were till dereferencing
the actual auxv entry pointer directly. Fix this by calculating all pointers
by hand and not use an array of auxv entries trick.

This makes make distcheck (which enables sanitize-undefined by default)
pass again using GCC8.

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agoreadelf: Print attribute name and form in error message.
Mark Wielaard [Tue, 21 Nov 2017 10:13:00 +0000 (11:13 +0100)]
readelf: Print attribute name and form in error message.

Now an error getting the attribute value will not only print the DIE offset
and the reason, but also the attribute name and form. e.g.

  DIE [b] cannot get attribute 'ranges' (sec_offset) value: .debug_ranges
  section missing

Also we don't abort, but try to print the other attributes of the DIE
anyway. It might just be one attribute whose value cannot be resolved.

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agoreadelf: Print DIE offset in attribute reading error messages.
Mark Wielaard [Tue, 3 Oct 2017 14:55:25 +0000 (16:55 +0200)]
readelf: Print DIE offset in attribute reading error messages.

When processing large files it is useful to know the DIE offset if
printing of attributes fails (especially when redirecting the output).
With this change the error message looks like:

  eu-readelf: DIE [2aeb8ef1] cannot get attribute value: invalid DWARF

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agotests: Fix cfi_debug => cfi_debug_bias typo in varlocs assert.
Mark Wielaard [Thu, 16 Nov 2017 12:20:11 +0000 (13:20 +0100)]
tests: Fix cfi_debug => cfi_debug_bias typo in varlocs assert.

We want to check whether the bias is zero, not whether we have dwarf
debug_frame cfi.

This triggered on a ppc64/ppc64le self-check since it has both
debug_frame and eh_frame cfi (other arches often only have eh_frame).

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agotests: Add varlocs-self and exprlocs-self tests.
Mark Wielaard [Wed, 8 Nov 2017 10:25:33 +0000 (11:25 +0100)]
tests: Add varlocs-self and exprlocs-self tests.

Make sure the testcases (library functions they use) don't crash,
triggers self-check/asserts or leaks memory under valgrind. This
also helps making sure newer DWARF constructs are handled (when
building with -gdwarf-5).

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agolibdw: Handle DW_OP_GNU_variable_value.
Mark Wielaard [Thu, 2 Nov 2017 15:24:41 +0000 (16:24 +0100)]
libdw: Handle DW_OP_GNU_variable_value.

Handle DW_OP_GNU_variable_value in dwarf_getlocation[_attr,_die].
DW_OP_GNU_variable_value takes one argument a DIE reference that
describes a value given by a location of const_value attribute.

To test handling of the new operand the varlocs test is adapted
to print out all DIEs and attributes with expressions or location
lists (the original varlocs test only prints out variables and
arguments of function DIEs).

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agolibdw: Update acceptable forms and attributes for dwarf_getlocation.
Mark Wielaard [Thu, 2 Nov 2017 15:24:17 +0000 (16:24 +0100)]
libdw: Update acceptable forms and attributes for dwarf_getlocation.

dwarf_getlocation has to know which attributes can contain a DWARF
expression or location list because the form alone might be ambiguous.

Since DWARF4 there is DW_FORM_exprloc so always accept that. But for older
DWARF or location lists we cannot just check for DW_FORM_sec_offset since
that could be a reference to diffent kinds of sections (based on attribute).

Update the attribute list based on the latest DWARF5 encodings table.
Note that DW_AT_call_origin wasn't added because that seems to be a
typo in the DWARF5 spec. http://dwarfstd.org/ShowIssue.php?issue=171103.1

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agoreadelf: Handle DW_OP_GNU_variable_value.
Mark Wielaard [Thu, 2 Nov 2017 15:23:24 +0000 (16:23 +0100)]
readelf: Handle DW_OP_GNU_variable_value.

Also format both DW_OP_call_ref and DW_OP_GNU_variable_value argument
as a normal DIE reference.

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agoconfig: files under /usr/lib/sysctl.d (_sysctldir) aren't %config.
Mark Wielaard [Thu, 2 Nov 2017 15:53:10 +0000 (16:53 +0100)]
config: files under /usr/lib/sysctl.d (_sysctldir) aren't %config.

Admin can place the real config file under /etc/sysctl.d as override.
https://bugzilla.redhat.com/show_bug.cgi?id=1506660

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agobackends: Ignore GCC8 -Wpacked-not-aligned for m68k_corenote.c.
Mark Wielaard [Tue, 24 Oct 2017 12:23:30 +0000 (14:23 +0200)]
backends: Ignore GCC8 -Wpacked-not-aligned for m68k_corenote.c.

The GCC8 -Wpacked-not-aligned warns if a structure field with explicit
padding in a packed structure will be misaligned. m68k prstatus core
notes are described by a packed structure which has such aligned structure
fields.

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agolib: Remove md5 and sha1 implementations.
Mark Wielaard [Mon, 16 Oct 2017 14:16:12 +0000 (16:16 +0200)]
lib: Remove md5 and sha1 implementations.

Only the testcase md5-sha1-test used them. So also remove that testcase.

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agolibdwfl: When the kernel is found, but not the modules warn, don't fail.
Mark Wielaard [Mon, 16 Oct 2017 11:25:33 +0000 (13:25 +0200)]
libdwfl: When the kernel is found, but not the modules warn, don't fail.

For -k the argp parser could fail to find the modules after the kernel
itself was already found. Calling failure at this point closes the Dwfl,
which isn't necessary. Just warn about the missing modules and continue
with the kernel only Dwfl.

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agolibelf: Don't error out when sanity checking e_shoff if scncnt is zero.
Mark Wielaard [Wed, 4 Oct 2017 18:52:53 +0000 (20:52 +0200)]
libelf: Don't error out when sanity checking e_shoff if scncnt is zero.

We won't use the e_shoff value in that case because we will set
elf->state.elf[64|32].scns.cnt to zero to indicate not to read
any section header data from the file.

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agolibelf: Add ELF_E_INVALID_ELF error value.
Mark Wielaard [Wed, 4 Oct 2017 14:51:15 +0000 (16:51 +0200)]
libelf: Add ELF_E_INVALID_ELF error value.

Add ELF_E_INVALID_ELF which is set when the ELF file data is bad.
This is different from ELF_E_INVALID_FILE which is set when the file
could not be read.

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agolibdw: Define LIBDW_CIE_ID and use it in dwarf_cfi_cie_p.
Mark Wielaard [Tue, 3 Oct 2017 21:08:01 +0000 (23:08 +0200)]
libdw: Define LIBDW_CIE_ID and use it in dwarf_cfi_cie_p.

dwarf_cfi_cie_p used DW_CIE_ID_64 from dwarf.h which meant you had
to include dwarf.h just to use the dwarf_cfi_cie_p macros. Just define
the constant as LIBDW_CIE_ID in libdw.h to keep it independent.

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agoMake sure packed structs follow the gcc memory layout
Ulf Hermann [Fri, 18 Aug 2017 12:05:10 +0000 (14:05 +0200)]
Make sure packed structs follow the gcc memory layout

gcc defaults to using struct layouts that follow the native conventions,
even if __attribute__((packed)) is given. In order to get the layout we
expect, we need to tell gcc to always use the gcc struct layout, at
least for packed structs. To do this, we can use the gcc_struct
attribute.

This is important, not only for porting to windows, but also potentially
for other platforms, as the bugs resulting from struct layout
differences are rather subtle and hard to find.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
6 years agoar: Check whether ar header values fit.
Mark Wielaard [Sun, 10 Sep 2017 22:12:31 +0000 (00:12 +0200)]
ar: Check whether ar header values fit.

When compiling with -O3 gcc finds an interesting error:

src/ar.c: In function ‘do_oper_insert’:
src/ar.c:1077:56: error: ‘%-*ld’ directive output may be truncated writing between 6 and 10 bytes into a region of size 7 [-Werror=format-truncation=]
   snprintf (tmpbuf, sizeof (tmpbuf), ofmt ? "%-*lo" : "%-*ld", bufsize, val);
                                                        ^~~~~
The problem is that the ar header values have to fit in a limited
(not zero terminated) string. We should check the snprintf return
value to see if the values are representable.

Also make ar valgrind and ubsan clean and add a minimal sanity test.

Reported-by: Matthias Klose <doko@ubuntu.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agoREADME: Add basic build instructions.
Mark Wielaard [Tue, 19 Sep 2017 14:05:49 +0000 (16:05 +0200)]
README: Add basic build instructions.

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 years agoInternationalized messages should not contain the '\v' escape sequence.
Mark Wielaard [Fri, 1 Sep 2017 10:42:45 +0000 (12:42 +0200)]
Internationalized messages should not contain the '\v' escape sequence.

Replace horizontal tab '\v' with double line feed '\n\n' in doc strings.
Regenerate .po files.

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agoCast pid_t to long long when printing
Ulf Hermann [Fri, 18 Aug 2017 15:20:02 +0000 (17:20 +0200)]
Cast pid_t to long long when printing

We don't know sizeof(pid_t) as it's not specified in any standard. In
order to still print it, we cast to long long, the largest integer type
we can easily print.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agoOn non-linux systems, don't use native signal numbers
Ulf Hermann [Fri, 18 Aug 2017 15:03:50 +0000 (17:03 +0200)]
On non-linux systems, don't use native signal numbers

We assume core files from linux systems, so we should use the linux
version of the signals when reading them. Other OS might have different
signal numbers.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
7 years agoDetect if symbol versioning is supported
Ulf Hermann [Fri, 18 Aug 2017 13:50:42 +0000 (15:50 +0200)]
Detect if symbol versioning is supported

If not, throw an error unless symbol versioning was explicitly
disabled.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
7 years agoDrop -rdynamic from deleted-lib.so link step
Ulf Hermann [Fri, 18 Aug 2017 13:17:38 +0000 (15:17 +0200)]
Drop -rdynamic from deleted-lib.so link step

-rdynamic is meant for ELF objects that need to export internal
symbols to libraries they link to, but deleted-lib.so does not link to
anything else and doesn't have any internal symbols.

Note that the "deleted" test program does link to deleted-lib.so, but
deleted-lib.so being a shared object, will automatically export the
(non-hidden) "libfunc" symbol anyway.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
7 years agoCheck if gcc complains about __attribute__ (visibility(..))
Ulf Hermann [Fri, 18 Aug 2017 11:06:36 +0000 (13:06 +0200)]
Check if gcc complains about __attribute__ (visibility(..))

If so, define attribute_hidden to be empty. Also, use attribute_hidden
in all places where we hide symbols. If this attribute is missing, it
simply means that we cannot hide private symbols in the binary using
attributes. This disables some optimizations and may increase the risk
of symbol name clashes with other libraries, but is not fatal.

However, we still employ linker version scripts to explicitly define
the exported symbols. This serves much of the same purpose. Also, as
all our symbols are prefixed with the library name, and "__" for
private ones, the chance of clashes is low anyway.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
7 years agoCheck for -z,defs, -z,relro, -fPIC, -fPIE before using them
Ulf Hermann [Fri, 18 Aug 2017 10:41:11 +0000 (12:41 +0200)]
Check for -z,defs, -z,relro, -fPIC, -fPIE before using them

Those flags are not available on all platforms, and omitting them when
not available will not cause any harm. In particular:

-z,defs disallows undefined symbols in object files. This option is
unsupported if the target binary format enforces the same condition
already. Furthermore it is only a compile time sanity check. When it is
omitted, the same binary is produced.

-z,relro instructs the loader to mark sections read-only after loading
the library, where possible. This is a hardening mechanism. If it is
unavailable, the functionality of the code is not affected in any way.

-fPIC instructs the compiler to produce position independent code. While
this is preferable to relocatable code, relocatable code also works and
may even be faster. Relocatable code might just be loaded into memory
multiple times for different processes.

-fPIE is the same thing as -fPIC for executables rather than shared
libraries.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
7 years agolibelf: Sync elf.h from glibc.
Mark Wielaard [Tue, 15 Aug 2017 20:43:01 +0000 (22:43 +0200)]
libelf: Sync elf.h from glibc.

Add new powerpc note descriptors.

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agotests: robustify run-strip-nothing.sh against unstripped libc_nonshared.a
Dmitry V. Levin [Tue, 8 Aug 2017 16:06:16 +0000 (19:06 +0300)]
tests: robustify run-strip-nothing.sh against unstripped libc_nonshared.a

When glibc's libc_nonshared.a contains objects with debug info,
this debug info is leaked into every output file produced by gcc.
Change run-strip-nothing.sh to use "gcc -s" instead of plain "gcc"
for producing objects without debug info.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
7 years agoPrepare for 0.170. elfutils-0.170
Mark Wielaard [Wed, 2 Aug 2017 16:30:07 +0000 (18:30 +0200)]
Prepare for 0.170.

Set version to 0.170. Update po/*.po files.
Add some more user visible changes to NEWS.

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agobackends: sparc GOTDATA_OP[_HIX22|LOX10] can be used in ET_REL files.
Mark Wielaard [Thu, 27 Jul 2017 21:07:00 +0000 (23:07 +0200)]
backends: sparc GOTDATA_OP[_HIX22|LOX10] can be used in ET_REL files.

Tested on new GNU Compile Farm server gcc202.

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agolibdw: Add DW_MACRO constants and DW_MACRO_GNU compatibility defines.
Mark Wielaard [Wed, 26 Jul 2017 21:02:18 +0000 (23:02 +0200)]
libdw: Add DW_MACRO constants and DW_MACRO_GNU compatibility defines.

Accept version 5 .debug_macro format, which is identical to the GNU
version 4 format. No real support yet for the new supplementary object
file (sup) and indirect string references (strx).  GCC doesn't generate
them yet. readelf does recognize them, but doesn't try to decode them.
dwarf_getmacros currently rejects the new formats.

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agolibdw: Handle DWARF5 immutable, packed and shared in dwarf_peel_type.
Mark Wielaard [Wed, 26 Jul 2017 20:54:59 +0000 (22:54 +0200)]
libdw: Handle DWARF5 immutable, packed and shared in dwarf_peel_type.

Also update the documentation to explain that any type alias or modifier
that doesn't modify, change the structural layout or the way to access
the underlying type is peeled. Explicitly mention pointer and reference
types as examples of modifiers that don't obey that rule and so aren't
peeled.

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agoHandle DWARF5 defaulted member function encodings.
Mark Wielaard [Wed, 26 Jul 2017 16:32:27 +0000 (18:32 +0200)]
Handle DWARF5 defaulted member function encodings.

Add DW_DEFAULTED_no, DW_DEFAULTED_in_class and DW_DEFAULTED_out_of_class
to dwarf.h.

Print value (no, in_class or out_of_class) of DW_AT_defaulted in readelf.

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agolibdw: DWARF5 Add DW_CC_pass_by_reference and DW_CC_pass_by_reference.
Mark Wielaard [Wed, 26 Jul 2017 16:15:20 +0000 (18:15 +0200)]
libdw: DWARF5 Add DW_CC_pass_by_reference and DW_CC_pass_by_reference.

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agolibdw: Add dwarf_default_lower_bound.
Mark Wielaard [Wed, 26 Jul 2017 16:06:21 +0000 (18:06 +0200)]
libdw: Add dwarf_default_lower_bound.

Add dwarf_default_lower_bound to get the default lower bound for a language
when not given as attribute for an subrange type. Implementation extracted
from dwarf_aggregate_size.

Add a test to check all known language codes are handled.

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agolibdw: DWARF5 Add new DW_LANG codes and default lower array bound.
Mark Wielaard [Wed, 26 Jul 2017 15:44:29 +0000 (17:44 +0200)]
libdw: DWARF5 Add new DW_LANG codes and default lower array bound.

Add DW_LANG_OpenCL, DW_LANG_Modula3, DW_LANG_C_plus_plus_03,
DW_LANG_OCaml, DW_LANG_Rust, DW_LANG_Swift, DW_LANG_Julia,
DW_LANG_Dylan, DW_LANG_RenderScript and DW_LANG_BLISS to dwarf.h.

Update default language array lower bounds in dwarf_aggregate_size.c.

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agolibdw: Add new DWARF5 character encodings.
Mark Wielaard [Wed, 26 Jul 2017 15:38:22 +0000 (17:38 +0200)]
libdw: Add new DWARF5 character encodings.

Add DW_ATE_UCS and DW_ATE_ASCII for Fortran 2003 string kinds ASCII
(ISO/IEC 646:1991) and ISO_10646 (UCS-4 in ISO/IEC 10646:2000).

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agolibdw: Add new DWARF5 tag constants.
Mark Wielaard [Wed, 26 Jul 2017 15:06:07 +0000 (17:06 +0200)]
libdw: Add new DWARF5 tag constants.

Add DW_TAG_coarray_type, DW_TAG_generic_subrange, DW_TAG_dynamic_type,
DW_TAG_call_site, DW_TAG_call_site_parameter, DW_TAG_skeleton_unit,
DW_TAG_immutable_type.

Just the constants, no further interpretion yet.

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agolibdw: Add DWARF5 attributes.
Mark Wielaard [Tue, 25 Jul 2017 13:29:10 +0000 (15:29 +0200)]
libdw: Add DWARF5 attributes.

Add new DWARF5 attribute constant names to the attributes enum.
Also add reserved comments between non-consecutive (reserved) numbers.

Remove DW_AT_subscr_data, DW_AT_element_list and DW_AT_member from the
enum list and turn them into compatibility defines because they are
not part of DWARF2+. That way code that directly references them still
compiles but they won't show up in known-dwarf.h.

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agolibdwfl: Move nested functions in parse_opt to file scope.
Yunlian Jiang [Wed, 26 Jul 2017 23:25:43 +0000 (16:25 -0700)]
libdwfl: Move nested functions in parse_opt to file scope.

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

Signed-off-by: Yunlian Jiang <yunlian@google.com>
7 years agolibdw: Add dwarf_line_file.
Mark Wielaard [Fri, 21 Jul 2017 19:23:07 +0000 (21:23 +0200)]
libdw: Add dwarf_line_file.

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agoppc64: Add HTM SPRs support to readelf
Gustavo Romero [Thu, 20 Jul 2017 21:49:02 +0000 (17:49 -0400)]
ppc64: Add HTM SPRs support to readelf

Since POWER8, PowerPC 64 supports Hardware Transactional Memory, which has
three special purpose registers associated to it: tfhar, tfiar, and texasr.
This commit add HTM SPRs set as known note type so it's possible to use
'readelf --notes' to inspect the HTM SPRs in a coredump file generated in
such a machines.

Signed-off-by: Gustavo Romero <gromero@linux.vnet.ibm.com>
7 years agostrip: Deal with ARM data marker symbols pointing to debug sections.
Mark Wielaard [Thu, 20 Jul 2017 20:34:29 +0000 (22:34 +0200)]
strip: Deal with ARM data marker symbols pointing to debug sections.

ARM data marker symbols "$d" indicate the start of a sequence of data
items in a section. For data only sections no data marker symbol is
necessary, but may be put pointing to the start of the section.
binutils however has a bug which places a data marker symbol somewhere
inside the section (at least for .debug_frame).
https://sourceware.org/bugzilla/show_bug.cgi?id=21809

When strip finds a symbol pointing to a debug section that would be
put into the .debug file then it will copy over the whole symbol table.
This isn't necessary because the symbol is redundant.

Add an ebl hook to recognize data marker symbols with implementations
for arm and aarch64. Use it in strip to strip such symbols from the
symbol table if they point to a debug section.

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agobackends: Don't depend on linux/bpf.h to compile bpf disassembler.
Mark Wielaard [Tue, 18 Jul 2017 12:12:36 +0000 (14:12 +0200)]
backends: Don't depend on linux/bpf.h to compile bpf disassembler.

We only need a few constants and one structure definition from linux/bpf.
Just define those in a local lib/bpf.h file. This makes sure the bpf
disassembler is always build and included even when elfutils is build
on older GNU/Linux systems (and even on other platforms).

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agoWrite to /dev/null rather than /dev/zero
Ulf Hermann [Thu, 4 May 2017 15:27:47 +0000 (17:27 +0200)]
Write to /dev/null rather than /dev/zero

/dev/zero is meant for reading zeroes. /dev/null is for writing into
nirvana.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
7 years agoUnify linking of libasm, libelf, libdw, backends
Ulf Hermann [Fri, 17 Feb 2017 15:11:28 +0000 (16:11 +0100)]
Unify linking of libasm, libelf, libdw, backends

Link them all with -z,defs,-z,relro,--no-undefined, provide complete
dependencies for the link steps, and add libeu.a to each one. libeu.a
contains useful library functionality that each of them might use. The
linker will strip unneeded symbols, so linking it in won't hurt even if
none of the functions are used.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
7 years agobackends: Swap sys/ptrace.h and asm/ptrace.h include order on s390.
Mark Wielaard [Mon, 17 Jul 2017 15:26:25 +0000 (17:26 +0200)]
backends: Swap sys/ptrace.h and asm/ptrace.h include order on s390.

glibc 2.26 changed the sys/ptrace.h header so that it cannot be included
after asm/ptrace.h. We still need to include the kernel asm/ptrace.h for
the ptrace_area definition. Including it after sys/ptrace.h works against
both old and new glibc.

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agostrip: Add --keep-section=SECTION and --remove-section=SECTION.
Mark Wielaard [Fri, 14 Jul 2017 15:09:40 +0000 (17:09 +0200)]
strip: Add --keep-section=SECTION and --remove-section=SECTION.

Adds two new output options:

  --keep-section=SECTION Keep the named section.  SECTION is an extended
                         wildcard pattern.  May be given more than once.

  --remove-section=SECTION   Remove the named section.  SECTION is an
                         extended wildcard pattern.  May be given more than
                         once.  Only non-allocated sections can be removed.

The --remove-section was already partially implemented, but only for the
.comment section. The short option -R is to be compatible with binutils.

The new testcase makes sure that various combinations of kept/removed
sections pull the correct dependencies into the output and/or debug files.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agoSupport EM_PPC machine flags
Andreas Schwab [Thu, 15 Jun 2017 12:14:50 +0000 (14:14 +0200)]
Support EM_PPC machine flags

This fixes the elflint self test when the compiler is configured for PIE
default.

Signed-off-by: Andreas Schwab <schwab@linux-m68k.org>
7 years agostrip: Don't generate empty output file when nothing to do.
Mark Wielaard [Wed, 7 Jun 2017 18:32:38 +0000 (20:32 +0200)]
strip: Don't generate empty output file when nothing to do.

If there was nothing to do strip would skip generating a separate
debug file if one was requested, but it would also not finish the
creation of a new output file (with the non-stripped sections).
Also if there was an error any partially created output would be kept.

Make sure that when the -o output file option is given we always generate
a complete output file (except on error). Also make sure that when the -f
debug file option is given it is only generated when it is not empty.

Add testcase run-strip-nothing.sh that tests the various combinations.

https://sourceware.org/bugzilla/show_bug.cgi?id=21522

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agostrip: Make sure old .shstrab is removed when eu-strip recreates it.
Mark Wielaard [Wed, 7 Jun 2017 12:05:36 +0000 (14:05 +0200)]
strip: Make sure old .shstrab is removed when eu-strip recreates it.

Although we always recreate the .shstrtab section for the new output
file we never explicitly assumed it could be removed. It might not be
possible to remove it when the section string table is shared with
a symbol table. But if it is removable we should (and recreate it for
the new section list).

Regression introduced in commit elfutils-0.163-33-gdf7dfab.
"Handle merged strtab/shstrtab string tables in strip and unstrip."
Add extra testcase to explicitly check for this case.

https://sourceware.org/bugzilla/show_bug.cgi?id=21525

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agoppc64: Add minimal fallback unwinder.
Mark Wielaard [Sun, 21 May 2017 21:33:15 +0000 (23:33 +0200)]
ppc64: Add minimal fallback unwinder.

This adds a minimal fallback unwinder for ppc64[le] in case we cannot find
CFI for a particular address. It simply always sets the program counter to
the link register, picks the previous stack pointer from the backchain,
and the previous link register from the LR save area.

This is enough for some simple situations when we don't have CFI and
seems to work nicely in the case of perf with libdw powerpc support:
https://lkml.org/lkml/2017/5/18/998

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agoPrepare for 0.169. elfutils-0.169
Mark Wielaard [Fri, 5 May 2017 07:47:29 +0000 (09:47 +0200)]
Prepare for 0.169.

Set version to 0.169. Update copyright year. Update po/*.po files.
And add user visible changes to new 0.169 NEWS section.

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agoMake elf section sorting more deterministic
Ulf Hermann [Thu, 20 Apr 2017 14:54:26 +0000 (16:54 +0200)]
Make elf section sorting more deterministic

At least one test (dwfl-addr-sect) depends on the order of elf sections
with equal addresses. This is not guaranteed by the code. Compare also
by end address and section index to tell entries apart.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agoDon't look for kernel version if not running on linux
Ulf Hermann [Thu, 20 Apr 2017 14:08:48 +0000 (16:08 +0200)]
Don't look for kernel version if not running on linux

We don't want to use it, even if it exists.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agoAdd frame pointer unwinding for aarch64 and relax backtrace testcases.
Ulf Hermann [Thu, 20 Apr 2017 12:41:35 +0000 (14:41 +0200)]
Add frame pointer unwinding for aarch64 and relax backtrace testcases.

If we don't find any debug information for a given frame, we usually
cannot unwind any further. However, the binary in question might have
been compiled with frame pointers, in which case we can look up the
well known frame pointer locations in the stack snapshot and use them
to bridge the frames without debug information.

Relax the backtrace core testcases a little by allowing a duplicate
sigusr2 frame or a backtrace ending with an invalid register. Both of
which can happen if the frame pointer unwinder guesses slightly wrong.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agoAdd i386 frame pointer unwinder.
Mark Wielaard [Thu, 6 Apr 2017 22:06:30 +0000 (00:06 +0200)]
Add i386 frame pointer unwinder.

Add a simple i386_unwind.c frame pointer unwinder as fallback if DWARF/CFI
unwinding fails.

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agoAdd frame pointer unwinding as fallback on x86_64
Ulf Hermann [Fri, 10 Feb 2017 14:19:40 +0000 (15:19 +0100)]
Add frame pointer unwinding as fallback on x86_64

If we don't find any debug information for a given frame, we usually
cannot unwind any further. However, the binary in question might have
been compiled with frame pointers, in which case we can look up the
well known frame pointer locations in the stack snapshot and use them
to bridge the frames without debug information.

The "unwind" hook is the right place for this as it is so far only
used on s390 and called only after trying to unwind with debug
information.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
7 years agotests: Add core backtracegen check and regen ppc32 backtrace testfiles.
Mark Wielaard [Tue, 25 Apr 2017 10:41:58 +0000 (12:41 +0200)]
tests: Add core backtracegen check and regen ppc32 backtrace testfiles.

Add a check to check_core to make sure the backtracegen function is
found in the backtrace. This function is in the middle of the backtrace
in the main executable and if not found it means the backtrace was
incomplete or the frame was skipped (which could happen on a bad frame
pointer only unwind).

This showed that the ppc32 backtrace test files were missing DWARF CFI
for the main executable. Regenerated them to include full CFI.

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agoRevert "Optionally allow unknown symbols in the backtrace tests"
Mark Wielaard [Mon, 24 Apr 2017 11:35:47 +0000 (13:35 +0200)]
Revert "Optionally allow unknown symbols in the backtrace tests"

This reverts commit f9971cb422df39adea7e8c7e22689b879e39c626.

Allowing no symbol resolving at all makes it too hard to see
whether the test actually tests anything.

But do keep "address out of range" as allowed error in check_err.
This can be interpreted as DWARF not available (if end of callstack
marker is missing, which it unfortunately often is missing even if CFI
is available.).

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agoAvoid double-including config.h
Ulf Hermann [Thu, 20 Apr 2017 14:31:02 +0000 (16:31 +0200)]
Avoid double-including config.h

config.h doesn't have include guards, so including it twice is bad. We
deal with this by checking for PACKAGE_NAME, but only in some places.
Once we start using gnulib, we will need to include config.h before any
gnulib-generated headers. This is problematic if we include it
transitively through our own private headers.

In order to set a clear rule about inclusion of config.h, it is now
included in every .c file as first header, but not in any header. This
will definitely avoid double-inclusion and satisfy the condition that it
has to be included before gnulib headers. It comes at the price of
adding some redundancy, but there is no clean way to avoid this.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
7 years agoUse F_GETFD rather than F_GETFL to check validity of file descriptor
Ulf Hermann [Thu, 20 Apr 2017 13:58:43 +0000 (15:58 +0200)]
Use F_GETFD rather than F_GETFL to check validity of file descriptor

F_GETFD is both cheaper and easier to port, and otherwise has the same
effect here.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
7 years agoMake __attribute__ conditional in all installed headers
Ulf Hermann [Thu, 20 Apr 2017 13:55:47 +0000 (15:55 +0200)]
Make __attribute__ conditional in all installed headers

__attribute__ is a GNU extension. If we want to link against the
libraries using a different compiler, it needs to be disabled. It was
already disabled in libdw.h, and this patch extends this to the other
headers. We move the defines to libelf.h as that is included in all
the others.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
7 years agoFix nesting of braces
Ulf Hermann [Thu, 27 Apr 2017 14:35:23 +0000 (16:35 +0200)]
Fix nesting of braces

The way it was before it didn't actually test if elf_update failed, but
rather did something random. !!(<some number>) is a boolean and boolean
true can be represented as anything non-0, including negative numbers.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
7 years agoOn elf_update, remember when we mmap()
Ulf Hermann [Thu, 20 Apr 2017 14:57:41 +0000 (16:57 +0200)]
On elf_update, remember when we mmap()

Otherwise we skip the munmap() later. This leaks resources.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
7 years agoAvoid signed/unsigned comparison
Ulf Hermann [Thu, 20 Apr 2017 14:40:30 +0000 (16:40 +0200)]
Avoid signed/unsigned comparison

Some compilers implicitly cast the result of uint_fast16_t *
uint_fast16_t to something signed and then complain about the
comparison to (unsigned) size_t.

Casting phnum to size_t is a good idea anyway as 16bit multiplication
can easily overflow and we are not checking for this.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
7 years agoInclude strings.h to make ffs available
Ulf Hermann [Thu, 20 Apr 2017 14:33:28 +0000 (16:33 +0200)]
Include strings.h to make ffs available

We cannot rely on it to be available from any of the other headers.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
7 years agoProtect against integer overflow on shnum
Ulf Hermann [Thu, 20 Apr 2017 14:04:54 +0000 (16:04 +0200)]
Protect against integer overflow on shnum

If shnum is 0, the many "shnum - 1" would result in an overflow. Check it
for 0, and only subtract once, rather than on every usage.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
7 years agoAdd EXEEXT to gendis
Ulf Hermann [Thu, 20 Apr 2017 15:02:42 +0000 (17:02 +0200)]
Add EXEEXT to gendis

Otherwise the build will fail on systems that actually need file
extension for executables.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
7 years agoInclude endian.h when handling BYTE_ORDER
Ulf Hermann [Thu, 20 Apr 2017 15:07:37 +0000 (17:07 +0200)]
Include endian.h when handling BYTE_ORDER

BYTE_ORDER and friends are customarily defined in endian.h.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
7 years agoAdd missing entries to .gitignore
Ulf Hermann [Fri, 21 Apr 2017 16:51:08 +0000 (18:51 +0200)]
Add missing entries to .gitignore

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
7 years agoAvoid YESSTR and NOSTR
Ulf Hermann [Thu, 20 Apr 2017 13:47:49 +0000 (15:47 +0200)]
Avoid YESSTR and NOSTR

Those are deprecated and apparently some implementations of nl_langinfo
return empty strings for them. The tests even tested for those empty
strings even though the intention of the code was clearly to output
"yes" or "no" there.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
7 years agoDon't use comparison_fn_t
Ulf Hermann [Thu, 20 Apr 2017 13:40:46 +0000 (15:40 +0200)]
Don't use comparison_fn_t

Not all search.h declare it, and it is not very helpful anyway.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
7 years agoClean up linux-specific system includes
Ulf Hermann [Thu, 20 Apr 2017 13:37:04 +0000 (15:37 +0200)]
Clean up linux-specific system includes

We only include them where we actually need them and only on linux.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
7 years agoInclude sys/types.h before fts.h
Ulf Hermann [Thu, 20 Apr 2017 14:45:51 +0000 (16:45 +0200)]
Include sys/types.h before fts.h

The bad fts not only needs to be included before config.h, but also
requires various special types without including sys/types.h.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
7 years agolibelf: Initialize n to zero in elf_getarsym.
Mark Wielaard [Wed, 19 Apr 2017 15:07:46 +0000 (17:07 +0200)]
libelf: Initialize n to zero in elf_getarsym.

When building with gcc -Os it seems we can inline read_number_entries
but if that function fails then n will not be initialized. GCC seems not
to realize that in that case n won't be used at all. Explicitly initialize
n to zero to prevent a spurious error: 'n' may be used uninitialized in
this function [-Werror=maybe-uninitialized] in that case.

https://sourceware.org/bugzilla/show_bug.cgi?id=21011

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agoAdd missing peel_type.c test for commit f339da.
Mark Wielaard [Thu, 6 Apr 2017 22:13:47 +0000 (00:13 +0200)]
Add missing peel_type.c test for commit f339da.

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agoelflint: Support checking ELF files with compressed sections.
Mark Wielaard [Wed, 5 Apr 2017 15:09:27 +0000 (17:09 +0200)]
elflint: Support checking ELF files with compressed sections.

Simply unconditionally uncompress any section to make sure indexes between
sections check out. Add some testcases with various compressed sections.

https://sourceware.org/bugzilla/show_bug.cgi?id=21332

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agolibdw: Fix dwarf_peel_type infinite loop.
Mark Wielaard [Thu, 30 Mar 2017 10:19:53 +0000 (12:19 +0200)]
libdw: Fix dwarf_peel_type infinite loop.

We were calling dwarf_attr_integrate () in the die in the loop instead of
on the result. Which would cause an infinite loop when die != result.
Add a testcase that explicitly checks this case.

https://sourceware.org/bugzilla/show_bug.cgi?id=21330

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agoelflint: Don't check section group without flags word.
Mark Wielaard [Tue, 28 Mar 2017 11:33:03 +0000 (13:33 +0200)]
elflint: Don't check section group without flags word.

https://sourceware.org/bugzilla/show_bug.cgi?id=21320

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agoelflint: Sanity check the number of phdrs and shdrs available.
Mark Wielaard [Mon, 27 Mar 2017 23:25:34 +0000 (01:25 +0200)]
elflint: Sanity check the number of phdrs and shdrs available.

Make sure we can at least read the shnum sections or phnum segments.
Limit the number we do check to those we can actually read.

https://sourceware.org/bugzilla/show_bug.cgi?id=21312

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agoelflint: Don't trust sh_entsize when checking hash sections.
Mark Wielaard [Mon, 27 Mar 2017 22:38:52 +0000 (00:38 +0200)]
elflint: Don't trust sh_entsize when checking hash sections.

Calculate and use the expected entsize instead of relying on the one
given by the ELF file section header. Return early if there isn't enough
data in the section to check the full hash table.

https://sourceware.org/bugzilla/show_bug.cgi?id=21311

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agoelflint: Check symbol table data is big enough before checking.
Mark Wielaard [Mon, 27 Mar 2017 21:59:02 +0000 (23:59 +0200)]
elflint: Check symbol table data is big enough before checking.

Before checking symbol index zero we should make sure the data size
is big enough.

https://sourceware.org/bugzilla/show_bug.cgi?id=21310

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agolibelf: Always update last_offset in updatefile and updatemmap.
Mark Wielaard [Mon, 27 Mar 2017 15:01:57 +0000 (17:01 +0200)]
libelf: Always update last_offset in updatefile and updatemmap.

When ELF section data was used, but not updated or marked as dirty and
there also existed non-dirty sections and some padding was needed between
the sections (possibly because of alignment) then elf_update might write
"fill" over some of the existing data. This happened because in that case
the last_position was not updated correctly.

Includes a new testcase fillfile that fails before this patch by showing
fill instead of the expected data in some section data. It succeeds with
this patch.

https://sourceware.org/bugzilla/show_bug.cgi?id=21199

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agolibelf: Check compression ratio before trying to allocate output buffer.
Mark Wielaard [Fri, 24 Mar 2017 14:06:04 +0000 (15:06 +0100)]
libelf: Check compression ratio before trying to allocate output buffer.

The maximum compression factor (http://www.zlib.net/zlib_tech.html) is
1032:1. Add a sanity check for that before trying to allocate lots of
memory and trying to decompress lots of bogus data.

https://sourceware.org/bugzilla/show_bug.cgi?id=21301

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agoUse the empty string for note names with zero size (without any data).
Mark Wielaard [Fri, 24 Mar 2017 13:10:26 +0000 (14:10 +0100)]
Use the empty string for note names with zero size (without any data).

ELF notes can have a zero sized name. In which case there is no data at
all (so also no zero terminator). Make sure to use the empty string for
such notes if the code does not otherwise explicitly check n_namesz.

https://sourceware.org/bugzilla/show_bug.cgi?id=21300

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agoreadelf: Fix off by one sanity check in handle_gnu_hash.
Mark Wielaard [Fri, 24 Mar 2017 11:15:02 +0000 (12:15 +0100)]
readelf: Fix off by one sanity check in handle_gnu_hash.

We sanity check to make sure we don't index outside the chain array
by testing inner > max_nsyms. But inner is a zero-based index, while
max_nsyms is the maximum number. Change the check to inner >= max_nsyms.

https://sourceware.org/bugzilla/show_bug.cgi?id=21299

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agolibasm: Fix one GCC7 -Wformat-truncation=2 warning.
Mark Wielaard [Sun, 12 Feb 2017 20:51:34 +0000 (21:51 +0100)]
libasm: Fix one GCC7 -Wformat-truncation=2 warning.

Make sure that if we have really lots of labels the tempsym doesn't get
truncated because it is too small to hold the whole name.

This doesn't enable -Wformat-truncation=2 or fix other "issues" pointed
out by enabling this warning because there are currently some issues
with it. https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79448

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agobackends: Add support for EM_PPC64 GNU_ATTRIBUTES.
Mark Wielaard [Wed, 15 Feb 2017 13:30:27 +0000 (14:30 +0100)]
backends: Add support for EM_PPC64 GNU_ATTRIBUTES.

ppc64 and ppc64le ELF files can also contain a power specific
.gnu.attributes section. Add support for those and recognize the new
GNU_Power_ABI_FP Single-precision hard float value.

Signed-off-by: Mark Wielaard <mark@klomp.org>