Mark Wielaard [Fri, 16 Feb 2018 19:34:25 +0000 (20:34 +0100)]
tests: Accept any core if no core with the "correct" pid can be found.
In some containers our view of pids is confused. We see the container
pid namespace, but the core is generated using the host pid namespace.
Since tests are run in a new fresh directory any core here is most like
is ours.
Mark Wielaard [Thu, 15 Feb 2018 13:44:18 +0000 (14:44 +0100)]
Include sys/ptrace.h as early as possible.
On some systems, at least on Fedora 27 ppc64le with glibc 2.26-24 and
kernel 4.14.18-300, including sys/ptrace.h late (after signal.h or
sys/wait.h for example) will cause issues and produce errors like:
In file included from /usr/include/asm/sigcontext.h:12:0,
from /usr/include/bits/sigcontext.h:30,
from /usr/include/signal.h:287,
from /usr/include/sys/wait.h:36,
from linux-pid-attach.c:38:
/usr/include/sys/ptrace.h:73:3: error: expected identifier before numeric constant
PTRACE_GETREGS = 12,
^
Mark Wielaard [Thu, 25 Jan 2018 00:13:10 +0000 (01:13 +0100)]
libdw: Add dwarf_die_addr_die function.
Currently storing a lot of Dwarf_Dies might be inefficient since it
costs a lot of memory since the sizeof (Dwarf_Die) == 32 bytes on 64bit
arches. You can try storing just the Dwarf_Off from dwarf_dieoffset.
Which is just 8 bytes. But then you have to keep track of whether to
call dwarf_dieoffset, if the Dwarf_Die came from the main .debug_info,
or call dwarf_dieoffset_types, if it came from .debug_types. And you'll
have to keep track of whether it came from the main Dwarf or the alt
Dwarf (dwz multi file). With DWARF5 or GNU DebugFission split-dwarf
you will also need to know which split Dwarf file the original DIE
came from.
A Dwarf_Die consists of an addr pointer where the actual DIE data
comes from, a CU pointer that provides context (and has a pointer
to the Dwarf file the Die is associated with) and a (cached)
Dwarf_Abbrev pointer that is initialized when the Dwarf_Die is
first read and describes how to interpret the DIE data.
libdw already keeps track of the data pointers (sections) of a
Dwarf file and given an offset it can already reconstruct the
other Dwarf_Die fields. So this patch introduces dwarf_die_addr_die.
Given a Dwarf_Die addr dwarf_die_addr_die returns a (reconstructed)
Dwarf_Die, or NULL if the given addr didn't come from a valid
Dwarf_Die. In particular it will make sure that the correct Dwarf_CU
pointer is set for the Dwarf_Die, the Dwarf_Abbrev pointer will not
be set up yet (it will only be once the Dwarf_Die is used to read
attributes, children or siblings).
This functions can be used to keep a reference to a Dwarf_Die which
you want to refer to later. The addr, and the result of this function,
is only valid while the associated Dwarf is valid.
Since libdw already had to lookup the Dwarf_CU given an offset, this
function is as efficient as dwarf_dieoffset (or dwarf_dieoffset_types)
without having to know the original origin of the Dwarf_Die. It will
search both the .debug_info and .debug_types data sections from both
the main Dwarf or the alt Dwarf file. Once split dwarf support is added
it will also look in any split dwarf .dwo (or the .dwp) file.
The only limitation, compared to using a Dwarf_Off and dwarf_dieoffset,
is that it only works during runtime while the main Dwarf object is
valid (till dwarf_end has been called on it).
Joshua Watt [Fri, 9 Feb 2018 16:27:18 +0000 (10:27 -0600)]
Use fallthrough attribute.
Use __attribute__ ((fallthrough)) to indicate switch case fall through
instead of a comment. This ensures that the fallthrough warning is not
triggered even if the file is pre-processed (hence stripping the
comments) before it is compiled.
The actual fallback implementation is hidden behind a FALLBACK macro in
case the compiler doesn't support it.
Finally, the -Wimplict-fallthrough warning was upgraded to only allow
the attribute to satisfy it; a comment alone is no longer sufficient.
Mark Wielaard [Fri, 19 Jan 2018 22:59:21 +0000 (23:59 +0100)]
libdw: Resolve alt file on first use.
Add a new alt_fd field to the Dwarf struct. This tracks whether we tried
to open the alt file ourselves. This is used in dwarf_getalt to see if
we should try to find and open the alt file ourselves (if the user hasn't
called dwarf_setalt yet). dwarf_formref_die and dwarf_formstring now call
dwarf_getalt instead of accessing the alt_dwarf Dwarf field directly.
For applications using libdwfl nothing changes (dwfl will find, set and
clean up the alt file). For programs that set the alt file themselves
already through other means, nothing changes. But for applications that
don't create the Dwarf through libdwfl and don't set the alt file already
libdw will now try to find and set it on first access. If found the
application will now not get errors for missing alt files.
Add a simple testcase based on the existing allfcts test which already
tries to set the alt file, but is too simplistic to find it in some
subdir (relative to the main debug file).
Mark Wielaard [Thu, 25 Jan 2018 13:37:17 +0000 (14:37 +0100)]
tests: Check symtabshdr instead of symtabndx in elfstrmerge.c.
Some gcc omptimization levels (-Og in particular) didn't see that when
symtabndx != 0, then symtabshdr was certain to be initialized. Change
the symtabndx == 0 check to symtabshdr == NULL and initialize symtabshdr
to work around that.
Mark Wielaard [Thu, 25 Jan 2018 12:24:19 +0000 (13:24 +0100)]
readelf: Fix crash on reading loc data or range data with bad/no CUs.
In print_debug_ranges_section and print_debug_loc_section we try to
get the associated CU through skip_listptr_hole for the first data data.
If no CU at all can be found (because the .debug_info section was bogus)
this would keep the Dwarf_CU uninitialized causing a crash later on
when it was compared to the last_cu and used because it was unequal.
Fix this by explicitly initializing cu to last_cu (which is NULL on
first use).
Petr Machata [Sun, 14 Jan 2018 02:22:05 +0000 (03:22 +0100)]
libdw: dwarf_formsdata should return a signed value
The function dwarf_formsdata is used for decoding signed values, but
except for the variable-length DW_FORM_sdata, it uses unsigned
primitives to decode the value. This is not a problem for 64-bit values,
but the smaller values come decoded wrong. Fix by changing to signed
primitives for decoding the fixed-length forms.
Add a test case that uses dwarf_aggregate_size to determine an array
size whose lower bound is -1, encoded using DW_FORM_data1, and upper
bound 255 with DW_FORM_data2. When the -1 is decoded wrongly, it comes
back as 255, and the array size is 1. The correct array size should be
257.
Mark Wielaard [Tue, 26 Dec 2017 15:49:46 +0000 (16:49 +0100)]
libdw: Reduce size of struct Dwarf_Abbrev.
If we don't cache the attrcnt and use bitfields for the has_children and
code we can reduce the size of struct Dwarf Abbrev from 32 to 24 bytes on
64bit architectures and from 28 to 20 bytes on 32bit arches.
Mark Wielaard [Tue, 26 Dec 2017 10:52:06 +0000 (11:52 +0100)]
libdw: New get_uleb128_unchecked to use with already checked Dwarf_Abbrev.
When creating a Dwarf_Abbrev in dwarf_getabbrev (__libdw_getabbrev) we
already check it is fully readable from the .debug_abbrev section. So
whenever we reread it later using the attrp pointer we don't have to
check it again. Introduce get_uleb128_unchecked to use for ulebs we
know are safe to read directly.
Mark Wielaard [Mon, 1 Jan 2018 21:39:24 +0000 (22:39 +0100)]
readelf: Use dwarf_form_name for printing (unknown) forms.
Use dwarf_form_name consistently to print forms. attr_callback was
using its own string conversion, print_debug_macro_section was using
dwarf_form_string instead of dwarf_form_name.
The difference between dwarf_form_string and dwarf_form_name is that
the first returns NULL if the form is unknown and the second returns
an hexadecimal string representation in that case.
Mark Wielaard [Sat, 23 Dec 2017 22:16:24 +0000 (23:16 +0100)]
tests: Try to use coredumpctl to extract core files.
If systemd-coredump is installed we have to use coredumpctl to extract
the core file to test. Unfortunately systemd-coredump/coredumpctl seem
to be somewhat fragile if multiple core dumps are generated/extracted
at the same time. So use a lock file to only run one core dump test at
a time (under make -j).
Mark Wielaard [Thu, 28 Dec 2017 23:34:14 +0000 (00:34 +0100)]
libdw: Check there is .debug_info/types section data in __libdw_offdie.
If a Dwarf_Die was requested from an offset into a section data that
didn't exist we would crash. Crashing is bad even if given bad input.
Just return an error in that case.
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.
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.
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).
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.
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.
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.
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.
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.
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.
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
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).
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).
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
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.
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.
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.
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.
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.
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.
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>
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>
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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).
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.
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.
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.
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.
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.
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
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>
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>
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.
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.
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.).
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.
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.
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.
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.
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.