platform/upstream/elfutils.git
2 years agotests: Add -rdynamic to dwfl_proc_attach_LDFLAGS
Mark Wielaard [Thu, 18 Nov 2021 20:34:57 +0000 (21:34 +0100)]
tests: Add -rdynamic to dwfl_proc_attach_LDFLAGS

dwfl-proc-attach uses (overrides) dlopen (so it does nothing).  This
seems to cause a versioned dlopen symbol to be pulled in when building
with LTO. Resulting in a link failure (when dlopen isn't integrated
into libc):

/usr/bin/ld: dwfl-proc-attach.o (symbol from plugin): undefined
reference to symbol 'dlopen@@GLIBC_2.2.5'
/usr/bin/ld: /usr/lib64/libdl.so.2: error adding symbols: DSO missing
from command line collect2: error: ld returned 1 exit status

Add -rdynamic to the LDFLAGS to add all symbols to the dynamic symbol
table for dwfl-proc-attach.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agodwfl: fix potential overflow when reporting on kernel modules
Matthias Maennich [Thu, 18 Nov 2021 19:44:50 +0000 (19:44 +0000)]
dwfl: fix potential overflow when reporting on kernel modules

dwfl_linux_kernel_report_modules_ has an outstanding ancient bug when
reading kernel module information from a modules list file. The target
buffer for the module name was sized too small to hold potential values.
Fix that by increasing the value to account for the null termination.

In practice, this unlikely ever happened, but it now got diagnosed by
LLVM as part of a stricter -Wfortify-source implementation [1]:

libdwfl/linux-kernel-modules.c:1019:7: error: 'sscanf' may overflow; destination buffer in argument 3 has size 128, but the corresponding specifier may require size 129 [-Werror,-Wfortify-source]
                    modname, &modsz, &modaddr) == 3)

[1] https://github.com/llvm/llvm-project/commit/2db66f8d48beeea835cb9a6940e25bc04ab5d941

Suggested-by: Paul Pluzhnikov <ppluzhnikov@google.com>
Signed-off-by: Matthias Maennich <maennich@google.com>
2 years agotests: Don't set DEBUGINFOD_TIMEOUT
Mark Wielaard [Thu, 11 Nov 2021 14:46:26 +0000 (15:46 +0100)]
tests: Don't set DEBUGINFOD_TIMEOUT

Various tests set DEBUGINFOD_TIMEOUT to 10. Which is less than the default
of 90. None of the tests relied on a lower timeout. So just don't set it.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agodebuginfod: fix compilation on platforms without <error.h>
Érico Nogueira [Thu, 11 Nov 2021 00:17:48 +0000 (21:17 -0300)]
debuginfod: fix compilation on platforms without <error.h>

"system.h" only declares the error() function, so it needs to be in an
'extern "C"' block, otherwise linking fails.

Since we are here, use quotes for "system.h" header, since it's a local
header, not a system one.

Signed-off-by: Érico Nogueira <erico.erc@gmail.com>
2 years agoPrepare for 0.186 elfutils-0.186
Mark Wielaard [Wed, 10 Nov 2021 15:26:07 +0000 (16:26 +0100)]
Prepare for 0.186

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoPR28430: debuginfod: support --passive mode
Frank Ch. Eigler [Sat, 6 Nov 2021 02:26:35 +0000 (22:26 -0400)]
PR28430: debuginfod: support --passive mode

Add support for a limited mode for debuginfod that uses a pure
read-only sqlite index.  This mode is useful for load spreading based
on naively shared or replicated databases.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2 years agolibdw, readelf: Read inlining info in NVIDIA extended line map
John M Mellor-Crummey [Wed, 20 Oct 2021 23:19:38 +0000 (18:19 -0500)]
libdw, readelf: Read inlining info in NVIDIA extended line map

As of CUDA 11.2, NVIDIA added extensions to the line map section
of CUDA binaries to represent inlined functions. These extensions
include

 - two new fields in a line table row to represent inline
   information: context, and functionname,

 - two new DWARF extended opcodes: DW_LNE_NVIDIA_inlined_call,
   DW_LNE_NVIDIA_set_function_name,

 - an additional word in the line table header that indicates
   the offset in the .debug_str function where the function
   names for this line table begin, and

A line table row for an inlined function contains a non-zero "context"
value. The “context” field indicates the index of the line table row
that serves as the call site for an inlined context.

The "functionname" field in a line table row is only meaningful if the
"context" field of the row is non-zero. A meaningful "functionname"
field contains an index into the .debug_str section relative to the
base offset established in the line table header; the position in the
.debug_str section indicates the name of the inlined function.

These extensions resemble the proposed DWARF extensions
(http://dwarfstd.org/ShowIssue.php?issue=140906.1) by Cary Coutant,
but are not identical.

This commit integrates support for handling NVIDIA's extended line
maps into elfutil's libdw library, by adding two functions
dwarf_linecontext and dwarf_linefunctionname, and the readelf
--debug-dump=line command line utility.

Signed-off-by: John M Mellor-Crummey <johnmc@rice.edu>
Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibdw: dwarf_elf_begin should use either plain, dwo or lto DWARF sections.
Mark Wielaard [Mon, 8 Nov 2021 08:27:51 +0000 (09:27 +0100)]
libdw: dwarf_elf_begin should use either plain, dwo or lto DWARF sections.

When opening an ELF file that contained a mix of plain, dwo or lto .debug
sections the result could be confusing. Add a check to pick just the plain
.debug sections, or the .dwo sections or the .gnu.debuglto_.debug sections
(in that order of preference). That way there is always a consistent set.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoImprove building with LTO
Alexander Miller [Thu, 18 Feb 2021 02:38:56 +0000 (03:38 +0100)]
Improve building with LTO

Use symver attribute for symbol versioning instead of .symver
assembler directive when available. Convert to use double @ syntax
for default version in all cases (required when using the attribute).

Add the attributes externally_visible, no_reorder if available when
using assembler directives to improve the situation for < gcc-10.
This is not 100% reliable, though; -flto-partition=none may still be
needed in some cases.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=24498
Signed-off-by: Alexander Miller <alex.miller@gmx.de>
2 years agoPR28514: debuginfod: limit groom operation times
Frank Ch. Eigler [Thu, 4 Nov 2021 17:08:35 +0000 (13:08 -0400)]
PR28514: debuginfod: limit groom operation times

For large databases and many stale files, it was possible to starve
rescan operations by numerous groom "nuke" (database delete ops).
Under the theory that including new data is at least as important as
aging old, we now impose a rough deadline on groom queries.

In the process, we discovered that we were commiting some
undefined-behaviour sqlite ops (deleting rows while iterating), which
may explain some previous heisenbug occurrences.  So the groom nuke
operations are split into decision & action phases, with associated
progress-tracking metrics.

Testing the timeout facility requires hand-testing beyond the
testsuite (since it requires LARGE databases to show measurable query
times).  So confirmed this part by hand.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2 years agoNEWS: make automake check-news / dist happy
Frank Ch. Eigler [Thu, 4 Nov 2021 20:26:55 +0000 (16:26 -0400)]
NEWS: make automake check-news / dist happy

automake's check-news option requires not too much new content
before a line that includes the current version number.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2 years agoNEWS: list some 0.186 debuginfod client & server features
Frank Ch. Eigler [Thu, 4 Nov 2021 19:26:33 +0000 (15:26 -0400)]
NEWS: list some 0.186 debuginfod client & server features

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2 years agoPR28240: debuginfod client root-safe negative caching
Frank Ch. Eigler [Wed, 18 Aug 2021 22:29:34 +0000 (18:29 -0400)]
PR28240: debuginfod client root-safe negative caching

Negative cache (000-permission) files were incorrectly treated as
valid cached files for the root user, because root can open even
000-perm files without -EACCES.  Corrected this checking sequence.

Fixed the debuginfod testsuite to run to completion as root or
as an ordinary user, correcting corresponding permission checks:
    stat -c %A $FILE
is right and
    [ -w $FILE]  [ -r $FILE ]
were wrong.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2 years agolibdw: Don't pass NULL to dwarf_peel_type
Mark Wielaard [Mon, 18 Oct 2021 12:35:20 +0000 (14:35 +0200)]
libdw: Don't pass NULL to dwarf_peel_type

commit c3a6a9dfc "libdw: Use signedness of subrange type to
determine array bounds" introduced a type check on a DIE which
exposed a latent bug in the get_type function. Even if the type
of a DIE couldn't be determined it would call dwarf_peel_type
on it. The gcc undefined sanitizer would flag this as being
undefined behaviour because the second argument of the function
is marked as non-NULL. Fix this by checking we actually have
a non-NULL type DIE.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibdw: Use signedness of subrange type to determine array bounds
Mark Wielaard [Wed, 6 Oct 2021 20:41:29 +0000 (22:41 +0200)]
libdw: Use signedness of subrange type to determine array bounds

When calculating the array size check if the subrange has an associate
type, if it does then check the type to determine whether the upper
and lower values need to be interpreted as signed of unsigned
values. We default to signed because that is what the testcase
run-aggregate-size.sh testfile-size4 expects (this is an hardwritten
testcase, we could have chosen a different default).

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agodebuginfod-client: Stick to http:// + https:// + file:// protocols
Mark Wielaard [Fri, 15 Oct 2021 13:16:54 +0000 (15:16 +0200)]
debuginfod-client: Stick to  + https:// + file:// protocols

Make sure we don't use any of the more experimental protocols
libcurl might support. URLs can be redirected and we might want
to follow http -> https, but not e.g. gopher or pop3.

Suggested-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoPR27783: switch default debuginfod-urls to drop-in style files
Frank Ch. Eigler [Sun, 3 Oct 2021 21:04:24 +0000 (17:04 -0400)]
PR27783: switch default debuginfod-urls to drop-in style files

Rewrote and commented the /etc/profile.d csh and sh script fragments
to take the default $DEBUGINFOD_URLS from the union of drop-in files:
/etc/debuginfod/*.urls.  Hand-tested with csh and bash, with
conditions including no prior $DEBUGINFOD_URLS, nonexistent .urls
files, multiple entries in .urls files.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2 years agotests: Handle dwarf_attr_string returning NULL in show-die-info.c
Mark Wielaard [Wed, 6 Oct 2021 21:53:34 +0000 (23:53 +0200)]
tests: Handle dwarf_attr_string returning NULL in show-die-info.c

Reported-by: Jan-Benedict Glaw <jbglaw@lug-owl.de>
Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoelflint.c: Don't dereference databits if bad
Mark Wielaard [Wed, 6 Oct 2021 21:37:42 +0000 (23:37 +0200)]
elflint.c: Don't dereference databits if bad

elflint.c: In function 'check_sections':
elflint.c:4105:48: error: null pointer dereference [-Werror=null-dereference]
4105 |                                  idx < databits->d_size && ! bad;
     |                                        ~~~~~~~~^~~~~~~~

Fix this by testing for ! bad first.

Reported-by: Jan-Benedict Glaw <jbglaw@lug-owl.de>
Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoPR28242: debuginfod prometheus metric widening
Di Chen [Wed, 6 Oct 2021 21:04:08 +0000 (17:04 -0400)]
PR28242: debuginfod prometheus metric widening

This patch aims to extend http_responses_* metrics with another label
"type" by getting the extra artifact-type content added as a new
key=value tag.

v2, tweaked patch to perform artifact-type sanitization at point of
vulnerability rather than in general metric tabulation logic.

Signed-off-by: Di Chen <dichen@redhat.com>
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2 years agoRISC-V: PR27925 Add support for LP64 and LP64F ABIs return values
William Cohen [Wed, 29 Sep 2021 18:56:15 +0000 (14:56 -0400)]
RISC-V: PR27925 Add support for LP64 and LP64F ABIs return values

The RISC-V Linux kernel is compiled without floating point (the LP64
ABI) and elfutils could not obtain return value locations for
functions in the kernel.  This issue was noticed when Systemtap
generated RISC-V kernel modules for scripts that used $return target
variables in function return probes. This patch adds the needed
support to provide return value information for the LP64 and LP64F
ABIs.

Signed-off-by: William Cohen <wcohen@redhat.com>
2 years agodebuginfod: Remove checking for unsafe headers
Noah Sanci [Fri, 17 Sep 2021 14:45:39 +0000 (10:45 -0400)]
debuginfod: Remove checking for unsafe headers

Some http response header checks were removed such as checking for
Connection and Cache-Control. These headers are not guarenteed to be
received and depend on proxy and libmicrohttpd versions. Checking for
the existance of Content-Length and DEBUGINFOD-* headers is sufficient
since Content-Length is added upon creation of an MHD_Response object
and DEBUGINFOD-* are added manually.
(source on Content-Length being added:
https://www.gnu.org/software/libmicrohttpd/manual/libmicrohttpd.html#
    microhttpd_002dresponse-headers )

Signed-off-by: Noah Sanci <nsanci@redhat.com>
2 years agodebuginfod: Query debuginfod servers before printing response
Noah Sanci [Fri, 17 Sep 2021 14:45:39 +0000 (10:45 -0400)]
debuginfod: Query debuginfod servers before printing response

While checking PR27277 on some buildbots, greping would fail in
run-debuginfod-response-headers.sh. This was because querying the
debuginfod server occurs after checking if the responseh headers had
arrived, leaving the possibility to leave the querying loop before
outputting the headers which caused the grep failure. Querying now
occurs before checking if response headers have arrived, so that they
will certainly be printed and grep will find them.

Signed-off-by: Noah Sanci <nsanci@redhat.com>
2 years agodebuginfod: PR27277 - Describe retrieved files when verbose
Noah Sanci [Tue, 10 Aug 2021 15:21:35 +0000 (11:21 -0400)]
debuginfod: PR27277 - Describe retrieved files when verbose

Allow users, with enough verbosity, to print the HTTP response headers
upon retrieving a file. These files may include several custome http
response headers such as X-DEBUGINFOD-FILE, X-DEBUGINFOD-SIZE, and
X-DEBUGINFOD-ARCHIVE. These headers are added from the daemon, in
debuginfod.cxx.

E.g output:

HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Length: 4095072
Cache-Control: public
Last-Modified: Thu, 09 Sep 2021 19:06:40 GMT
X-FILE: debuginfod
X-FILE-SIZE: 4095072
Content-Type: application/octet-stream
Date: Fri, 10 Sep 2021 16:38:06 GMT

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

Signed-off-by: Noah Sanci <nsanci@redhat.com>
2 years agodebuginfod: PR28034 - No longer escape '/', and loop efficiency
Noah Sanci [Thu, 9 Sep 2021 17:10:33 +0000 (13:10 -0400)]
debuginfod: PR28034 - No longer escape '/', and loop efficiency

Previously, urls containing '/', so most urls, would escape '/' to %2F,
which is undesirable for use in other libraries which may escape
differently. This patch escapes the '/' and replaces all of them
ensuring there are no %2Fs sent.
Some inefficiencies within the code were fixed, such as changing constant
operations of a while loop within a for loop to a while loop outside of
a for loop. Also strlen is no longer used within the loop, simplifying
the interior operations to mere arithmetic.

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

Signed-off-by: Noah Sanci <nsanci@redhat.com>
2 years agoPR28339: debuginfod: fix groom/scan race condition on just-emptied queue
Frank Ch. Eigler [Tue, 14 Sep 2021 12:15:23 +0000 (08:15 -0400)]
PR28339: debuginfod: fix groom/scan race condition on just-emptied queue

debuginfod's scan and groom operations (thread_main_scanner,
thread_main_fts_source_paths) are intended to be mutually exclusive,
as a substitute for more complicated sql transaction batching.  (This
is because scanning / grooming involves inserting or deleting data
from multiple related tables.)

The workq class that governs this in debuginfod.cxx has a problem: if
the workq just becomes empty, its sole entry pulled by a scanner
thread in response to a wait_front(), an 'idler' groomer thread is
ALSO permitted to run, because there is no indication as to when the
scanner thread operation finishes, only when it starts.

Extending the workq with a counter ("fronters") to track any active
scanning activity (even if the workq is empty) lets us block idlers
groomers a little longer.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2 years agodebuginfod: Add endl after "fdcache emergency flush for filling tmpdir" log
Mark Wielaard [Sun, 12 Sep 2021 22:35:55 +0000 (00:35 +0200)]
debuginfod: Add endl after "fdcache emergency flush for filling tmpdir" log

Without the endl the next log message will not start on its own line.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolib: Make error.c more like error(3)
Colin Cross [Fri, 10 Sep 2021 18:07:16 +0000 (11:07 -0700)]
lib: Make error.c more like error(3)

Fix some issues with the error reimplementation to make it match
the specification for error(3).

Flush stdout before printing to stderr.  Also flush stderr afterwards,
which is not specified in the man page for error(3), but is what
bionic does.

error(3) prints strerror(errnum) if and only if errnum is nonzero,
but verr prints strerror(errno) unconditionaly.  When errnum is nonzero
copy it to errno and use verr, and when it is not set use verrx that
doesn't print errno.

error(3) only exits if status is nonzero, but verr exits uncondtionally.
Use vwarn/vwarnx when status is zero, which don't exit.

Signed-off-by: Colin Cross <ccross@google.com>
2 years agolibdw: set address size, offset size and version on fake CUs
Mark Wielaard [Thu, 26 Aug 2021 17:05:45 +0000 (19:05 +0200)]
libdw: set address size, offset size and version on fake CUs

There are three "fake CUs" that are associated with .debug_loc,
.debug_loclist and .debug_addr.  These fake CUs are used for "fake
attributes" to provide values that are stored in these sections
instead of in the .debug_info section. These fake CUs didn't have the
address size, offset size and DWARF version set. This meant that
values that depended on those properties might not be interpreted
correctly. One example was the value associated with a DW_OP_addrx
(which comes from the .debug_addr section).

Add a testcase using varlocs to test that addresses can correctly be
retrieved for gcc/clang, DWARF4/5 and 32/64 bits objects.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agotests: Don't fail run-debuginfod-fd-prefetch-caches.sh if grep -c fails
Mark Wielaard [Thu, 9 Sep 2021 19:51:51 +0000 (21:51 +0200)]
tests: Don't fail run-debuginfod-fd-prefetch-caches.sh if grep -c fails

The set -o errtrace made run-debuginfod-fd-prefetch-caches.sh
fail. On some systems. Add set -o functrace to make it fail consistently.

The failure is because the grep -c for in the log file fails (it
returns zero). Fix this by using || true. But this is only a
workaround. It makes the test pass, but only because all values are
always zero. The test doesn't currently test anything.

Also make sure that err and cleanup are only executed once.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agofindtextrel: do not use unbound alloca
Dmitry V. Levin [Thu, 9 Sep 2021 08:03:00 +0000 (08:03 +0000)]
findtextrel: do not use unbound alloca

This fixes the following compilation warning:

findtextrel.c:184:1: warning: stack usage might be unbounded [-Wstack-usage=]

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2 years agotests: Cleanup error handling and don't share cache between servers/client
Mark Wielaard [Thu, 9 Sep 2021 16:50:54 +0000 (18:50 +0200)]
tests: Cleanup error handling and don't share cache between servers/client

There were still three tests that shared a cache between the servers
and client that queried those servers. Give them all separate caches.

Also the error handler for debuginfod tests wasn't called when a
command inside a function failed. Since testrun is a function, there
would be no metrics or error log files listed if the testrun command
failed. Making it hard to see what went wrong. Fix this by using
set -o errtrace

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoUse xasprintf instead of asprintf followed by error(EXIT_FAILURE)
Dmitry V. Levin [Mon, 6 Sep 2021 10:00:00 +0000 (10:00 +0000)]
Use xasprintf instead of asprintf followed by error(EXIT_FAILURE)

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2 years agoIntroduce xasprintf
Dmitry V. Levin [Mon, 6 Sep 2021 10:00:00 +0000 (10:00 +0000)]
Introduce xasprintf

Similar to other x* functions, xasprintf is like asprintf except that
it dies in case of an error.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2 years agoRemove redundant casts of memory allocating functions returning void *
Dmitry V. Levin [Mon, 6 Sep 2021 08:00:00 +0000 (08:00 +0000)]
Remove redundant casts of memory allocating functions returning void *

Return values of functions returning "void *", e.g. calloc, malloc,
realloc, xcalloc, xmalloc, and xrealloc, do not need explicit casts.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2 years agosrc: add -Wno-error=stack-usage= to AM_LDFLAGS
Dmitry V. Levin [Sun, 5 Sep 2021 08:00:00 +0000 (08:00 +0000)]
src: add -Wno-error=stack-usage= to AM_LDFLAGS

While -Wstack-usage= is already excluded from AM_CFLAGS for various
tools in src using *_no_Wstack_usage variables, this obviously does not
help when LTO is enabled, so add -Wno-error=stack-usage= to AM_LDFLAGS
for linking tools in src.

References: https://sourceware.org/bugzilla/show_bug.cgi?id=24498
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
2 years agotests: Make sure to wait for initial scan and groom cycle earlier
Mark Wielaard [Tue, 7 Sep 2021 21:56:42 +0000 (23:56 +0200)]
tests: Make sure to wait for initial scan and groom cycle earlier

At startup the debuginfod server does a scan and groom cycle. Make
sure to wait for that before making any changes to the scan dirs.  And
not just right before triggering a new one with SIGUSR1 for scan or
SIGURS2 for groom.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agotests: Make sure to wait for initial scan and groom cycle
Mark Wielaard [Mon, 6 Sep 2021 23:50:51 +0000 (01:50 +0200)]
tests: Make sure to wait for initial scan and groom cycle

At startup the debuginfod server does a scan and groom cycle. Make
sure to wait for that before triggering a new one with SIGUSR1 or
SIGURST2.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agotests: Only export DEBUGINFOD_URLS when necessary
Mark Wielaard [Mon, 6 Sep 2021 22:31:00 +0000 (00:31 +0200)]
tests: Only export DEBUGINFOD_URLS when necessary

A couple of test set DEBUGINFOD_URLS before starting a debuginfd
server causing the server to query itself or a nonexisting debuginfod
server as delegate. In most cases it should be set after, except for
the testcase that explicitly checks for errors when using an invalid
URL.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agotests: Print metrics for both ports on error and fix port selection
Mark Wielaard [Mon, 6 Sep 2021 21:04:06 +0000 (23:04 +0200)]
tests: Print metrics for both ports on error and fix port selection

On error we would only print the metrics of one port (twice) because
of a typo. Also PORT1 and PORT2 could be equal because of a logic
error. Fix the typo and simplify the port selection by using
non-overlapping ranges to select PORT1 and PORT2.

2 years agotests: Set DEBUGINFOD_CACHE_PATH for run-debuginfod-{file,query-retry}.sh
Mark Wielaard [Mon, 6 Sep 2021 19:48:38 +0000 (21:48 +0200)]
tests: Set DEBUGINFOD_CACHE_PATH for run-debuginfod-{file,query-retry}.sh

2 years agotests: Make sure all debuginfod tests use a clean database and cache.
Mark Wielaard [Fri, 3 Sep 2021 23:40:53 +0000 (01:40 +0200)]
tests: Make sure all debuginfod tests use a clean database and cache.

Always set DEBUGINFOD_CACHE_PATH to an unique (new) directory
and make sure that each debuginfod invocation uses a new sqlite
database.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agotests: Add debuginfod-subr.sh to EXTRA_DIST
Mark Wielaard [Fri, 3 Sep 2021 11:10:43 +0000 (13:10 +0200)]
tests: Add debuginfod-subr.sh to EXTRA_DIST

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agodebuginfod: Fracture tests/run-debuginfod-find.sh into specific tests
Noah Sanci [Tue, 10 Aug 2021 15:21:35 +0000 (11:21 -0400)]
debuginfod: Fracture tests/run-debuginfod-find.sh into specific tests

tests/run-debuginfod-find.sh was a massive test script with many broadly
varying tests. This caused the test script to fail when any number of
things went wrong and because of its intertwined nature, detecting the
source of a failure could be difficult. The size of the test script
also meant many unrelated tests were run making the testing process
unnecessarily lengthy.

This patch fractures tests/run-debuginfod-find.sh into smaller, more
manageable individual test script files. This ensures that when failure
occurs, a programmer can easily determine where their patch went
wrong. It also allows programmers to specify exactly which tests to
run, making testing more efficient. Redundancies are also reduced by
placing code in tests/debuginfod-subr.sh.

Signed-off-by: Noah Sanci <nsanci@redhat.com>
2 years agoconfigure.ac: rework gnu99 ext check to allow clang
Adrian Ratiu [Mon, 30 Aug 2021 15:43:13 +0000 (18:43 +0300)]
configure.ac: rework gnu99 ext check to allow clang

It is true that Clang does not support all gnu99 extensions [1],
but not all of them are used in the codebase and over time there
have been code cleanup efforts to improve Clang support.

For example after commit 779c57ea ("readelf: Pull advance_pc()
in file scope") there are no more nested function declarations
and elfutils now builds fine with Clang.

So in the interest of enabling Clang builds we remove the only
remaining blocker: the configure checks for nested functions and
variable length arrays which are also unused.

Considering mixed decls and code is also part of c99 standard,
the entire check becomes redundant and we can just replace
AC_PROG_CC -> AC_PROG_CC_C99.

[1] https://sourceware.org/bugzilla/show_bug.cgi?id=24964
Signed-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>
2 years agodebuginfod: Turn -d ":memory:" into -d "file::memory:?cache=shared"
Mark Wielaard [Sat, 28 Aug 2021 18:25:56 +0000 (20:25 +0200)]
debuginfod: Turn -d ":memory:" into -d "file::memory:?cache=shared"

debuginfod opens the database twice, once in read/wrote and once in
read-only mode. This means the magic ":memory:" in-memory database
cannot be used as is because the two connections don't really share
the underlying database. Fix this by turning ":memory:" into
":file::memory:?cache=shared" which makes the in-memory database
shared. See https://sqlite.org/inmemorydb.html

Document this in debuginfod.8 and make some tests use -d :memory:

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agotests: Use fresh separate databases for debuginfd forwarded-ttl-limit
Mark Wielaard [Sat, 28 Aug 2021 13:54:18 +0000 (15:54 +0200)]
tests: Use fresh separate databases for debuginfd forwarded-ttl-limit

Sharing the database between the two debuginfod instances that forward
queries to each other causes issues. Make both debuginfod instances
use a new fresh database.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agodebuginfod: PR27917 - protect against federation loops
Di Chen [Fri, 20 Aug 2021 05:03:21 +0000 (13:03 +0800)]
debuginfod: PR27917 - protect against federation loops

If someone misconfigures a debuginfod federation to have loops, and
a nonexistent buildid lookup is attempted, bad things will happen,
as is documented.

This patch aims to reduce the risk by adding an option to debuginfod
that functions kind of like an IP packet's TTL: a limit on the length of
XFF: header that debuginfod is willing to process. If X-Forwarded-For:
exceeds N hops, it will not delegate a local lookup miss to upstream
debuginfods.

Commit ab38d167c40c99 causes federation loops for non-existent resources
to result in multiple temporary deadlocks, each lasting for
$DEBUGINFOD_TIMEOUT seconds. Since concurrent requests for each unique
resource are now serialized, federation loops can result in one server
thread waiting to acquire a lock while the server thread holding the
lock waits for the first thread to respond to an http request.

This PR can help protect against the above multiple temporary deadlocks
behaviour. Ex. if --forwarded-ttl-limit=0 then the timeout behaviour of
local loops should be avoided.

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

Signed-off-by: Di Chen <dichen@redhat.com>
2 years agoAdd lib/error.c
Mark Wielaard [Fri, 27 Aug 2021 16:47:30 +0000 (18:47 +0200)]
Add lib/error.c

This new file was supposed to be part of 4d6dd0e5a "lib: avoid potential
problems with `-fno-common`".

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolib: avoid potential problems with `-fno-common`
Saleem Abdulrasool [Fri, 27 Aug 2021 15:51:47 +0000 (15:51 +0000)]
lib: avoid potential problems with `-fno-common`

This properly homes the fallback function into a translation unit rather
than trying to define an inline common definition for the fallback path.
The intent of the original approach was to actually simply avoid adding
a new source file that is used for the fallback path.  However, that may
cause trouble with multiple definitions if the symbol does not get vague
linkage (which itself is not particularly great).  This simplifies the
behaviour at the cost of an extra inode.

2 years agolib: remove unused `STROF` definition (NFC)
Saleem Abdulrasool [Fri, 27 Aug 2021 15:20:13 +0000 (15:20 +0000)]
lib: remove unused `STROF` definition (NFC)

This definition was in the fallback path, where `sys/cdefs.h` is not
available.  Now that we have a single path through here, this macro gets
defined, though is unused.  Remove the unused macro definition.

Signed-off-by: Saleem Abdulrasool <abdulras@google.com>
2 years agohandle libc implementations which do not provide `error.h`
Saleem Abdulrasool [Fri, 20 Aug 2021 20:28:23 +0000 (20:28 +0000)]
handle libc implementations which do not provide `error.h`

Introduce a configure time check for the presence of `error.h`.  In the
case that `error.h` is not available, we can fall back to `err.h`.
Although `err.h` is not a C standard header (it is a BSD extension),
many libc implementations provide.  If there are targets which do not
provide an implementation of `err.h`, it would be possible to further
extend the implementation to be more portable.

This resolves bug #21008.

Signed-off-by: Saleem Abdulrasool <abdulras@google.com>
2 years agodebuginfod, elfclassify: remove unnecessary header inclusion
Saleem Abdulrasool [Fri, 20 Aug 2021 18:21:20 +0000 (18:21 +0000)]
debuginfod, elfclassify: remove unnecessary header inclusion

`error.h`'s inclusion was centralised into the `system.h` header.  As
the implementation currently includes `system.h` already, the inclusion
of `error.h` is unnecessary.  This prepares for a future portability
change to allow elfutil to build with alternate libc implementations.

Signed-off-by: Saleem Abdulrasool <abdulras@google.com>
2 years agolib: remove usage of `sys/cdefs.h`
Saleem Abdulrasool [Fri, 20 Aug 2021 18:20:08 +0000 (18:20 +0000)]
lib: remove usage of `sys/cdefs.h`

This header is a BSD header that is also available in glibc.  However,
this is a not a standard C header and was used for `__CONCAT`.  Because
this is not a standard header, not all libc implementations provide the
header.  Remove the usage of the header and always use the previously
fallback path.  This is needed in order to build with musl.

Signed-off-by: Saleem Abdulrasool <abdulras@google.com>
2 years agoPR27950 - package new debuginfod-client-config.7 man page in rpm
Frank Ch. Eigler [Fri, 20 Aug 2021 17:54:55 +0000 (13:54 -0400)]
PR27950 - package new debuginfod-client-config.7 man page in rpm

The template rpm spec file needs to include the new .7 page in all the
subrpms whose man pages may .so it.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2 years agoPR28249: correct debuginfod after-you locking
Frank Ch. Eigler [Thu, 19 Aug 2021 17:11:11 +0000 (13:11 -0400)]
PR28249: correct debuginfod after-you locking

The initial code for bug #27673 accidentally nuked all buildid service
concurrency, not just identical concurrent requests.  Correct this
with one-liner patch.  Observing the effect in the automated testsuite
is difficult, so hand-tested against large requests and short ones,
run in an interleaved way.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2 years agodebuginfod-doc: PR27950: make distcheck happy
Frank Ch. Eigler [Wed, 11 Aug 2021 23:32:29 +0000 (19:32 -0400)]
debuginfod-doc: PR27950: make distcheck happy

The debuginfod-client-config.7 shouldn't be included twice in
notrans_dist_man7_MANS.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2 years agodebuginfod-doc: PR27950 - Remove redanduncies in man page.
Alice Zhang [Wed, 4 Aug 2021 20:50:44 +0000 (16:50 -0400)]
debuginfod-doc: PR27950 - Remove redanduncies in man page.

Create a new file, debuginfod-client-config.7, that holds all
environment variables and cache control files related info. Get rid of
repetitive definitions in three other files, instead, those files will
include the content of new file. Any future modification related to
environment variables and cache files will only require changes in one
file.

Signed-off-by: Alice Zhang <alizhang@redhat.com>
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3 years agotests: Allow an extra pthread_kill frame in backtrace tests
Mark Wielaard [Wed, 4 Aug 2021 19:01:27 +0000 (21:01 +0200)]
tests: Allow an extra pthread_kill frame in backtrace tests

glibc 2.34 calls pthread_kill from the raise function. Before raise
directly called the (tg)kill syscall. So allow pthread_kill to be the
first frame in a backtrace where raise is expected. Also change some
asserts to fprintf plus abort to make it more clear why the testcase
fails.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agodebuginfod: PR27982 - added DEBUGINFOD_MAXSIZE and DEBUGINFOD_MAXTIME
Noah Sanci [Mon, 26 Jul 2021 17:29:11 +0000 (13:29 -0400)]
debuginfod: PR27982 - added DEBUGINFOD_MAXSIZE and DEBUGINFOD_MAXTIME

DEBUGINFOD_TIMEOUT is a good way to catch servers that are too slow to
*start* transmitting a file.  But we have no way of limiting total
download time or space.  A user might prefer to have his debugger fetch
only quick & small files, and make do without the bigger ones.  Some
transitive dependencies of e.g. gnome programs are huge: 3GB of LLVM
debuginfo, 1GB of webkitgtk, etc. etc.
DEBUGINFOD_MAXSIZE and DEBUGINFOD_MAXTIME were added to dictate the
max download size and time of a debuginfod client. DEBUGINFOD_MAXSIZE
is handled server-side and is sent using the http header:
X-DEBUGINFOD-MAXSIZE. The client side then checks to ensure this maxsize
has been respected.

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

Signed-off-by: Noah Sanci <nsanci@redhat.com>
3 years agoupdate Japanese translation
Hayatsu Shunsuke [Sun, 25 Jul 2021 06:50:30 +0000 (15:50 +0900)]
update Japanese translation

Signed-off-by: Hayatsu Shunsuke <hayatsu.shunsuke@gmail.com>
3 years agodebuginfod: PR27983 - ignore duplicate urls
Noah Sanci [Fri, 9 Jul 2021 18:53:10 +0000 (14:53 -0400)]
debuginfod: PR27983 - ignore duplicate urls

Gazing at server logs, one sees a minority of clients who appear to have
duplicate query traffic coming in: the same URL, milliseconds apart.
Chances are the user accidentally doubled her $DEBUGINFOD_URLS somehow,
and the client library is dutifully asking the servers TWICE. Bug #27863
reduces the pain on the servers' CPU, but dupe network traffic is still
being paid.  We should reject sending outright duplicate concurrent
traffic.
The urls are now simply removed upon finding a duplicate after url
construction.

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

Signed-off-by: Noah Sanci <nsanci@redhat.com>
3 years agolib: Add static inline reallocarray fallback function
Mark Wielaard [Wed, 28 Jul 2021 14:46:36 +0000 (16:46 +0200)]
lib: Add static inline reallocarray fallback function

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agodebuginfod: PR28034 - client-side %-escape url characters
Noah Sanci [Fri, 16 Jul 2021 19:16:20 +0000 (15:16 -0400)]
debuginfod: PR28034 - client-side %-escape url characters

When requesting some source files, some URL-inconvenient chars
sometimes pop up.  Example from f33 libstdc++:
/buildid/44d8485cb75512c2ca5c8f70afbd475cae30af4f/source/usr/src/debug/
gcc-10.3.1-1.fc33.x86_64/obj-x86_64-redhat-linux/x86_64-redhat-linux/
libstdc++-v3/src/c++11/../../../../../libstdc++-v3/src/c++11/
condition_variable.cc
As this URL is passed into debuginfod's handler_cb, it appears that the
+ signs are helpfully unescaped to spaces by libmicrohttpd, which
'course breaks everything.
In order to ensure the server properly parses urls such as this one,
%-escape characters on the client side so that the correct url
is preserved and properly processed on the server side.

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

Signed-off-by: Noah Sanci <nsanci@redhat.com>
3 years agodebuginfod: Minor run-debuginfod-find.sh test fixes
Noah Sanci [Wed, 21 Jul 2021 18:52:07 +0000 (14:52 -0400)]
debuginfod: Minor run-debuginfod-find.sh test fixes

$PORT3's metrics are not reported on error and $PID4 was not properly
killed. This patch addresses both of those issues by reporting the
metrics of $PORT3 as $PORT1 and $PORT2 were in err() and waiting for
$PID4 to terminate before continuing with the test.

Signed-off-by: Noah Sanci <nsanci@redhat.com>
3 years agolibelf: Optimize elf_strptr.c validate_str by checking last char first
Mark Wielaard [Mon, 19 Jul 2021 13:52:51 +0000 (15:52 +0200)]
libelf: Optimize elf_strptr.c validate_str by checking last char first

In most cases the last char of the sectio will be zero. Check that
first before calling memrchr. This is a minor optimization in normal
cases. But it helps asan a lot by removing the memrchr call in most
cases.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agoreadelf: Pull advance_pc() in file scope
Timm Bäder [Thu, 18 Mar 2021 09:25:24 +0000 (10:25 +0100)]
readelf: Pull advance_pc() in file scope

Make advance_pc() a static function so we can get rid of another nested
function. Rename it to run_advance_pc() and use a local advance_pc()
macro to pass all the local variables. This is similar to what the
equivalent code in libdw/dwarf_getsrclines.c is doing.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agodebuginfod: PR25978 - Created the prefetch fdcache
Noah [Thu, 10 Jun 2021 14:29:45 +0000 (10:29 -0400)]
debuginfod: PR25978 - Created the prefetch fdcache

The debuginfod fdcache-prefetch logic has been observed to show some
degeneracies in operation.  Since fdcache evictions are done
frequently, and freshly prefetched archive elements are put at the
back of lru[], each eviction round can summarily nuke things that
were just prefetched .... and are just going to be prefetched again.
It would be better to have two lru lists, or being able to insert
newly prefetched entries somewhere in the middle of the list rather
than at the very very end.

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

Signed-off-by: Noah Sanci <nsanci@redhat.com>
3 years agoPR27531: retry within default retry_limit will be supported.
Alice Zhang [Tue, 6 Jul 2021 20:12:43 +0000 (16:12 -0400)]
PR27531: retry within default retry_limit will be supported.

In debuginfod-client.c (debuginfod_query_server),insert a
goto statement for jumping back to the beginning of curl
handles set up if query fails and a non ENOENT error is returned.

Also introduced DEBUGINFOD_RETRY_LIMIT_ENV_VAR and default
DEBUGINFOD_RETRY_LIMIT(which is 2).

Correponding test has been added to tests/run-debuginfod-find.sh

Signed-off-by: Alice Zhang <alizhang@redhat.com>
3 years agodebuginfod: PR27711 - Use -I/-X regexes during groom phase
Noah [Wed, 7 Jul 2021 18:40:10 +0000 (14:40 -0400)]
debuginfod: PR27711 - Use -I/-X regexes during groom phase

The debuginfod -I/-X regexes operate during traversal to identify
those files in need of scanning.  The regexes are not used during
grooming.  This means that if from run to run, the regex changes so
that formerly indexed files are excluded from traversal, the data is
still retained in the index.

This is both good and bad.  On one hand, if the underlying data is
still available, grooming will preserve the data, and let clients ask
for it.  On the other hand, if the growing index size is a problem,
and one wishes to age no-longer-regex-matching index data out, there
is no way.

Let's add a debuginfod flag to use regexes during grooming.
Specifically, in groom(), where the stat() test exists, also check
for regex matching as in scan_source_paths().  Treat failure of the
regex the same way as though the file didn't exist.

Signed-off-by: Noah Sanci <nsanci@redhat.com>
3 years agotests: Fix EXTRA_DIST typo in testfile-largealign.o.bz2
Mark Wielaard [Thu, 8 Jul 2021 09:44:26 +0000 (11:44 +0200)]
tests: Fix EXTRA_DIST typo in testfile-largealign.o.bz2

Signed-off-by: Mark Wielaard <mark@klomp.org>
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>