platform/upstream/elfutils.git
2 years agotests: include config.h first.
Mark Wielaard [Sun, 16 Oct 2022 16:23:06 +0000 (18:23 +0200)]
tests: include config.h first.

Otherwise some symbols (lseek, open) might not get the 64bit offset
variants because they don't pick up _FILE_OFFSET_BITS.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agotests: Check lseek, read and malloc results with correct types in test.
Mark Wielaard [Sun, 16 Oct 2022 16:02:46 +0000 (18:02 +0200)]
tests: Check lseek, read and malloc results with correct types in test.

When compiling dwfl-report-offline-memory.c on some systems (latest
gcc/glibc and --enable-sanitize-undefined) we might get:

In file included from /usr/include/features.h:490,
                 from /usr/include/assert.h:35,
                 from dwfl-report-offline-memory.c:18:
In function ‘read’,
    inlined from ‘main’ at dwfl-report-offline-memory.c:68:23:
/usr/include/bits/unistd.h:38:10: error: ‘__read_alias’ specified size 18446744073709551615
  exceeds maximum object size 9223372036854775807 [-Werror=stringop-overflow=]
   38 |   return __glibc_fortify (read, __nbytes, sizeof (char),
      |          ^~~~~~~~~~~~~~~
/usr/include/bits/unistd.h: In function ‘main’:
/usr/include/bits/unistd.h:26:16: note: in a call to function ‘__read_alias’ declared with
  attribute ‘access (write_only, 2, 3)’
   26 | extern ssize_t __REDIRECT (__read_alias, (int __fd, void *__buf,
      |                ^~~~~~~~~~
cc1: all warnings being treated as errors
make[2]: *** [Makefile:2461: dwfl-report-offline-memory.o] Error 1

Fix by using the correct types and checking all return values.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibdwfl: add dwfl_report_offline_memory
Aleksei Vetrov [Tue, 20 Sep 2022 13:36:37 +0000 (13:36 +0000)]
libdwfl: add dwfl_report_offline_memory

This method allows to read and report ELF from memory instead of opening
a file. That way arbitrary memory can be worked with, e.g. when coming
from a stream without the need to persist.

Another useful application is for fuzzing, because fuzzers might be able
to track accesses to the memory and change the fuzzer input to cover
more edge cases through more targeted input. Hence, add a new function
along with a test case.

Signed-off-by: Aleksei Vetrov <vvvvvv@google.com>
2 years agotests: Add libeu to tests needing error() API
Khem Raj [Tue, 13 Sep 2022 16:40:06 +0000 (09:40 -0700)]
tests: Add libeu to tests needing error() API

A local error() implementation is used when libc does not provide it,
therefore link in libeu.a which contains this function in tests needing
error() API

Signed-off-by: Khem Raj <raj.khem@gmail.com>
2 years agodebuginfod-client: Ensure only negative error codes returned.
Aaron Merey [Wed, 28 Sep 2022 14:04:23 +0000 (10:04 -0400)]
debuginfod-client: Ensure only negative error codes returned.

Switch a couple error codes from positive to negative so they aren't
interpreted as file descriptors by the caller.

2 years agoRetrive 64bit timestamp from curl_easy_getinfo on _TIME_BITS=64 environment
河辺 岳人 [Tue, 27 Sep 2022 12:10:39 +0000 (21:10 +0900)]
Retrive 64bit timestamp from curl_easy_getinfo on _TIME_BITS=64 environment

On 32bit system compiled with -D_TIME_BITS=64, following tests failed:

FAIL: run-debuginfod-archive-test.sh
FAIL: run-debuginfod-archive-groom.sh
FAIL: run-debuginfod-archive-rename.sh
FAIL: run-debuginfod-federation-sqlite.sh
FAIL: run-debuginfod-federation-metrics.sh
FAIL: run-debuginfod-federation-link.sh

due to tests/debuginfod-subr.sh:archive_test failing on
"test $fileame -ot `pwd`", with LHS file having a bogus timestamp.
LHS is generated by debuginfo-find as a cache file.

I'm not sure the fix is the correct way, but
since -D_TIME_BITS=64 mandates -D_FILE_OFFSET_BITS=64 in glibc,
this does work on glibc environment.

Signed-off-by: Taketo Kabe <kabe@sra-tohoku.co.jp>
2 years agoar: Correct -N COUNT off-by-one
Mark Wielaard [Sun, 28 Aug 2022 15:46:08 +0000 (17:46 +0200)]
ar: Correct -N COUNT off-by-one

When using instance [COUNT], the instance check is wrong.
instance-- == 0 should be --instance == 0.

Add a testcase run-ar-N.sh that uses -N COUNT with extract and delete
operations checking the right instance was extracted and deleted.

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

Reported-by: panxiaohe <panxh_ran@163.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibelf: Correctly decode ar_mode as octal string
Mark Wielaard [Sun, 28 Aug 2022 17:51:13 +0000 (19:51 +0200)]
libelf: Correctly decode ar_mode as octal string

ar_mode is encoded as an octal ascii string, not decimal. Add a new
OCT_FIELD macro to decode it.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoPR28284 cont'd, ->winning_headers reset at start of new query
Frank Ch. Eigler [Thu, 8 Sep 2022 13:47:45 +0000 (09:47 -0400)]
PR28284 cont'd, ->winning_headers reset at start of new query

Mark noted we need to ditch the last client ->winning_headers along
with the last ->url.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2 years agoadd debuginfod_get_headers if DUMMY_LIBDEBUGINFOD is used
Martin Liska [Thu, 8 Sep 2022 09:12:53 +0000 (11:12 +0200)]
add debuginfod_get_headers if DUMMY_LIBDEBUGINFOD is used

Signed-off-by: Martin Liska <mliska@suse.cz>
2 years agoPR28284: add tweaks on previous debuginfod x-debuginfod* header forwarding work
Frank Ch. Eigler [Fri, 2 Sep 2022 16:41:38 +0000 (12:41 -0400)]
PR28284: add tweaks on previous debuginfod x-debuginfod* header forwarding work

Embrace case-independent headers, more fully document, handle HTTP \r.
In addition to test case, hand-tested against fedora debuginfod
instances, running federated servers under valgrind.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2 years agoPR28284 - Debuginfod header functionality implemented
Noah Sanci [Wed, 15 Jun 2022 14:07:29 +0000 (10:07 -0400)]
PR28284 - Debuginfod header functionality implemented

Debuginfod and debuginfod clients are now equipped to send
and receive http headers prefixed with X-DEBUGINFOD and
print them in verbose mode for more context

Signed-off-by: Noah Sanci <nsanci@redhat.com>
2 years agodebuginfod: Use auto-sized connection pool when -C is not given with arg
Aaron Merey [Sat, 3 Sep 2022 01:23:32 +0000 (21:23 -0400)]
debuginfod: Use auto-sized connection pool when -C is not given with arg

Since commit 4b42d9ad, libmicrohttpd's epoll event loop is used when
available in which case we must disable its setting for spawning a thread
per request.  This contradicts the debuginfod doc's description of '-C',
which indicates that if this command line option is not given then the
thread pool size is unbounded.

Fix this by using an auto-sized thread pool when '-C' is not given, just
as we do when it's given with no argument. Update the doc's description
of '-C'.

Also use a fixed-size pool even if epoll is not supported. The unbounded
pool config cannot be considered entirely reliable as it appears to cause
random fails in the run-debuginfod-webapi-concurrency test.

Signed-off-by: Aaron Merey <amerey@redhat.com>
2 years agoAdd missing changelog entries.
Martin Liska [Wed, 17 Aug 2022 13:30:19 +0000 (15:30 +0200)]
Add missing changelog entries.

2 years agoconfig/debuginfod.sysconfig: Clarify & classify the variables
Frank Ch. Eigler [Wed, 17 Aug 2022 13:01:23 +0000 (09:01 -0400)]
config/debuginfod.sysconfig: Clarify & classify the variables

Some of them are for debuginfod command line; others are environment
variables for the embedded client library.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2 years agoAdd new debuginfod.sysconfig value DEBUGINFOD_EXTRA_ARGS
Martin Liska [Wed, 17 Aug 2022 12:24:32 +0000 (14:24 +0200)]
Add new debuginfod.sysconfig value DEBUGINFOD_EXTRA_ARGS

Split DEBUGINFOD_PATHS and put non-path arguments to the newly created
variable called DEBUGINFOD_EXTRA_ARGS.

Signed-off-by: Martin Liska <mliska@suse.cz>
2 years agodebuginfod: fix http_requests_total{type="debuginfo"} when dwz is used
Martin Liska [Wed, 17 Aug 2022 07:38:17 +0000 (09:38 +0200)]
debuginfod: fix http_requests_total{type="debuginfo"} when dwz is used

When dwarf_extract_source_paths is called, it can call handle_buildid
when a rpm file used dwz. Ignore such internal request in
http_requests_total statistics.

Signed-off-by: Martin Liska <mliska@suse.cz>
2 years agodebuginfod: print filename for "cannot open archive" error
Martin Liska [Wed, 17 Aug 2022 07:11:10 +0000 (09:11 +0200)]
debuginfod: print filename for "cannot open archive" error

Report the file that has such a problem so that one can inspect it.

Signed-off-by: Martin Liska <mliska@suse.cz>
2 years agoSupport nullglob in profile.*.in files
Martin Liska [Tue, 16 Aug 2022 13:14:26 +0000 (15:14 +0200)]
Support nullglob in profile.*.in files

In openSUSE we have the following RPM checker that uses
shopt -s nullglob:
https://github.com/openSUSE/post-build-checks/blob/master/checks/50-check-libtool-deps#L31

The script loads all /etc/profile.d/*.sh files via source $FILE which
can end up by stuck cat (with no arguments):

shopt -s nullglob ; cat "/etc/debuginfod"/*.urls
(stuck)

2 years agoPR29474: debuginfod
Frank Ch. Eigler [Mon, 15 Aug 2022 10:20:10 +0000 (06:20 -0400)]
PR29474: debuginfod

Previous code sometimes confused debuginfod with concurrent queries
targeting the same RPM.  One thread fetching & prefetching, the other
thread misinterpreted the sudden presence of its target file in the
fdcache as a mere unnecessary prefetch duplicate.  But if it was the
other thread's target file, previous code would -skip- it completely,
resulting in a 404 error.  New code allows the other thread to also
decompress the target file and return it, and still continue to its
own prefetching process for other files.

There's a performance trade-off here.  Another option would be for the
other thread to check the fdcache regularly and abort its own
prefetch/fetch/prefetch loop early in case of a sudden target file
hit.  That'd save CPU probably but it'd stop prefetching of later
segments of the input archive, which could save future time.

Automated testing is too time/load sensitive to attempt.  Confirmed
working with Martin's stress tester.

Reported-By: Martin Liška <mliska@suse.cz>
Signed-Off-By: Frank Ch. Eigler <fche@redhat.com>
2 years agoreadelf: Handle SHT_RISCV_ATTRIBUTES like SHT_GNU_ATTRIBUTES
Andreas Schwab [Wed, 10 Aug 2022 08:52:42 +0000 (10:52 +0200)]
readelf: Handle SHT_RISCV_ATTRIBUTES like SHT_GNU_ATTRIBUTES

Signed-off-by: Andreas Schwab <schwab@suse.de>
2 years agoFill in fde_augmentation_data_size in dwarf_next_cfi
Ulrich Drepper [Thu, 11 Aug 2022 13:17:33 +0000 (15:17 +0200)]
Fill in fde_augmentation_data_size in dwarf_next_cfi

(dwarf_next_cfi): Don't skip processing the augmentation string.
Be more stringent what to accept.

2 years agoelflint: Allow zero p_memsz for PT_RISCV_ATTRIBUTES
Andreas Schwab [Tue, 9 Aug 2022 08:29:53 +0000 (10:29 +0200)]
elflint: Allow zero p_memsz for PT_RISCV_ATTRIBUTES

The RISCV_ATTRIBUTES segment is not meant to be loaded.

Signed-off-by: Andreas Schwab <schwab@suse.de>
2 years agobackends: Handle new RISC-V specific definitions
Andreas Schwab [Tue, 9 Aug 2022 07:54:28 +0000 (09:54 +0200)]
backends: Handle new RISC-V specific definitions

Handle PT_RISCV_ATTRIBUTES, SHT_RISCV_ATTRIBUTES, DT_RISCV_VARIANT_CC.

Signed-off-by: Andreas Schwab <schwab@suse.de>
2 years agolibelf: Sync elf.h from glibc
Andreas Schwab [Mon, 8 Aug 2022 11:44:08 +0000 (13:44 +0200)]
libelf: Sync elf.h from glibc

Adds PT_RISCV_ATTRIBUTES, SHT_RISCV_ATTRIBUTES, PT_AARCH64_MEMTAG_MTE,
RELR definitions, LoongArch relocations.

dwelf_elf_e_machine_string was updated to handle EM_LOONGARCH, and
ebl_dynamic_tag_name was updated to handle the new RELR dynamic tags.

Signed-off-by: Andreas Schwab <schwab@suse.de>
2 years agolib: Add documentation to explain concurrent htab resizing.
Mark Wielaard [Fri, 5 Aug 2022 15:17:54 +0000 (17:17 +0200)]
lib: Add documentation to explain concurrent htab resizing.

Document which lock is held by which thread and how moving the
htab data is coordinated.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agopo: standardize Project-Id-Version to just elfutils
Mark Wielaard [Fri, 5 Aug 2022 17:09:36 +0000 (19:09 +0200)]
po: standardize Project-Id-Version to just elfutils

The po/pl.po file already just said Project-Id-Version: elfutils\n
Do the same for the other po files which had somewhat odd names.
The generated pot file will still include the version number too.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agotests: run-low_high_pc.sh: drop redundant 'lx' suffix
Sergei Trofimovich via Elfutils-devel [Sat, 6 Aug 2022 08:55:06 +0000 (09:55 +0100)]
tests: run-low_high_pc.sh: drop redundant 'lx' suffix

Noticed when debugged test failure:

    lowpc: 8049000, highpc: 8049000lx
    ../sysdeps/i386/crti.S: [2def] '_init' highpc <= lowpc

Signed-off-by: Sergei Trofimovich <slyich@gmail.com>
2 years agodebuginfod: optimize regular expressions in groom()
Josef Cejka [Wed, 3 Aug 2022 11:33:21 +0000 (13:33 +0200)]
debuginfod: optimize regular expressions in groom()

Check if applying of -I and -X during grooming is enabled
before the regular expressions are matched.

Signed-off-by: Josef Cejka <jcejka@suse.de>
2 years agotests: Add initial scan wait_ready in run-debuginfod-percent-escape.sh
Mark Wielaard [Mon, 1 Aug 2022 10:18:30 +0000 (12:18 +0200)]
tests: Add initial scan wait_ready in run-debuginfod-percent-escape.sh

Otherwise wait_ready for thread_work_total{role="traverse"} after the
kill -USR1 can be either zero, one or two. We want to see it change to
one first, then after the kill -USR1 it should change to two to be sure
the scan happened after the new binary was created.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoreadelf: memrchr searches backwards but takes the start buf as argument
Mark Wielaard [Mon, 1 Aug 2022 00:02:16 +0000 (02:02 +0200)]
readelf: memrchr searches backwards but takes the start buf as argument

The bug (caught by valgrind) was giving memrchr to end of the buffer.

Also as cleanup, Use d_val not d_ptr for calculating offset.

2 years agoreadelf: Support --dynamic with --use-dynamic
Di Chen [Thu, 28 Apr 2022 11:55:33 +0000 (19:55 +0800)]
readelf: Support --dynamic with --use-dynamic

Currently, eu-readelf is using section headers to dump the dynamic
segment information (print_dynamic -> handle_dynamic).

This patch adds new options to eu-readelf (-D, --use-dynamic)
for (-d, --dynamic).

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

Signed-off-by: Di Chen <dichen@redhat.com>
2 years agolibdwfl: Add new function dwfl_frame_reg
Di Chen [Thu, 28 Jul 2022 08:31:05 +0000 (16:31 +0800)]
libdwfl: Add new function dwfl_frame_reg

Dwfl has most of the infrastructure to keep the full unwind state,
including the state of unwound registers per frame using
Dwfl_Thread_Callbacks. But there is no public API to access the state,
except for the PC (dwfl_frame_pc).

This commit adds a new function dwfl_frame_reg to get the value of the
DWARF register number in the given frame.

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

Signed-off-by: Di Chen <dichen@redhat.com>
2 years agolibdwfl: Rewrite reading of ar_size in elf_begin_rand
Mark Wielaard [Thu, 28 Jul 2022 13:31:12 +0000 (15:31 +0200)]
libdwfl: Rewrite reading of ar_size in elf_begin_rand

With GCC 12.1.1, glibc 2.35, -fsanitize=undefined and
-D_FORTIFY_SOURCE=3 we get the following error message:

In file included from /usr/include/ar.h:22,
                 from ../libelf/libelfP.h:33,
                 from core-file.c:31:
In function ‘pread’,
    inlined from ‘pread_retry’ at ../lib/system.h:188:21,
    inlined from ‘elf_begin_rand’ at core-file.c:86:16,
    inlined from ‘core_file_read_eagerly’ at core-file.c:205:15:
/usr/include/bits/unistd.h:74:10: error: ‘__pread_alias’ writing 58 or more bytes into a region of size 10 overflows the destination [-Werror=stringop-overflow=]
   74 |   return __glibc_fortify (pread, __nbytes, sizeof (char),
      |          ^~~~~~~~~~~~~~~
/usr/include/ar.h: In function ‘core_file_read_eagerly’:
/usr/include/ar.h:41:10: note: destination object ‘ar_size’ of size 10
   41 |     char ar_size[10];           /* File size, in ASCII decimal.  */
      |          ^~~~~~~
/usr/include/bits/unistd.h:50:16: note: in a call to function ‘__pread_alias’ declared with attribute ‘access (write_only, 2, 3)’
   50 | extern ssize_t __REDIRECT (__pread_alias,
      |                ^~~~~~~~~~
cc1: all warnings being treated as errors

The warning disappears when dropping either -fsanitize=undefined
or when using -D_FORTIFY_SOURCE=2. It looks like a false positive.
But I haven't figured out how/why it happens.

The code is a little tricky to proof correct though. The ar_size
field is a not-zero terminated string ASCII decimal, right-padded
with spaces. Which is then converted with strtoll. Relying on the
fact that the struct ar_hdr is zero initialized, so there will be
a zero byte after the ar_size field.

Rewrite the code to just use a zero byte terminated char array.
Which is much easier to reason about. As a bonus the error disappears.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agodebuginfod: create indexes to speed up grooming
Josef Cejka [Fri, 29 Jul 2022 16:05:05 +0000 (12:05 -0400)]
debuginfod: create indexes to speed up grooming

Create indexes on _r_de and _f_de tables
to speed up delete operations called by groom() function.

Primary keys of those tables are optimalized to search rows
by buildids so delete by file and mtime attributes
has to scan the whole table. On large database can single
delete query take minutes and grooming will be aborted
before completion by time limit.

New indexes are compatible with current sqlite schema.

Signed-off-by: Josef Cejka <jcejka@suse.de>
2 years agodwfl_get_debuginfod_client: add dummy parameter for --disable-libdebuginfod
Shahab Vahedi [Mon, 18 Jul 2022 17:44:06 +0000 (13:44 -0400)]
dwfl_get_debuginfod_client: add dummy parameter for --disable-libdebuginfod

Since the stub version of "dwfl_get_debuginfod_client" doesn't name its
parameter, building elfuitls fails on a system with gcc 10.2.1:

-----------------------------------------------------------------------------
$ ./configure ... --disable-libdebuginfod
$ make
  Making all in libdwfl
    CC       debuginfod-client.o
  /src/libdwfl/debuginfod-client.c: In function 'dwfl_get_debuginfod_client':
  /src/libdwfl/debuginfod-client.c:145:29: error: parameter name omitted
    145 | dwfl_get_debuginfod_client (Dwfl *)
        |                             ^~~~~~
  make[2]: *** [Makefile:707: debuginfod-client.o] Error 1
-----------------------------------------------------------------------------

This fixes the issue by providing a name for the unused parameter.

Signed-off-by: Shahab Vahedi <shahab@synopsys.com>
2 years agoMove dwfl_get_debuginfod_client to ELFUTILS_0.188
Mark Wielaard [Wed, 13 Jul 2022 20:34:36 +0000 (22:34 +0200)]
Move dwfl_get_debuginfod_client to ELFUTILS_0.188

0.187 was already released, so add new function to 0.188. Also add
NEWS entry and INTUSE.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoIntroduce public dwfl_get_debuginfod_client API
Milian Wolff [Thu, 7 Jul 2022 17:33:35 +0000 (19:33 +0200)]
Introduce public dwfl_get_debuginfod_client API

Dwfl can use debuginfod internally, which was so far totally opaque
to the outside. While the functionality is great for users of the
dwfl API, the long wait times induced by downloading of data over
debuginfod lead to complaints by endusers. To offer them a bit more
insight into the internal ongoings, one can now use e.g.
`debuginfod_set_progressfn` on the handle returned by
`dwfl_get_debuginfod_client` to report download progress.

Rename get_client to dwfl_get_debuginfod_client and make it public.
Unconditionally compile debuginfod-client.c and stub the new public
function and always return NULL when debuginfod integration was
disabled.

Signed-off-by: Milian Wolff <mail@milianw.de>
2 years agodoc/debuginfod.8: tiny obvious typo fix
Frank Ch. Eigler [Wed, 8 Jun 2022 22:18:08 +0000 (18:18 -0400)]
doc/debuginfod.8: tiny obvious typo fix

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2 years agoArm Ehdr flag printing
Ulrich Drepper [Wed, 1 Jun 2022 11:14:27 +0000 (13:14 +0200)]
Arm Ehdr flag printing

Arm needs to decode flags and I modeled it after the binutils code.
The same messages are printed.  Given the requirement of the interface
and the ABIs the current version of the callback function isn't
sufficient unless one wants to create a stateful interface.  The
problem is that most flags need to be interpreted in the context of
the ABI version.  So I changed the API to also pass the original flag
value.  This shouldn't be a problem because there are no users yet.

There is also a bug in ebl_machine_flag_name. When copying the string
provided by the callback cp is moved past the NUL byte.  It should
move to the NUL byte.  Otherwise one cannot anything but the first
added flag description.  Finally some cosmetic changes (space after
each comma in the output).

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoNEWS & ChangeLog: add debuginfod blurbs
Frank Ch. Eigler [Fri, 3 Jun 2022 16:56:43 +0000 (12:56 -0400)]
NEWS & ChangeLog: add debuginfod blurbs

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2 years agodebuginfod: add --disable-source-scan option
Michael Trapp [Fri, 3 Jun 2022 16:54:17 +0000 (12:54 -0400)]
debuginfod: add --disable-source-scan option

--disable-source-scan disables scanning of the dwarf source info
of debuginfo sections. The source info is not required in setups
without source code access.

Signed-off-by: Michael Trapp <michael.trapp@sap.com>
2 years agoPR28577: Make run-debuginfod-fd-prefetch-caches.sh test something
Noah Sanci [Fri, 13 May 2022 18:32:27 +0000 (14:32 -0400)]
PR28577: Make run-debuginfod-fd-prefetch-caches.sh test something

Update to the run-debuginfod-fd-prefetch to make the test more
sound.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoAdded debuginfod.service.8 manual page.
Noah Sanci [Thu, 2 Jun 2022 18:26:46 +0000 (14:26 -0400)]
Added debuginfod.service.8 manual page.

Signed-off-by: Noah Sanci <nsanci@redhat.com>
2 years agotests: Disable run-debuginfod-federation-metrics.sh for old libmicrohttpd
Mark Wielaard [Thu, 2 Jun 2022 15:36:39 +0000 (17:36 +0200)]
tests: Disable run-debuginfod-federation-metrics.sh for old libmicrohttpd

On really old libmicrohttpd the run-debuginfod-federation-metrics.sh
test will crash debuginfod after too many file descriptors have been
used. libmicrohttpd looses track of the state and aborts instead of
producing an error. Just disable the testcase on these very old versions.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibdwfl: Update docs and nonnull attributes for dwfl_module_addrinfo
Mark Wielaard [Sun, 15 May 2022 19:53:41 +0000 (21:53 +0200)]
libdwfl: Update docs and nonnull attributes for dwfl_module_addrinfo

Make clear that both the offset and sym arguments cannot be NULL.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agodebuginfod: update mtime of interval_path as early as possible
Mark Wielaard [Sun, 8 May 2022 19:16:10 +0000 (21:16 +0200)]
debuginfod: update mtime of interval_path as early as possible

Call utime on interval_path file as soon as the thread is committed to
cleanup the cache files. This will prevent other threads trying to
also commit to cleaning the cache files. Having multiple threads try
to clean the cache simultaniously doesn't improve cleanup speed
because the threads will try to delete the files in the same order.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agodebuginfod: Remove debuginfod_init_cache
Mark Wielaard [Sun, 8 May 2022 17:27:48 +0000 (19:27 +0200)]
debuginfod: Remove debuginfod_init_cache

debuginfod_init_cache would create all config files if they didn't
exist yet. It always made two stat calls. Then debuginfod_clean_cache
would call debuginfod_config_cache which did the same checks and
created any missing config files. Just make sure the cache_path
directory exists and remove debuginfod_init_cache before calling
debuginfod_clean_cache.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agodebuginfod: Make sure debuginfod_config_cache always returns valid stat
Mark Wielaard [Sun, 8 May 2022 21:55:19 +0000 (23:55 +0200)]
debuginfod: Make sure debuginfod_config_cache always returns valid stat

If the condig file which value was requested from
debuginfod_config_cache didn't exist yet, stat would fail and no valid
struct stat would be returned even when the file was correctly
created. Fix this by always using O_CREAT to open the file, and reuse
that file descriptor to call fstat and for either writing the default
value or reading the config file value.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agodebuginfod: Always request servname from getnameinfo for conninfo.
Mark Wielaard [Sun, 8 May 2022 08:59:52 +0000 (10:59 +0200)]
debuginfod: Always request servname from getnameinfo for conninfo.

When getting the connection info getnameinfo is called getting the
hostname and servname except when the sockaddr is a pure ipv6
address. In that last case only hostname is requested. Since servname
is stack allocated and not initialized it might contain garbage which
is then put in the log. Just always request both hostname and servname
with NI_NUMERICHOST | NI_NUMERICSERV.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agostrip: Add more NULL check
Mark Wielaard [Sun, 8 May 2022 09:00:42 +0000 (11:00 +0200)]
strip: Add more NULL check

When gelf_getshdr, gelf_getrela, gelf_getrel or gelf_getsymshndx
return NULL it is an internal error which we want to report instead of
crashing.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibdw: Add sanity check to store_implicit_value
Mark Wielaard [Mon, 9 May 2022 16:47:45 +0000 (18:47 +0200)]
libdw: Add sanity check to store_implicit_value

Don't just skip the block length, but check it is equal to the
op->number that we are going to use as length.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agodebuginfod: Check all curl_easy_setopt calls
Mark Wielaard [Mon, 9 May 2022 16:20:02 +0000 (18:20 +0200)]
debuginfod: Check all curl_easy_setopt calls

curl_easy_setup can fail for various reasons. Add a curl_easy_setopt_ck
macro to check all curl_easy_setopt calls and provides a human readable
error message in verbose mode.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agodebuginfod: Check result of curl_easy_getinfo in debuginfod_write_callback
Mark Wielaard [Mon, 9 May 2022 15:32:24 +0000 (17:32 +0200)]
debuginfod: Check result of curl_easy_getinfo in debuginfod_write_callback

This was the only place in debuginfod-client.c where we didn't check
the result of curl_easy_getinfo. Just check it to make things consistent.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoelfcompress: Add sanity checks to make sure to not override variable
Mark Wielaard [Tue, 10 May 2022 10:31:04 +0000 (12:31 +0200)]
elfcompress: Add sanity checks to make sure to not override variable

The process_file code is a little tricky. Add sanity checks to make
sure shstrtab_name, shstrtab_newname and symstrents are only set once.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoPR28577: run-debuginfod-fd-prefetch-caches.sh now tests something
Noah Sanci [Fri, 13 May 2022 14:27:29 +0000 (10:27 -0400)]
PR28577: run-debuginfod-fd-prefetch-caches.sh now tests something
run-debuginfod-fd-prefetch-caches.sh now tests the maximum fd
and mb values of prefetch and fd (least recently used) caches.

Signed-off-by: Noah Sanci <nsanci@redhat.com>
2 years agodebuginfod: Use MHD_USE_EPOLL for libmicrohttpd version 0.9.51 or higher
Mark Wielaard [Thu, 5 May 2022 22:29:28 +0000 (00:29 +0200)]
debuginfod: Use MHD_USE_EPOLL for libmicrohttpd version 0.9.51 or higher

Also disable MHD_USE_THREAD_PER_CONNECTION when using MHD_USE_EPOLL.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agodebuginfod: Try without MHD_USE_DUAL_STACK if MHD_start_daemon fails
Mark Wielaard [Thu, 5 May 2022 21:59:57 +0000 (23:59 +0200)]
debuginfod: Try without MHD_USE_DUAL_STACK if MHD_start_daemon fails

On a systems that have ipv6 disabled debuginfod doesn't start up
anymore because libhttpd MHD_USE_DUAL_STACK only works if it can
open an ipv6 socket. If MHD_start_daemon with MHD_USE_DUAL_STACK
fails try again without that flag set.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agodebuginfod.8: Tweak wording of fdcache operation & parameters.
Frank Ch. Eigler [Mon, 9 May 2022 23:26:07 +0000 (19:26 -0400)]
debuginfod.8: Tweak wording of fdcache operation & parameters.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2 years agoPR29098: debuginfod - set default prefetch cache size to >0
Noah Sanci [Mon, 9 May 2022 17:15:04 +0000 (13:15 -0400)]
PR29098: debuginfod - set default prefetch cache size to >0

Added default value to fdcache_prefetch_mds and fdcache_prefetch_fds.
Defaults to one half of corresponging fdcache's values.

Signed-off-by: Noah Sanci <nsanci@redhat.com>
foo

2 years agoPR29117: fix fd leak in debuginfod client for cache-miss files
Frank Ch. Eigler [Wed, 4 May 2022 14:26:42 +0000 (10:26 -0400)]
PR29117: fix fd leak in debuginfod client for cache-miss files

Correct a nasty fd leak and a few less nasty leaks in the debuginfod
client code.  The nasty one impacts long-lived apps such as debuginfod
servers.

Signed-off-by: Mark Wielaard <mark@klomp.org>
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2 years agoconfig: Move the 2>/dev/null inside the sh -c '' quotes for profile.csh.
Mark Wielaard [Tue, 3 May 2022 15:48:55 +0000 (17:48 +0200)]
config: Move the 2>/dev/null inside the sh -c '' quotes for profile.csh.

csh/tcsh would warn about "Ambiguous output redirect" if not done inside
the sh -c command.

Fix-by: наб <nabijaczleweli@nabijaczleweli.xyz>
https://bugzilla.redhat.com/show_bug.cgi?id=2080957

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoconfigure: Don't use valgrind and sanitize-undefined for make distcheck
Mark Wielaard [Mon, 2 May 2022 23:35:53 +0000 (01:35 +0200)]
configure: Don't use valgrind and sanitize-undefined for make distcheck

make distcheck would always run with --enable-valgrind and
--enable-sanitize-undefined. Assuming the maintainer would run this just
before doing a release. But this makes distcheck really, really, really
slow. And we have various buildbots now that run various combinations
of valgrind, undefined and/or address sanitizer over every commit now.

This make make distcheck "fast" again.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoPrepare for 0.187 elfutils-0.187
Mark Wielaard [Mon, 25 Apr 2022 16:27:33 +0000 (18:27 +0200)]
Prepare for 0.187

Set version to 0.187
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>
2 years agodebuginfod: ensure X-DEBUGINFOD-SIZE contains file size
Aaron Merey [Mon, 25 Apr 2022 15:10:46 +0000 (11:10 -0400)]
debuginfod: ensure X-DEBUGINFOD-SIZE contains file size

For archived files X-DEBUGINFOD-SIZE currently contains the size of the
archive instead of the size of the uncompressed file.  Fix this.

Also add testcases to verify X-DEBUGINFOD-SIZE contains uncompressed
file sizes.

Signed-off-by: Aaron Merey <amerey@redhat.com>
2 years agodebuginfod: Use the debuginfod-size response header
Aaron Merey [Wed, 12 Jan 2022 03:07:55 +0000 (22:07 -0500)]
debuginfod: Use the debuginfod-size response header

In some cases the content-length header may not be available in order
to pass to a progressfn.  If content-length isn't available then attempt
to get the size of the download from the debuginfod-size header instead.

It should be mentioned that if a compressed file (ex. gzip) is being
transferred, the actual transfer length will be less than debuginfod-size.
In this case debuginfod-size is a best-guess upper bound on the size of
the transfer.

Signed-off-by: Aaron Merey <amerey@redhat.com>
2 years agodebuginfod, libdwfl: Initialize libcurl and dlopen debuginfod-client lazily
Mark Wielaard [Fri, 22 Apr 2022 21:36:30 +0000 (23:36 +0200)]
debuginfod, libdwfl: Initialize libcurl and dlopen debuginfod-client lazily

We used to go out of our way to initialize libcurl early before any other
thread/code was running. But this meant that we might pay startup cost,
which under FIPS is significant, even for code that never uses libdebuginfod
or TLS libcurl connections. Although curl_global_init itself isn't thread-safe
we can use pthread_once to make sure we don't race against ourselves. This
still means we might race against any application code that might use
libcurl. But we can assume they will have called curl_global_init before
calling dwfl_begin or debuginfod_begin.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoAUTHORS: Use generator script & git mailmap
Frank Ch. Eigler [Sun, 24 Apr 2022 23:39:47 +0000 (19:39 -0400)]
AUTHORS: Use generator script & git mailmap

We can compute a pretty complete list of contributors.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2 years agolibelf: Check for mremap, elf_update needs it for ELF_C_RDWR_MMAP
Mark Wielaard [Sun, 24 Apr 2022 17:42:29 +0000 (19:42 +0200)]
libelf: Check for mremap, elf_update needs it for ELF_C_RDWR_MMAP

Add a AC_CHECK_FUNCS configure check for mremap. Some systems like
KFreeBSD and the Hurd don't have it. Also add a configure warning
because without mremap elf_update will often fail when ELF_C_RDWR_MMAP
is used. ELF_C_RDWR_MMAP is an elfutils extension to libelf.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoelfclassify: Fix --no-stdin flag
Mark Wielaard [Sun, 24 Apr 2022 15:48:39 +0000 (17:48 +0200)]
elfclassify: Fix --no-stdin flag

The no-stdin option was using the wrong flag, classify_flag_stdin,
instead of classify_flag_no_stdin.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agodebuginfod: Use MHD_USE_ITC in MHD_start_daemon flags
Mark Wielaard [Sun, 24 Apr 2022 10:16:58 +0000 (12:16 +0200)]
debuginfod: Use MHD_USE_ITC in MHD_start_daemon flags

This prevents the "Server reached connection limit. Closing inbound
connection." issue we have been seeing in the
run-debuginfod-webapi-concurrency.sh testcase. From the manual:

    If the connection limit is reached, MHD’s behavior depends a bit
    on other options. If MHD_USE_ITC was given, MHD will stop
    accepting connections on the listen socket. This will cause the
    operating system to queue connections (up to the listen() limit)
    above the connection limit. Those connections will be held until
    MHD is done processing at least one of the active connections. If
    MHD_USE_ITC is not set, then MHD will continue to accept() and
    immediately close() these connections.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agotests: Lower parallel lookups in run-debuginfod-webapi-concurrency.sh
Mark Wielaard [Sat, 23 Apr 2022 01:20:17 +0000 (03:20 +0200)]
tests: Lower parallel lookups in run-debuginfod-webapi-concurrency.sh

With 100 parallel lookups we sometimes see:
Server reached connection limit. Closing inbound connection.

Lower parallel lookups to 64

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoconfig: simplify profile.*sh.in
наб via Elfutils-devel [Wed, 19 Jan 2022 12:31:35 +0000 (13:31 +0100)]
config: simplify profile.*sh.in

1. Simplify needless sh -c "cat glob 2>/dev/null"
   into cat glob 2>/dev/null under sh
   and fix re-expansion/-e protection under csh
2. Use $( instead of ` under sh
3. Assign to DEBUGINFOD_URLS directly and either export it or unset it

Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
2 years agoreadelf: Define dyn_mem outside the while loop.
Mark Wielaard [Tue, 19 Apr 2022 09:25:42 +0000 (11:25 +0200)]
readelf: Define dyn_mem outside the while loop.

The GCC address sanitizer might complain otherwise:
stack-use-after-scope src/readelf.c:1787 in get_dyn_ents

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoreadelf: Don't consider padding DT_NULL as dynamic section entry
Di Chen [Tue, 1 Mar 2022 12:44:38 +0000 (20:44 +0800)]
readelf: Don't consider padding DT_NULL as dynamic section entry

when using `$ eu-readelf -d {FILE}` to get the number of dynamic
section entris, it wrongly counts the padding DT_NULLs as dynamic
section entries. However, DT_NULL Marks end of dynamic section.
They should not be considered as dynamic section entries.

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

Signed-off-by: Di Chen <dichen@redhat.com>
2 years agolibdw: Remove unused atomics.h include from libdwP.h
Mark Wielaard [Sun, 17 Apr 2022 02:35:44 +0000 (04:35 +0200)]
libdw: Remove unused atomics.h include from libdwP.h

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agotests: Don't try to corrupt sqlite database during test.
Mark Wielaard [Thu, 14 Apr 2022 11:26:57 +0000 (13:26 +0200)]
tests: Don't try to corrupt sqlite database during test.

In run-debuginfod-federation-sqlite.sh we used to try to corrupt
the sqlite database while the debuginfod server was running and
check it detected errors, but that was unreliably and slightly
dangerous since part of the database was already mapped into memory.
Instead trigger some some random activity, then trigger a shutdown.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoPR29022: 000-permissions files cause problems for backups
Aaron Merey [Fri, 8 Apr 2022 23:37:11 +0000 (19:37 -0400)]
PR29022: 000-permissions files cause problems for backups

000-permission files currently used for negative caching can cause
permission problems for some backup software and disk usage checkers.
Fix this by using empty files for negative caching instead.

Also use each empty file's mtime to determine the time since
last download attempt instead of the cache_miss_s file's mtime.

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

Tested-by: Milian Wolff <mail@milianw.de>
Signed-off-by: Aaron Merey <amerey@redhat.com>
2 years agolibdw: Add DWARF5 package file section identifiers, DW_SECT_*
Mark Wielaard [Wed, 13 Apr 2022 15:23:57 +0000 (17:23 +0200)]
libdw: Add DWARF5 package file section identifiers, DW_SECT_*

This only adds the constants. There is no handling of DWARF
package file (dwp) files for now.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoconfig: Add versioned requires on libs/libelf for debuginfod-client
Mark Wielaard [Thu, 7 Apr 2022 13:16:41 +0000 (15:16 +0200)]
config: Add versioned requires on libs/libelf for debuginfod-client

elfutils-debuginfod-client contains the debuginfod-client binary
which is uses libelf and libdw. Add explicit versioned requires
on elfutils-libs and elfutils-libelf so they will always be in sync
like done with all other inter sub package dependencies.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agodebuginfod: Include "IPv4 IPv6" in server startup message
Aaron Merey [Wed, 6 Apr 2022 17:38:04 +0000 (13:38 -0400)]
debuginfod: Include "IPv4 IPv6" in server startup message

At startup debuginfod prints a message indicating the port which the
server is listening to.  Prior to commit 4e4082be03 this message would
include "IPv4" and/or "IPv6"

    [...] (48671/48671): started http server on IPv4 IPv6 port=8002

As of commit 4e4082be03 the IP versions have been removed from this
message.  This change can cause issues in any applications that
parse the message for this information.  Fix this by adding
"IPv4 IPv6" back to the message.

Signed-off-by: Aaron Merey <amerey@redhat.com>
2 years agolibelf: Return already gotten Elf_Data from elf_getdata_rawchunk
Mark Wielaard [Fri, 1 Apr 2022 10:19:20 +0000 (12:19 +0200)]
libelf: Return already gotten Elf_Data from elf_getdata_rawchunk

elf_getdata_rawchunk keeps a list of Elf_Data_Chunk to track which
Elf_Data structures have already been requested. This allows elf_end
to clean up all internal data structures and the Elf_Data d_buf if
it was malloced.

But it didn't check if a chunk was already requested earlier. This
meant that if for example dwelf_elf_gnu_build_id was called multiple
times to lookup a build-id from the phdrs a new Elf_Data_Chunk was
created. This could slowly leak memory.

So also keep track of the offset from which the size and type of
the rawdata was requested so we can return existing data if it is
requested multiple times.

Note that the current cache is a simple linked list but the chain
is normally not that long. It is normally used to get chunks from
the phdrs, and there are normally less than 10.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agodebuginfod: use single ipv4+ipv6 microhttpd daemon configuration
Frank Ch. Eigler [Sun, 3 Apr 2022 23:42:48 +0000 (19:42 -0400)]
debuginfod: use single ipv4+ipv6 microhttpd daemon configuration

Use a single MHD_USE_DUAL_STACK mhd daemon.  This way, the thread
connection pool is not doubled, saving memory and better matching user
expectations.  A slight tweak to logging is required to pull IPv4
remote addresses back out, and also to allow IPv6 ::-laden address
forwarding through federation links.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2 years agoPR28708: debuginfod: use MHD_USE_EPOLL for microhttpd threads
Frank Ch. Eigler [Sun, 3 Apr 2022 16:47:17 +0000 (12:47 -0400)]
PR28708: debuginfod: use MHD_USE_EPOLL for microhttpd threads

Testing on s390x and other architectures indicates that this
configuration reduces thundering-herd wakeups and saturation of a
small number of threads.  The run-debuginfod-webapi-concurrency.sh
test appears solid now.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
2 years agolibelf: Also copy/convert partial datastructures in xlate functions
Mark Wielaard [Tue, 29 Mar 2022 22:17:08 +0000 (00:17 +0200)]
libelf: Also copy/convert partial datastructures in xlate functions

The generated xlate functions can only convert full datastructures,
dropping any trailing partial data on the floor. That means some of
the data might be undefined. Just copy over the trailing bytes as
is. That data isn't really usable. But at least it is defined data.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoIntroduce error_exit as a noreturn variant of error (EXIT_FAILURE, ...)
Mark Wielaard [Sun, 27 Mar 2022 19:08:36 +0000 (21:08 +0200)]
Introduce error_exit as a noreturn variant of error (EXIT_FAILURE, ...)

error (EXIT_FAILURE, ...) should be noreturn but on some systems it
isn't.  This may cause warnings about code that should not be
reachable.  So have an explicit error_exit wrapper that is noreturn
(because it calls exit explicitly).  Use error_exit in all tools under
the src directory.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoelflint: Recognize NT_FDO_PACKAGING_METADATA
Mark Wielaard [Thu, 24 Mar 2022 23:00:47 +0000 (00:00 +0100)]
elflint: Recognize NT_FDO_PACKAGING_METADATA

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibebl: recognize FDO Packaging Metadata ELF note
Luca Boccassi [Sun, 21 Nov 2021 19:43:18 +0000 (19:43 +0000)]
libebl: recognize FDO Packaging Metadata ELF note

As defined on: https://systemd.io/COREDUMP_PACKAGE_METADATA/
this note will be used starting from Fedora 36. Allow
readelf --notes to pretty print it:

Note section [ 3] '.note.package' of 76 bytes at offset 0x2e8:
  Owner          Data size  Type
  FDO                   57  FDO_PACKAGING_METADATA
    Packaging Metadata: {"type":"deb","name":"fsverity-utils","version":"1.3-1"}

Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
2 years agolibelf: Sync elf.h from glibc.
Mark Wielaard [Thu, 24 Mar 2022 22:06:09 +0000 (23:06 +0100)]
libelf: Sync elf.h from glibc.

Adds EM_INTELGT, NT_ARM_TAGGED_ADDR_CTRL, NT_ARM_PAC_ENABLED_KEYS,
ELF_NOTE_FDO, NT_FDO_PACKAGING_METADATA and OpenRISC 1000 specific
relocs.

It also adds and renames some GNU_PROPERTY constants. But none of the
constants the elfutils code uses was renamed or given a different
constant value.

dwelf_elf_e_machine_string was updated to handle EM_INTELGT.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoconfigure: Don't check whether -m64 works for 32bit host biarch check
Mark Wielaard [Sun, 20 Mar 2022 23:34:24 +0000 (00:34 +0100)]
configure: Don't check whether -m64 works for 32bit host biarch check

Running a 32bit backtrace test against a 64bit binary doesn't work.
Only a 64bit binary can backtrace a 32bit binary. So disable the
biarch check that inserts -m64 for a 32bit host.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agotests: Check addsections test binary is 64bit for run-large-elf-file.sh
Mark Wielaard [Sun, 20 Mar 2022 23:13:56 +0000 (00:13 +0100)]
tests: Check addsections test binary is 64bit for run-large-elf-file.sh

The test binary should be 64bit to be able to create 4GB, or larger,
ELF files.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibelf: Correct alignment of ELF_T_GNUHASH data for ELFCLASS64
Mark Wielaard [Wed, 23 Mar 2022 00:20:56 +0000 (01:20 +0100)]
libelf: Correct alignment of ELF_T_GNUHASH data for ELFCLASS64

ELF_T_GNUHASH data is just 32bit words for ELFCLASS32. But for
ELFCLASS64 it is a mix of 32bit and 64bit words. In the
elf_cvt_gnuhash function we rely on the alignment of the whole to be
64bit word aligned, even though the first 4 words are
32bits. Otherwise we might try to convert an unaligned 64bit word.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibelf: Don't overflow offsets in elf_cvt_Verneed and elf_cvt_Verdef
Mark Wielaard [Sun, 20 Mar 2022 21:21:05 +0000 (22:21 +0100)]
libelf: Don't overflow offsets in elf_cvt_Verneed and elf_cvt_Verdef

The conversion functions for Verdef and Verneed keep offsets to the next
structure. Make sure that following vd_aux, vda_next, vd_next, vn_aux,
vna_next and vn_next don't overflow (and wrap around) the offsets.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibdwfl: Use memcpy to assign image header field values
Mark Wielaard [Fri, 18 Mar 2022 15:44:53 +0000 (16:44 +0100)]
libdwfl: Use memcpy to assign image header field values

The values in the kernel image header aren't properly aligned.
Use memcpy and the LE16, LE32 macros to assign and check the
values.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibdwfl: Close ar members when they cannot be processed.
Mark Wielaard [Fri, 18 Mar 2022 15:01:20 +0000 (16:01 +0100)]
libdwfl: Close ar members when they cannot be processed.

When reporting ar members they should be closed when they cannot
be processed. A comment in offline.c said that process_file called
elf_end if it returned NULL. But this is incorrect. And other places
that call process_file do call elf_end explicitly when it returns
NULL.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibelf: Check alignment of Verdef, Verdaux, Verneed and Vernaux offsets
Mark Wielaard [Thu, 17 Mar 2022 23:59:38 +0000 (00:59 +0100)]
libelf: Check alignment of Verdef, Verdaux, Verneed and Vernaux offsets

The Verdef, Verdaux, Verneed and Vernaux structures contain fields
which point to the next structures. Make sure these offsets are
correctly aligned for the structures they point to.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibelf: Make sure ar_size starts with a digit before calling atol.
Mark Wielaard [Thu, 17 Mar 2022 13:03:06 +0000 (14:03 +0100)]
libelf: Make sure ar_size starts with a digit before calling atol.

The ar_size field is a 10 character string, not zero terminated, of
decimal digits right padded with spaces.  Make sure it actually starts
with a digit before calling atol on it.  We already make sure it is
zero terminated. Otherwise atol might produce unexpected results.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibelf: Take map offset into account for Shdr alignment check in elf_begin
Mark Wielaard [Thu, 17 Mar 2022 12:58:56 +0000 (13:58 +0100)]
libelf: Take map offset into account for Shdr alignment check in elf_begin

The sh_num function tries to get at the zero section Shdr directly.
When the file is mmapped it has to make sure the offset into the file
to the start of the Elf structure is taken into account when trying to
cast the address to make sure the alignment is correct.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoconfigure: Use AS_HELP_STRING instead of AC_HELP_STRING.
Mark Wielaard [Mon, 14 Mar 2022 12:13:34 +0000 (13:13 +0100)]
configure: Use AS_HELP_STRING instead of AC_HELP_STRING.

In most places we already used AS_HELP_STRING. A few places used
AC_HELP_STRING. Which has been deprecated for a long time. Use
AS_HELP_STRING instead of AC_HELP_STRING everywhere.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoaddr2line: Make --absolute the default, add --relative option.
Mark Wielaard [Fri, 11 Mar 2022 14:44:21 +0000 (15:44 +0100)]
addr2line: Make --absolute the default, add --relative option.

Make --absolute (including the compilation directory in file names)
the default and add a new option --relative to get the previous
default behavior.

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

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