platform/upstream/elfutils.git
3 years agolibelf: Fix unaligned d_off offsets for input sections with large alignments
Andrei Homescu [Tue, 29 Jun 2021 01:26:53 +0000 (18:26 -0700)]
libelf: Fix unaligned d_off offsets for input sections with large alignments

The mkl_memory_patched.o object inside the libmkl_core.a library from
the Intel Math Kernel Library version 2018.2.199 has this section
with an alignment of 4096 and offset of 0xb68:
 [ 2] .data PROGBITS 0000000000000000 000b68 011000 00 WA 0 0 4096

Reading this file with libelf and trying to write it back to disk triggers
the following sequence of events:
1) code in elf_getdata.c clamps d_align for this section's data buffer
   to the section's offset
2) code in elf32_updatenull.c checks if the alignment is a power of two
   and incorrectly returns an error

This commit fixes this corner case by increasing the alignment to the
next power of two after the clamping, so the check passes.

A test that reproduces this bug using strip is also included.

Signed-off-by: Andrei Homescu <ah@immunant.com>
3 years agoreadelf: Handle line tables without line number statements correctly
Mark Wielaard [Sat, 3 Jul 2021 22:08:32 +0000 (00:08 +0200)]
readelf: Handle line tables without line number statements correctly

When we see a line table without line number statements we need to
continue with the next table. Add a testcase for this situation.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agoreadelf: Fix error message when two attribute names differ in in compare_listptr.
Mark Wielaard [Sat, 3 Jul 2021 16:56:54 +0000 (18:56 +0200)]
readelf: Fix error message when two attribute names differ in in compare_listptr.

We were printing the second attribute name twice. Print the first and second.

Reported-by: Gabriel Valky <gvalky@tachyum.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agounstrip: Always check gelf_getrel[a] results
Mark Wielaard [Fri, 18 Jun 2021 13:08:48 +0000 (15:08 +0200)]
unstrip: Always check gelf_getrel[a] results

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agostrip: Always check gelf_update results.
Mark Wielaard [Fri, 18 Jun 2021 13:06:32 +0000 (15:06 +0200)]
strip: Always check gelf_update results.

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agodebuginfod-client: Fix client dereference when calloc fails.
Mark Wielaard [Fri, 18 Jun 2021 13:02:43 +0000 (15:02 +0200)]
debuginfod-client: Fix client dereference when calloc fails.

When the calloc call in debuginfod_begin fails we should skip all
initialization of the client handle.

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agorun-debuginfod-find.sh: Disable valgrind for debuginfod client cache tests
Mark Wielaard [Fri, 2 Jul 2021 18:26:52 +0000 (20:26 +0200)]
run-debuginfod-find.sh: Disable valgrind for debuginfod client cache tests

valgrind itself might use the debuginfod client. So disable valgrind
when testing the cache.

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agodebuginfod test: fix groom/stale race condition
Frank Ch. Eigler [Wed, 16 Jun 2021 22:49:10 +0000 (18:49 -0400)]
debuginfod test: fix groom/stale race condition

Additional tracing, and use of "% make check VERBOSE=1" in a .spec
file allowed tracking down of this intermittent problem.  The race was
between a SIGUSR1 or two to a debuginfod server (triggering two
traverse/scan phases), followed shortly by a SIGUSR2 (triggering a
groom).  If those signals were received too close together, the groom
phase could be stopped early, and the rm'd files not noticed.

New testsuite code adds metric polls after SIGUSR1 & SIGUSR2 to ensure
the respective processing phases are complete.  It also turns on "set -x"
tracing, so as to avoid pulling out quite as much hair next time.
"make check VERBOSE=1" is also important for spec files.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3 years agodebuginfod tests: tolerate 000-perm files in cache-copy test
Frank Ch. Eigler [Wed, 16 Jun 2021 14:49:49 +0000 (10:49 -0400)]
debuginfod tests: tolerate 000-perm files in cache-copy test

It appears possible for 000-permission files to sneak into the
test debuginfod-cache, which cp (or find|cpio) refuse to copy.
These files are OK not to copy, so ignore the error and proceed.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3 years agodebuginfod tests: try to generate diagnostics more reliably on error
Frank Ch. Eigler [Wed, 16 Jun 2021 00:04:53 +0000 (20:04 -0400)]
debuginfod tests: try to generate diagnostics more reliably on error

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3 years agolibdwfl: fix potential NULL pointer dereference when reading link map
Omar Sandoval [Thu, 10 Jun 2021 00:45:57 +0000 (17:45 -0700)]
libdwfl: fix potential NULL pointer dereference when reading link map

When read_addrs() was moved into file scope, there was a mistake in
converting "buffer" from a closure variable to a parameter: we are
checking whether the pointer argument is NULL, not whether the buffer
itself is NULL.  This causes a NULL pointer dereference when we try
to use the NULL buffer later.

Fixes: 3bf41d458fb6 ("link_map: Pull read_addrs() into file scope")
Signed-off-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agoPR27863: debuginfod optimization for concurrent requests
Frank Ch. Eigler [Fri, 4 Jun 2021 12:40:11 +0000 (08:40 -0400)]
PR27863: debuginfod optimization for concurrent requests

Sometimes, due to configuration error, mishap, or DoS misadventure, a
debuginfod server may receive near-concurrent requests for the exact
same data from multiple clients.  In practically all cases, it is
beneficial to the clients, as well as the server, to serialize these
requests.  This way, debuginfod does not waste CPU in repeatedly &
concurrently decompressing large archives or querying upstream
servers.  Second and later requesters can benefit from the fdcache /
client-cache and get their results, probably earlier!

This patch adds an "after-you" queueing phase to servicing
http-buildid requests, whereby thereads serialize themselves on each
query URL being serviced at the moment.  Prometheus metrics are added,
and the http GET trace line is modified to print the queue+service
times separately.

Hand-tested on large kernel-debuginfo's, and shows host CPU refusing
to multiply in the face of concurrent identical queries.  The
automated test tries a hundred concurrent curls, at least some of
which are slow enough to trigger the "after-you" wait here.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3 years agoelflint: fix undefined 'buffer_left' reference
Sergei Trofimovich [Mon, 7 Jun 2021 21:37:42 +0000 (22:37 +0100)]
elflint: fix undefined 'buffer_left' reference

Link failure is reproducible on gcc-11.1.0 target:

```
$ autoreconf -i -f
$ ./configure --enable-maintainer-mode --disable-debuginfod \
    --host=x86_64-pc-linux-gnu \
    CFLAGS=-march=znver3 \
    CXXFLAGS=-march=znver3 \
    LDFLAGS=" "
$ make

  CCLD     elflint
ld: elflint.o: in function `check_attributes':
elflint.c:(.text+0xdcff): undefined reference to `buffer_left'
ld: elflint.c:(.text+0xe557): undefined reference to `buffer_left'
```

It happens due to possible external linkage of `buffer_left()`.

The change forces local linkage to always use local definition
(either inline or out-of-line).

Reported-by: Toralf Förster
Bug: https://bugs.gentoo.org/794601
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
Fixes: e95d1fbb ("elflint: Pull left() in file scope")
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agoPrepare for 0.185 elfutils-0.185
Mark Wielaard [Sat, 22 May 2021 13:41:43 +0000 (15:41 +0200)]
Prepare for 0.185

Set version to 0.185
Update NEWS and elfutils.spec.in
Regenerate po/*.po files

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agoPR27859: correct 404-latch bug in debuginfod client reuse
Frank Ch. Eigler [Fri, 14 May 2021 22:37:30 +0000 (18:37 -0400)]
PR27859: correct 404-latch bug in debuginfod client reuse

PR27701 implemented curl handle reuse in debuginfod_client objects,
but with an unexpected bug.  Server responses returning an error
"latched" because the curl_easy handles for error cases weren't all
systematically removed from the curl multi handle.  This prevented
their proper re-addition the next time.

This version of the code simplfies matters by making only the curl
curl_multi handle long-lived.  This turns out to be enough, because it
can maintain a pool of long-lived http/https connections and related
data, and lend them out to short-lived curl_easy handles.  This mode
handles errors or hung downloads even better, because the easy handles
don't undergo complex state transitions between reuse.

A new test case confirms this correction via the federating debuginfod
instance (cleaning caches between subtests to make sure http* is being
used and reused).

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3 years agoelfcompress: fix exit status in case of an error
Dmitry V. Levin [Wed, 12 May 2021 16:00:00 +0000 (16:00 +0000)]
elfcompress: fix exit status in case of an error

Exit status of 255 in case of an error is probably not what elfcompress
users expect, change it to 1.

Reported-by: Vitaly Chikunov <vt@altlinux.org>
Fixes: 92acb57eb046 ("elfcompress: New utility.")

3 years agoelfcompress: remove redundant assignment
Dmitry V. Levin [Wed, 12 May 2021 15:00:00 +0000 (15:00 +0000)]
elfcompress: remove redundant assignment

At the point of "Nothing to do" fnew variable has not been assigned
after initialization, so it does not have to be reset to NULL.

Note that any reset of fnew to NULL has to preceded with free(fnew).

Fixes: ed62996defc6 ("elfcompress: Don't rewrite file if no section data needs to be updated.")

3 years agoelfcompress: fix exit status regression in case of "Nothing to do"
Dmitry V. Levin [Wed, 12 May 2021 15:00:00 +0000 (15:00 +0000)]
elfcompress: fix exit status regression in case of "Nothing to do"

When elfcompress decides that no section data needs to be updated and
therefore the file does not have to be rewritten, it still has to exit
with a zero status indicating success.

Resolves: https://sourceware.org/bugzilla/show_bug.cgi?id=27856
Fixes: c497478390de ("elfcompress: Replace cleanup() with label")

3 years agoCome up with startswith function.
Martin Liska [Mon, 19 Apr 2021 12:33:36 +0000 (14:33 +0200)]
Come up with startswith function.

New function in system.h that returns true if a string has a given
prefix, false otherwise.  Use it in place of strncmp.

Signed-off-by: Martin Liška <mliska@suse.cz>
3 years agoelfutils.spec: Add procps as a %check BuildRequires:.
Frank Ch. Eigler [Tue, 11 May 2021 19:57:42 +0000 (15:57 -0400)]
elfutils.spec: Add procps as a %check BuildRequires:.

On Fedora rawhide, we can no longer just assume ps(1) is there.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3 years agoPrepare for 0.184 elfutils-0.184
Mark Wielaard [Mon, 10 May 2021 12:13:53 +0000 (14:13 +0200)]
Prepare for 0.184

Set version to 0.184
Update NEWS and elfutils.spec.in
Regenerate po/*.po files

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agolibdw: Document and handle DW_FORM_indirect in __libdw_form_val_compute_len
Mark Wielaard [Sat, 1 May 2021 16:00:49 +0000 (18:00 +0200)]
libdw: Document and handle DW_FORM_indirect in __libdw_form_val_compute_len

Update the documentation in __libdw_form_val_compute_len for handling
DW_FORM_indirect and make sure the indirect form isn't DW_FORM_indirect
itself or DW_FORM_implicit_const.

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agodebuginfod: debuginfod client should cache negative results.
Alice Zhang via Elfutils-devel [Tue, 4 May 2021 20:25:59 +0000 (16:25 -0400)]
debuginfod: debuginfod client should cache negative results.

Add debuginfod_config_cache for reading and writing to cache
configuration files, make use of the function within
debuginfod_clean_cache and debuginfod_query_server.

In debuginfod_query_server, create 000-permission file on failed
queries. Before querying each BUILDID, if corresponding 000 file
detected, compare its stat mtime with parameter from
.cache/cache_miss_s. If mtime is fresher, then return ENOENT and
exit; otherwise unlink the 000 file and proceed to a new query.

tests: add test in run-debuginfod-find.sh

test if the 000 file is created on failed query; if querying the
same failed BUILDID, whether the query should proceed without
going through server; set the cache_miss_s to 0 and query the same
buildid, and this time should go through the server.

Signed-off-by: Alice Zhang <alizhang@redhat.com>
3 years agoPR27571: debuginfod client cache - file permissions
Frank Ch. Eigler [Mon, 26 Apr 2021 16:21:03 +0000 (12:21 -0400)]
PR27571: debuginfod client cache - file permissions

Files in the download cache should be read-only.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3 years agoPR26125: debuginfod client cache - rmdir harder
Frank Ch. Eigler [Mon, 26 Apr 2021 13:58:45 +0000 (09:58 -0400)]
PR26125: debuginfod client cache - rmdir harder

With PR25365, we accidentally lost the ability to rmdir client-cache
directories corresponding to buildids.  Bring this back, with some
attention to a possible race between a client doing cleanup and
another client doing lookups at the same time.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3 years agolibdw: handle DW_FORM_indirect when reading attributes
Omar Sandoval [Fri, 23 Apr 2021 23:36:15 +0000 (16:36 -0700)]
libdw: handle DW_FORM_indirect when reading attributes

Whenever we encounter an attribute with DW_FORM_indirect, we need to
read its true form from the DIE data. Then, we can continue normally.
This adds support to the most obvious places: __libdw_find_attr() and
dwarf_getattrs(). There may be more places that need to be updated.

I encountered this when inspecting a file that was processed by our BOLT
tool: https://github.com/facebookincubator/BOLT. This also adds a couple
of test cases using a file generated by that tool.

Signed-off-by: Omar Sandoval <osandov@fb.com>
3 years agoPR27701: debuginfod client: encourage reused debuginfod_client objects
Frank Ch. Eigler [Fri, 23 Apr 2021 17:04:26 +0000 (13:04 -0400)]
PR27701: debuginfod client: encourage reused debuginfod_client objects

Client objects now carry long-lived curl handles for outgoing
connections.  This makes it more efficient for multiple sequential
queries, because the TCP connections and/or TLS state info are kept
around awhile, avoiding O(100ms) setup latencies.  debuginfod is
adjusted to take advantage of this for federation.  Other clients
should gradually do this too, perhaps including elfutils itself (in
the libdwfl->debuginfod_client hooks).

A large gdb session with 117 debuginfo downloads was observed to run
twice as fast (45s vs. 1m30s wall-clock time), just in nuking this
extra setup latency.  This was tested via a debuginfod intermediary:
it should be even faster once gdb reuses its own debuginfod_client.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3 years agopo: update XGETTEXT_OPTIONS
Dmitry V. Levin [Sun, 21 Mar 2021 08:00:00 +0000 (08:00 +0000)]
po: update XGETTEXT_OPTIONS

Recognize sgettext as a macro which is used for translations.

Flag _, N_, and sgettext with pass-c-format.  The effect of this
specification is that xgettext will propagate format string
requirements for _, N_, and sgettext calls to their first arguments,
and thus mark them as format strings.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agodebuginfod: only update database stats once per groom
Frank Ch. Eigler [Thu, 15 Apr 2021 10:29:01 +0000 (06:29 -0400)]
debuginfod: only update database stats once per groom

On very large servers, each database-stat counting pass can take tens
of minutes (!), and doing it twice per groom pass does not seriously
improve data quality.  Just do it once, after stale data removal &
basic sqlite vacuum.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3 years agodebuginfod: Recognize .debug_*-less symtab-laden files as debuginfo
Frank Ch. Eigler [Thu, 15 Apr 2021 08:49:59 +0000 (04:49 -0400)]
debuginfod: Recognize .debug_*-less symtab-laden files as debuginfo

Borrow logic from elfclassify for is_debug_only() for our own
debuginfo identification.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3 years agonm: Fix file descriptor leak on dwfl_begin failure.
Mark Wielaard [Sat, 3 Apr 2021 17:52:38 +0000 (19:52 +0200)]
nm: Fix file descriptor leak on dwfl_begin failure.

If dwfl_begin fails we won't use the dwfl_fd descriptor we just dupped.
Make sure to close on dwfl_begin failure to avoid the leak.

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agounstrip: Fix small leak in handle_output_dir_module.
Mark Wielaard [Sat, 3 Apr 2021 17:36:12 +0000 (19:36 +0200)]
unstrip: Fix small leak in handle_output_dir_module.

eu-unstrip might leak a string for each module found when using the -d
option. Make sure to free the output_file name when we are done with the
module.

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agoar: Always close newfd in do_oper_insert.
Mark Wielaard [Sat, 3 Apr 2021 17:20:32 +0000 (19:20 +0200)]
ar: Always close newfd in do_oper_insert.

newfd is normally created by mkstemp given the original fd exists.
Otherwise it will created by open from arfname. In the second case
newfd might not get closed. Preventd this by always trying to close
it after errout.

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agodoc/debuginfod.8: fix wrong parameter name for .deb files in description
Frank Ch. Eigler [Mon, 5 Apr 2021 01:57:20 +0000 (21:57 -0400)]
doc/debuginfod.8: fix wrong parameter name for .deb files in description

One place in the description referred to the parameter for
.deb/.ddeb files as "-D" as opposed to the correct "-U".

Signed-off-by: Andreas Ziegler <andreas.ziegler@fau.de>
3 years agodebuginfod: Set child thread names via pthread_setname_np()
Frank Ch. Eigler [Tue, 30 Mar 2021 17:22:43 +0000 (13:22 -0400)]
debuginfod: Set child thread names via pthread_setname_np()

In order to assist problem diagnosis / monitoring, use this
gnu-flavoured pthread function to set purpose names to the various
child threads debuginfod starts.  libmicrohttpd already sets this for
its threads.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3 years agodebuginfod-client: Don't compare a double to a long
Timm Bäder [Sun, 7 Mar 2021 18:02:29 +0000 (13:02 -0500)]
debuginfod-client: Don't compare a double to a long

Clang warns about this:

../../debuginfod/debuginfod-client.c:899:28: error: implicit conversion from 'long' to 'double' changes value from 9223372036854775807 to 9223372036854775808 [-Werror,-Wimplicit-int-float-conversion]
                pa = (dl > LONG_MAX ? LONG_MAX : (long)dl);
                         ~ ^~~~~~~~
/usr/lib64/clang/10.0.1/include/limits.h:47:19: note: expanded from macro 'LONG_MAX'
                  ^~~~~~~~~~~~
<built-in>:38:22: note: expanded from here
                     ^~~~~~~~~~~~~~~~~~~~

Modified for jakub's observation about LONG_MAX overflow.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agoUpdate Polish translation
Piotr Drąg [Sun, 21 Feb 2021 14:33:43 +0000 (15:33 +0100)]
Update Polish translation

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

Signed-off-by: Piotr Drąg <piotrdrag@gmail.com>
3 years agoUpdate POTFILES.in
Piotr Drąg [Sun, 21 Feb 2021 13:54:46 +0000 (14:54 +0100)]
Update POTFILES.in

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

Signed-off-by: Piotr Drąg <piotrdrag@gmail.com>
3 years agobuild: Check for -Wno-packed-not-aligned support
Timm Bäder [Wed, 17 Feb 2021 09:27:08 +0000 (10:27 +0100)]
build: Check for -Wno-packed-not-aligned support

Clang does not support this warning, so check for compiler support
before using it.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agobuild: Check for -Wtrampolines support
Timm Bäder [Wed, 17 Feb 2021 09:27:07 +0000 (10:27 +0100)]
build: Check for -Wtrampolines support

Clang does not support -Wtrampolines, so check if the compiler supports
it before using it.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agodebuginfod-client: Fix typo in curl feature detection
Timm Bäder [Fri, 5 Mar 2021 18:36:15 +0000 (13:36 -0500)]
debuginfod-client: Fix typo in curl feature detection

CURLINFO_CURLINFO_CONTENT_LENGTH_DOWNLOAD_T is one CURLINFO_ too much.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agoreadelf: Sanity check verneed and verdef offsets in handle_symtab.
Mark Wielaard [Wed, 3 Mar 2021 20:40:53 +0000 (21:40 +0100)]
readelf: Sanity check verneed and verdef offsets in handle_symtab.

We are going through vna_next, vn_next and vd_next in a while loop.
Make sure that all offsets are sane. We don't want things to wrap
around so we go in cycles.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agoelfcompress: Replace cleanup() with label
Timm Bäder [Tue, 2 Mar 2021 08:05:33 +0000 (09:05 +0100)]
elfcompress: Replace cleanup() with label

This unifies the error handling with the rest of the code base and gets
rid of a nested function.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agobuild: Check for -Wimplicit-fallthrough=5 separately
Timm Bäder [Wed, 17 Feb 2021 09:27:06 +0000 (10:27 +0100)]
build: Check for -Wimplicit-fallthrough=5 separately

GCC accepts the =5, which means it doesn't try to parse any comments
and only accepts the fallthrough attribute in code. Clang does not ever
parse any comments and always wants the fallthrough attribute anyway.
Clang also doesn't accept the =n parameter for -Wimplicit-fallthrough.

Test for =5 separately and use it if supported and fall back to just
-Wimplicit-fallthrough otherwise.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agotests: Pull new_data_buf() into file scope for elfstrmerge.
Timm Bäder [Wed, 17 Feb 2021 08:46:05 +0000 (09:46 +0100)]
tests: Pull new_data_buf() into file scope for elfstrmerge.

Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agotests: Pull newsecndx() info file scope for elfstrmerge
Timm Bäder [Wed, 17 Feb 2021 08:46:04 +0000 (09:46 +0100)]
tests: Pull newsecndx() info file scope for elfstrmerge

Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agoelfcompress: Pull get_sections() into file scope
Timm Bäder [Wed, 17 Feb 2021 08:45:09 +0000 (09:45 +0100)]
elfcompress: Pull get_sections() into file scope

Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agoelfcompress: Pull get_section() into file scope
Timm Bäder [Wed, 17 Feb 2021 08:45:08 +0000 (09:45 +0100)]
elfcompress: Pull get_section() into file scope

Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agoelfcompress: Pull set_section() into file scope
Timm Bäder [Wed, 17 Feb 2021 08:45:07 +0000 (09:45 +0100)]
elfcompress: Pull set_section() into file scope

Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agounstrip: Remove nested next() function
Timm Bäder [Wed, 17 Feb 2021 08:43:48 +0000 (09:43 +0100)]
unstrip: Remove nested next() function

This is a simple one-liner, so inline this into the few callers.
Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agounstrip: Pull warn() into file scope
Timm Bäder [Wed, 17 Feb 2021 08:43:47 +0000 (09:43 +0100)]
unstrip: Pull warn() into file scope

Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agounstrip: Inline find_unalloc_section() into only caller
Timm Bäder [Wed, 17 Feb 2021 08:43:46 +0000 (09:43 +0100)]
unstrip: Inline find_unalloc_section() into only caller

Get rid of an unnecessary nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agounstrip: Pull check_match() into file scope
Timm Bäder [Wed, 17 Feb 2021 08:43:45 +0000 (09:43 +0100)]
unstrip: Pull check_match() into file scope

Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agounstrip: Pull adjust_reloc() into file scope
Timm Bäder [Wed, 17 Feb 2021 08:43:44 +0000 (09:43 +0100)]
unstrip: Pull adjust_reloc() into file scope

Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agoelflint: Pull left() in file scope
Timm Bäder [Wed, 17 Feb 2021 08:42:19 +0000 (09:42 +0100)]
elflint: Pull left() in file scope

And rename it to buffer_left() to be a bit more descriptive

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agoelflint: Pull pos() info file scope
Timm Bäder [Wed, 17 Feb 2021 08:42:18 +0000 (09:42 +0100)]
elflint: Pull pos() info file scope

Rename it to buffer_pos() to be a bit more descriptive and get rid of a
nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agodebuginfod: filter webapi for bad keywords early
Frank Ch. Eigler [Thu, 25 Feb 2021 19:04:20 +0000 (14:04 -0500)]
debuginfod: filter webapi for bad keywords early

Prevent some unnecessary processing of user data and
keep invalid request types out of metrics.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3 years agotestsuite: run-debuginfod-find.sh: Fix grooming test indeterminacy
Frank Ch. Eigler [Thu, 18 Feb 2021 00:34:09 +0000 (19:34 -0500)]
testsuite: run-debuginfod-find.sh: Fix grooming test indeterminacy

We were looking at a less-than-ideal metric to check the effects
of grooming on the database.  It turns out there is a counter
just for removed files/archives, which will have the same value
regardless of the presence of other test configurations.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3 years agoNEWS: add a debuginfod blurb re. bsdtar
Frank Ch. Eigler [Wed, 17 Feb 2021 20:20:25 +0000 (15:20 -0500)]
NEWS: add a debuginfod blurb re. bsdtar

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3 years agotestsuite: run-debuginfod-find.sh: Be more verbose on failure
Frank Ch. Eigler [Wed, 17 Feb 2021 20:38:43 +0000 (15:38 -0500)]
testsuite: run-debuginfod-find.sh: Be more verbose on failure

To help diagnose timing glitches in debuginfod testing, print more
diagnostics on a metric-timeout failure.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3 years agoreadelf: Type DIE offset is from start of CU.
Mark Wielaard [Fri, 12 Feb 2021 15:42:44 +0000 (16:42 +0100)]
readelf: Type DIE offset is from start of CU.

While inspecting some type units I noticed the type offset seemed off.
We were printing the offset as is, but it should include the offset of
the unit. There was actually a testcase for this, run-readelf-types.sh
but that had the same bug in the expected output. Fixed both.

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agoreadelf, libdw: blocks aren't expressions for DWARF version 4
Mark Wielaard [Fri, 12 Feb 2021 15:28:50 +0000 (16:28 +0100)]
readelf, libdw: blocks aren't expressions for DWARF version 4

For DWARF version 4 or higher a block form really encodes a block,
not an expression location. Also constant offsets can be expressed
as DW_FORM_implicit_const in DWARF version 5.

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agoPR27413: use bsdtar to unpack deb-related formats
Frank Ch. Eigler [Sun, 14 Feb 2021 21:02:05 +0000 (16:02 -0500)]
PR27413: use bsdtar to unpack deb-related formats

dpkg-deb has been reported to be fragile when running under
debuginfod, whereas bsdtar (libarchive) is happy with all these
flavors of files.  Switch to a bsdtar based pipeline, now
equipped with an escaped glob pattern that adapts to a variety
of interior data.tar* compression formats.

No testsuite impact.  .ipk format tested with some random openwrt and
kino-extension binaries found on the net.  Some of these are built
with out buildid, and hardly any with debuginfo, but whatever, bsdtar
and elfutils extract whatever info is there.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
Signed-off-by: Dorinda Bassey <dorindabassey@gmail.com>
3 years agotests: Quote make variables in TESTS_ENVIRONMENT
Alexander Miller via Elfutils-devel [Sun, 7 Feb 2021 15:48:17 +0000 (16:48 +0100)]
tests: Quote make variables in TESTS_ENVIRONMENT

Commit eb922a1b8f3a ("tests: use ${CC} instead of 'gcc' in tests")
exports ${CC} into the test environment, but doesn't quote the
value for the assignment. That doesn't work properly if the value
contains whitespace. In a multilib/biarch environment however, it's
common to set CC="gcc -m32" or similar. That causes tests to print
error messages: "/bin/sh: line 2: -m32: command not found".

Fix that by adding quotes around all make variables (not just $CC)
used in setting up TESTS_ENVIRONMENT.

Signed-off-by: Alexander Miller <alex.miller@gmx.de>
3 years agoelfutils.spec.in: Escape %%check in comment.
Mark Wielaard [Fri, 12 Feb 2021 15:36:04 +0000 (16:36 +0100)]
elfutils.spec.in: Escape %%check in comment.

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agotests/run-debuginfod-find.sh: skip test if cpio isn't available.
Érico Rolim [Tue, 9 Feb 2021 00:56:50 +0000 (19:56 -0500)]
tests/run-debuginfod-find.sh: skip test if cpio isn't available.

Signed-off-by: Érico Rolim <erico.erc@gmail.com>
3 years agoNEWS: add one more debuginfod brag elfutils-0.183
Frank Ch. Eigler [Sat, 6 Feb 2021 01:18:39 +0000 (20:18 -0500)]
NEWS: add one more debuginfod brag

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3 years agoPrepare for 0.183
Mark Wielaard [Fri, 5 Feb 2021 21:55:10 +0000 (22:55 +0100)]
Prepare for 0.183

Set version to 0.183
Update NEWS and elfutils.spec.in.
Set copyright year in configure.ac and printversion.
Regenerate po/*.po files.

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agobackends/ppc_initreg.c: include <asm/ptrace.h>.
Érico Rolim [Fri, 5 Feb 2021 17:52:06 +0000 (14:52 -0300)]
backends/ppc_initreg.c: include <asm/ptrace.h>.

Necessary on musl for struct pt_regs definition, doesn't affect the
build on glibc, since <sys/user.h> includes the same header.

Signed-off-by: Érico Rolim <erico.erc@gmail.com>
3 years agoar: Pull should_truncate_fname() into file scope
Timm Bäder [Wed, 3 Feb 2021 14:44:46 +0000 (15:44 +0100)]
ar: Pull should_truncate_fname() into file scope

Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agoPR27092: debuginfod low-memory handling
Frank Ch. Eigler [Fri, 5 Feb 2021 01:31:56 +0000 (20:31 -0500)]
PR27092: debuginfod low-memory handling

A couple of closely related pieces of work allow more early warning
about low storage/memory conditions:

- New prometheus metrics to track filesystem freespace, and more
  details about some errors.
- Frequent checking of $TMPDIR freespace, to trigger fdcache
  emergency flushes.
- Switch to floating point prometheus metrics, to communicate
  fractions - and short time intervals - accurately.
- Fix startup-time pthread-creation error handling.

Testing is smoke-test-level only as it is hard to create
free-space-limited $TMPDIRs. Locally tested against tiny through
medium tmpfs filesystems, with or without sqlite db also there.  Shows
a pleasant stream of diagnostics and metrics during shortage but
generally does not fail outright.  However, catching an actual
libstdc++- or kernel-level OOM is beyond our ken.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3 years agoPR27323 debuginfod: improve query concurrency with grooming
Frank Ch. Eigler [Tue, 2 Feb 2021 21:49:19 +0000 (16:49 -0500)]
PR27323 debuginfod: improve query concurrency with grooming

Start using a second sqlite3 database connection for webapi query
servicing.  This allows much better concurrency when long-running
grooming operations are in progress.

No testsuite impact.  Grooming times are too short to try to hit with
concurrent requests.  OTOH the existing tests did show some
interesting regressions that needed fixing, like needing not to
dual-wield db and dbq when doing rpm-dwz-related lookups from during
scanning, and the way in which corrupted databases are reported.
These needed some automated invocations of gdb on the running
debuginfod binaries that just failed their testing, for in-situ
debugging.

Hand-tested for function on a huge 20GB index file.  Allowed webapi
queries to be run throughout random points of the grooming process,
including especially the long count(*) report loops before & after.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3 years agoreadelf: Remove show_op_index variable
Timm Bäder [Tue, 2 Feb 2021 10:23:24 +0000 (11:23 +0100)]
readelf: Remove show_op_index variable

advance_pc() uses show_op_index to save whether the current op_index is
> 0 OR the new op_index is > 0.

The new op index is calculated via

new_op_index = (op_index + op_advance) % max_ops_per_instr;

since all of the variables involved are unsigned,
new_op_index >= op_index is always true.

So...

if op_index > 0, then new_op_index > 0
if op_index == 0, then new_op_index >= 0

and if the new_op_index is > 0, then the old one was as well.

In any case, we only need to check the new_op_index, since show_op_index
used to OR the two comparisons.

In other words:

 op_index > 0  |  new_op_index > 0  || show_op_index
 ------------------------------------------------
      true           true                true
     false           true                true
      true          false                true     xx
     false          false                false

... but since the third line (marked with xx) is not possible,
the table becomes:

 op_index > 0  |  new_op_index > 0  || show_op_index
 ------------------------------------------------
      true           true                true
     false           true                true
     false          false                false

... and show_op_index is equal to (new_op_index > 0).
So, remove the show_op_index variable and simply replace it by comparing
the new op_index > 0.

3 years agolibdwfl: use GNU strerror_r only when available.
Érico Rolim [Tue, 2 Feb 2021 00:16:56 +0000 (21:16 -0300)]
libdwfl: use GNU strerror_r only when available.

Some C libraries don't provide the GNU version of strerror_r, only the
XSI-compliant one. We use the GNU version when available, since it fits
the code better, and otherwise use the XSI-compliant one.

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

Signed-off-by: Érico Rolim <erico.erc@gmail.com>
3 years agotests: use ${CC} instead of 'gcc' in tests
Sergei Trofimovich via Elfutils-devel [Sun, 31 Jan 2021 15:49:13 +0000 (15:49 +0000)]
tests: use ${CC} instead of 'gcc' in tests

To better support cross-compilation Gentoo provides a way
to configure system without 'gcc' binary and only provide
tool-prefixed tools, like 'x86_64-pc-linux-gnu-gcc'.
The packages are built as ./configure --host=x86_64-pc-linux-gnu.

In https://bugs.gentoo.org/718872 Agostino Sarubbo found
a few test failures that use hardcoded 'gcc' instead of
expected ${CC}. The change propagates detected ${CC} at
configure time to test scripts.

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
3 years agoreadelf: Pull regname() into file scope
Timm Bäder [Fri, 8 Jan 2021 08:16:32 +0000 (09:16 +0100)]
readelf: Pull regname() into file scope

Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agoreadelf: Pull left() info file scope
Timm Bäder [Fri, 8 Jan 2021 08:16:31 +0000 (09:16 +0100)]
readelf: Pull left() info file scope

Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agoreadelf: Pull same_set() info file scope
Timm Bäder [Fri, 8 Jan 2021 08:16:30 +0000 (09:16 +0100)]
readelf: Pull same_set() info file scope

Get rid of a nested function this way

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agoreadelf: Pull add_dump_section() into file scope
Timm Bäder [Fri, 8 Jan 2021 08:16:29 +0000 (09:16 +0100)]
readelf: Pull add_dump_section() into file scope

Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agoarlib-argp: Pull text_for_default() into file scope
Timm Bäder [Fri, 8 Jan 2021 08:13:28 +0000 (09:13 +0100)]
arlib-argp: Pull text_for_default() into file scope

Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agozstrptr: Pull print_string() into file scope
Timm Bäder [Fri, 8 Jan 2021 08:13:26 +0000 (09:13 +0100)]
zstrptr: Pull print_string() into file scope

Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agoaddr2line: Pull show_note() and show_int() in file scope
Timm Bäder [Fri, 8 Jan 2021 08:13:25 +0000 (09:13 +0100)]
addr2line: Pull show_note() and show_int() in file scope

Get rid of the nested functions

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agoelf-from-memory: Refactor to get rid of nested function
Timm Bäder [Fri, 8 Jan 2021 08:09:56 +0000 (09:09 +0100)]
elf-from-memory: Refactor to get rid of nested function

Try to unify the 32/64 bit code paths and get rid of the nested
handle_segment() this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agoelf-from-memory: Restructure code to get rid of nested handle_segment()
Timm Bäder [Fri, 8 Jan 2021 08:09:55 +0000 (09:09 +0100)]
elf-from-memory: Restructure code to get rid of nested handle_segment()

Use one loop for both 32 and 64  bit case. This allows for only one call
site of the old handle_segment(), which we can then inline into the for
loop.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agostrip: Remove no_symtab_updates() function
Timm Bäder [Fri, 8 Jan 2021 08:04:49 +0000 (09:04 +0100)]
strip: Remove no_symtab_updates() function

The no_symtab_updates() function was being called at the beginning of
all case labels in this switch, so we can just call it once before the
switch. Then it only has one call-site, so inline this short function
there.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agostrip: Pull update_section_size() into file scope
Timm Bäder [Fri, 8 Jan 2021 08:04:48 +0000 (09:04 +0100)]
strip: Pull update_section_size() into file scope

Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agostrip: Pull relocate() info file scope
Timm Bäder [Fri, 8 Jan 2021 08:04:47 +0000 (09:04 +0100)]
strip: Pull relocate() info file scope

Pull relocate() info file scope and get rid of a nested function this
way. Refactor remove_debug_relocations() to minimize the parameters we
need to pass to relocate().

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agostrip: Replace nested check_preserved function with loop
Timm Bäder [Fri, 8 Jan 2021 08:04:46 +0000 (09:04 +0100)]
strip: Replace nested check_preserved function with loop

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agoelflint: Recognize SHF_GNU_RETAIN as extra section flag.
Mark Wielaard [Tue, 12 Jan 2021 10:35:10 +0000 (11:35 +0100)]
elflint: Recognize SHF_GNU_RETAIN as extra section flag.

SHF_GNU_RETAIN is like SHF_LINK_ORDER it can appear on any section
and should be ignored by elflint. Add all such flags to a new
EXTRA_SHFLAGS and use it consistently in check_sections.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agoAdd coverage target
Dmitry V. Levin [Tue, 12 Jan 2021 08:00:00 +0000 (08:00 +0000)]
Add coverage target

Implement a target for capturing code coverage using lcov.
It is available when elfutils is configured using --enable-gcov.

Tested with
autoreconf -if && ./configure --enable-maintainer-mode --enable-gcov &&
make && make check && make coverage

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agosrc/elflint.c: add debug print for GNU_RETAIN and others
Sergei Trofimovich [Thu, 31 Dec 2020 12:11:34 +0000 (12:11 +0000)]
src/elflint.c: add debug print for GNU_RETAIN and others

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agosrc/elflint.c: fix printing of unknown flags
Sergei Trofimovich [Thu, 31 Dec 2020 12:11:42 +0000 (12:11 +0000)]
src/elflint.c: fix printing of unknown flags

before the change section_flags_string() ignored unknown section
flags: snprintf() did write numeric value into buffer, but
"*cp = '\0'" negated the effect.

The change advances the 'cp' pointer'.

While at it add a '|' separator between known and unknown flags.

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
3 years agosrc/readelf: use qsort instead of qsort_r.
Érico Rolim [Wed, 16 Dec 2020 22:30:12 +0000 (19:30 -0300)]
src/readelf: use qsort instead of qsort_r.

This program is single threaded, so using qsort with a global variable
isn't a danger. The interface for qsort_r isn't standardized (and
diverges between glibc and FreeBSD, for example), which makes usage of
qsort, where possible, preferrable.

Signed-off-by: Érico Rolim <erico.erc@gmail.com>
3 years agoSplit the top level .gitignore file
Dmitry V. Levin [Sun, 20 Dec 2020 08:00:00 +0000 (08:00 +0000)]
Split the top level .gitignore file

Move subdirectory parts of the top level .gitignore into appropriate
subdirectories.  This would be consistent with ChangeLog files,
currently one has to update the top level ChangeLog file when
the top level .gitignore file is changed in a way that affects
a specific subdirectory only.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years ago.gitignore: update
Dmitry V. Levin [Sun, 20 Dec 2020 08:00:00 +0000 (08:00 +0000)]
.gitignore: update

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agolibcpu: linking i386_gendis requires obstack.
Érico Rolim [Wed, 16 Dec 2020 18:56:14 +0000 (15:56 -0300)]
libcpu: linking i386_gendis requires obstack.

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agoHandle SHF_GNU_RETAIN in eu-readelf and eu-elflint.
Mark Wielaard [Sat, 12 Dec 2020 22:36:15 +0000 (23:36 +0100)]
Handle SHF_GNU_RETAIN in eu-readelf and eu-elflint.

readelf -S now shows 'R' when SHF_GNU_RETAIN is set.
elflint accepts SHF_GNU_RETAIN when set on section in --gnu mode.

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agolibelf: Sync elf.h from glibc.
Mark Wielaard [Sat, 12 Dec 2020 19:48:40 +0000 (20:48 +0100)]
libelf: Sync elf.h from glibc.

Adds SHF_GNU_RETAIN.

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agoModernize gettext infrastructure
Dmitry V. Levin [Tue, 15 Dec 2020 08:00:00 +0000 (08:00 +0000)]
Modernize gettext infrastructure

Switch to use AM_GNU_GETTEXT, AM_GNU_GETTEXT_VERSION, and
AM_GNU_GETTEXT_REQUIRE_VERSION, this allows to stop bundling gettext
infrastructure files and let autoreconf invoke autopoint which will set
the gettext infrastructure up.

Use this opportunity to create separate .gitignore files for m4/ and po/
directories.

Tested with
autoreconf -if && ./configure --enable-maintainer-mode && make && make distcheck

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agosrc: consistently use _(Str) instead of gettext(Str)
Dmitry V. Levin [Wed, 16 Dec 2020 08:00:00 +0000 (08:00 +0000)]
src: consistently use _(Str) instead of gettext(Str)

Make use of the _(Str) macro provided by <config.h>.

The change was made automatically using the following command:
$ git grep -l '\<gettext *(' src |xargs sed -i 's/\<gettext *(/_(/g'

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>