]> git.ipfire.org Git - thirdparty/elfutils.git/log
thirdparty/elfutils.git
7 years agoExplicitly qualify specializations of elfutils::to_string dwarflint
David Malcolm [Fri, 23 Feb 2018 14:54:02 +0000 (09:54 -0500)] 
Explicitly qualify specializations of elfutils::to_string

I attempted to build the "dwarflint" branch with gcc 7.3.1 , but ran
into various problems of the form:

c++/known.cc:220:1: error: explicit specialization of ‘template<class type> std::__cxx11::string elfutils::to_string(const type&)’ outside its namespace must use a nested-name-specifier [-fpermissive]
 to_string<dwarf::dwarf_enum> (const dwarf::dwarf_enum &value)
 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~

The fix appears to be trivial.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
7 years agoAdd support for dwarflint testing
Djordje Todorovic [Thu, 28 Sep 2017 07:33:40 +0000 (09:33 +0200)] 
Add support for dwarflint testing

* dwarflint/tests: Update all scripts and makefiles to work
with current test environment.
* dwarflint/Makefile.am: Add support for dwarflint testing.
* tests/test-subr.sh: Update to be used in dwarflint/tests.
* tests/test-wrapper.sh: Likewise.
* tests/run-dwarflint-self.sh: Return back into tests/.

Signed-off-by: Djordje Todorovic <djordje.todorovic@rt-rk.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agodwarflint: Remember the referring CU when read src lines
Djordje Todorovic [Tue, 26 Sep 2017 13:45:10 +0000 (15:45 +0200)] 
dwarflint: Remember the referring CU when read src lines

Signed-off-by: Djordje Todorovic <djordje.todorovic@rt-rk.com>
7 years agolibdw: Proper handling of DW_AT_high_pc
Djordje Todorovic [Tue, 26 Sep 2017 13:43:43 +0000 (15:43 +0200)] 
libdw: Proper handling of DW_AT_high_pc

Since DWARF4 DW_AT_high_pc may be a constant.
Which should be added to the DW_AT_low_pc value to get the address.

Signed-off-by: Djordje Todorovic <djordje.todorovic@rt-rk.com>
7 years agoAdd support for DW_OP_GNU_parameter_ref to dwarf-opcodes.h
Mark Wielaard [Fri, 6 Oct 2017 13:19:05 +0000 (15:19 +0200)] 
Add support for DW_OP_GNU_parameter_ref to dwarf-opcodes.h

Signed-off-by: Djordje Todorovic <djordje.todorovic@rt-rk.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agodwarflint: Avoid corrupted access
Djordje Todorovic [Tue, 26 Sep 2017 13:40:25 +0000 (15:40 +0200)] 
dwarflint: Avoid corrupted access

Signed-off-by: Djordje Todorovic <djordje.todorovic@rt-rk.com>
7 years agodwarflint: Report summary for sub-category of variables
Djordje Todorovic [Tue, 26 Sep 2017 13:33:13 +0000 (15:33 +0200)] 
dwarflint: Report summary for sub-category of variables

Add new option --sub-category of locstats that reports
summary for either for local variables or formal parameters.

* dwarflint/locstats.cc: Handle the option.

Signed-off-by: Djordje Todorovic <djordje.todorovic@rt-rk.com>
7 years agoC++ build fixes.
Mark Wielaard [Mon, 2 Oct 2017 14:06:30 +0000 (16:06 +0200)] 
C++ build fixes.

Add AX_CXX_COMPILE_STDCXX_11 and AX_CXX_COMPILE_STDCXX from the
autoconf-archive. Use it in configure.ac to make sure we get a
C++11 capable compiler. Add various c++ sources to libdw/Makefile.am.
Change INCLUDES in dwarflint/Makefile.am to AM_CPPFLAGS to support
newer automake.

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agolibdw: Update code to work with current version of elfutils
Djordje Todorovic [Tue, 26 Sep 2017 13:23:35 +0000 (15:23 +0200)] 
libdw: Update code to work with current version of elfutils

Signed-off-by: Djordje Todorovic <djordje.todorovic@rt-rk.com>
7 years agodwarflint: Update code to work with current version of elfutils
Djordje Todorovic [Tue, 26 Sep 2017 13:20:04 +0000 (15:20 +0200)] 
dwarflint: Update code to work with current version of elfutils

Signed-off-by: Djordje Todorovic <djordje.todorovic@rt-rk.com>
7 years agoAdd files needed by c++ module from dwarf branch.
Djordje Todorovic [Tue, 26 Sep 2017 13:15:44 +0000 (15:15 +0200)] 
Add files needed by c++ module from dwarf branch.

* src/dwarf-opcodes.h: Return back the file.
* src/dwarfstrings.c: Likewise.
* src/dwarfstrings.h: Likewise.

Signed-off-by: Djordje Todorovic <djordje.todorovic@rt-rk.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
7 years agoAdd support for building C++
Djordje Todorovic [Tue, 26 Sep 2017 13:12:44 +0000 (15:12 +0200)] 
Add support for building C++

* configure.ac: Add support for C++ build.
* Makefile.am: Add dwarflint into SUBDIRS.

Signed-off-by: Djordje Todorovic <djordje.todorovic@rt-rk.com>
7 years agoAdd dwarflint/ from origin/dwarf branch
Djordje Todorovic [Tue, 26 Sep 2017 12:21:47 +0000 (14:21 +0200)] 
Add dwarflint/ from origin/dwarf branch

Signed-off-by: Djordje Todorovic <djordje.todorovic@rt-rk.com>
7 years agoAdd libdw/c++/ from origin/dwarf branch
Djordje Todorovic [Tue, 26 Sep 2017 13:11:06 +0000 (15:11 +0200)] 
Add libdw/c++/ from origin/dwarf branch

Signed-off-by: Djordje Todorovic <djordje.todorovic@rt-rk.com>
7 years agolibdw: Add ELFUTILS_PRIVATE_TMP version
Djordje Todorovic [Tue, 26 Sep 2017 12:19:34 +0000 (14:19 +0200)] 
libdw: Add ELFUTILS_PRIVATE_TMP version

This hack is needed for libdw/c++/values.cc.

Signed-off-by: Djordje Todorovic <djordje.todorovic@rt-rk.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
7 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>
7 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>
7 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>
7 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>
7 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 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>
8 years agoMove print_version into printversion.{h|c}
Ulf Hermann [Thu, 16 Feb 2017 11:32:02 +0000 (12:32 +0100)] 
Move print_version into printversion.{h|c}

Rename version.c so that the implementation is called after the header
and the header doesn't clash with the toplevel version.h. print_version
depends on argp and is only used in the tools.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
8 years agoCheck for existence of mempcpy
Ulf Hermann [Thu, 16 Feb 2017 09:10:30 +0000 (10:10 +0100)] 
Check for existence of mempcpy

If it doesn't exist, provide a definition based on memcpy.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
8 years agoAlways use the same method to query the system page size
Ulf Hermann [Wed, 15 Feb 2017 14:28:38 +0000 (15:28 +0100)] 
Always use the same method to query the system page size

This makes it easier to write a replacement for it on systems where
sysconf(3) doesn't exist.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
8 years agoMove color handling into a separate header
Ulf Hermann [Tue, 14 Feb 2017 13:30:47 +0000 (14:30 +0100)] 
Move color handling into a separate header

We only need it in nm.c and objdump.c, but it pulls in argp as
dependency. By dropping it from libeu.h, the libraries can be
compiled without argp.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
8 years agoAdd -D_FORTIFY_SOURCE=2 to CFLAGS if possible.
Mark Wielaard [Thu, 9 Feb 2017 20:09:54 +0000 (21:09 +0100)] 
Add -D_FORTIFY_SOURCE=2 to CFLAGS if possible.

Some distros now add -D_FORTIFY_SOURCE=2 by default and we have missed
some issues in the past caught by it. Add it to CFLAGS if possible.
The configure check will make sure that it doesn't conflict with any
other CFLAGS already defined.

Signed-off-by: Mark Wielaard <mark@klomp.org>
8 years agoOptionally allow unknown symbols in the backtrace tests
Ulf Hermann [Fri, 10 Feb 2017 14:19:40 +0000 (15:19 +0100)] 
Optionally allow unknown symbols in the backtrace tests

This is useful to test unwinding without debug information. The
binaries being examined might still have frame pointers that allow
us to bridge the unknown symbols.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
8 years agoMake the backtrace-data test helper more robust
Ulf Hermann [Fri, 10 Feb 2017 14:19:01 +0000 (15:19 +0100)] 
Make the backtrace-data test helper more robust

When unwinding by frame pointer the unwinder might ask for invalid
addresses. We don't have to fail the test in this case. In fact
any broken dwarf information can lead to requests for invalid
addresses, also without frame pointer unwinding.

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
8 years agoAdd missing tests to .gitignore
Ulf Hermann [Fri, 10 Feb 2017 14:18:10 +0000 (15:18 +0100)] 
Add missing tests to .gitignore

Some test binaries were missing and showed up in "git status".

Signed-off-by: Ulf Hermann <ulf.hermann@qt.io>
8 years agoDefine PACKAGE_URL for older autoconf.
Mark Wielaard [Thu, 12 Jan 2017 10:43:30 +0000 (11:43 +0100)] 
Define PACKAGE_URL for older autoconf.

autoconf < 2.64 doesn't define PACKAGE_URL through AC_INIT.
Define it ourselves if needed.

Signed-off-by: Mark Wielaard <mark@klomp.org>
8 years agoFix TEMP_FAILURE_RETRY definition when not defined.
Luiz Angelo Daros de Luca [Thu, 29 Dec 2016 23:02:57 +0000 (21:02 -0200)] 
Fix TEMP_FAILURE_RETRY definition when not defined.

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

Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
8 years agoUpdate Polish translation
Piotr Drąg [Thu, 29 Dec 2016 16:54:13 +0000 (17:54 +0100)] 
Update Polish translation

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

Signed-off-by: Piotr Drąg <piotrdrag@gmail.com>