]> git.ipfire.org Git - thirdparty/elfutils.git/log
thirdparty/elfutils.git
4 weeks agoima testing: switch 'pem' mode for koji subtest, allow dist/distcheck users/fche/try-bz28204
Frank Ch. Eigler [Sat, 30 Mar 2024 17:42:49 +0000 (13:42 -0400)] 
ima testing: switch 'pem' mode for koji subtest, allow dist/distcheck

4 weeks agoENABLE_IMA_VERIFICATION-undef case tweak
Frank Ch. Eigler [Sat, 30 Mar 2024 17:18:19 +0000 (13:18 -0400)] 
ENABLE_IMA_VERIFICATION-undef case tweak

4 weeks agopr28204 - rework sans libimaevm library
Frank Ch. Eigler [Sat, 30 Mar 2024 17:04:14 +0000 (13:04 -0400)] 
pr28204 - rework sans libimaevm library

Use only imaevm.h for a few struct decls, and openssl functions
directly.  Simplifies code and corrects some concurrency concerns.

5 months agoreview response: drop debuginfod/ima-certs/
Frank Ch. Eigler [Fri, 17 Nov 2023 16:26:53 +0000 (11:26 -0500)] 
review response: drop debuginfod/ima-certs/

5 months agoreview comments cont'd: become less optimistic
Frank Ch. Eigler [Fri, 17 Nov 2023 16:18:35 +0000 (11:18 -0500)] 
review comments cont'd: become less optimistic

5 months agoresponse to review comments cont'd
Frank Ch. Eigler [Fri, 17 Nov 2023 15:37:37 +0000 (10:37 -0500)] 
response to review comments cont'd

6 months agoPR28204 debuginfod-client review changes
Frank Ch. Eigler [Tue, 31 Oct 2023 13:15:58 +0000 (09:15 -0400)] 
PR28204 debuginfod-client review changes

- rename "permissive" to "optimistic" throughout

6 months agoPR28204 debuginfod-client review changes
Frank Ch. Eigler [Tue, 31 Oct 2023 00:43:31 +0000 (20:43 -0400)] 
PR28204 debuginfod-client review changes

- libimaevm functions bracketed by pthread mutex
- libimaevm init_public_keys called once per cert per session, independent of keyid
- thus keyid doesn't need funky foo+1 pointer-arithmetic extraction code
- strtok -> strtok_r
- a strdup memory leak fixed
- section queries disabled in ima:enforcing mode
- additional backup temporary-file cleanup

7 months agodebuginfod: PR28204 - RPM IMA per-file signature verification
Ryan Goldberg [Mon, 14 Aug 2023 17:51:00 +0000 (13:51 -0400)] 
debuginfod: PR28204 - RPM IMA per-file signature verification

Recent versions of Fedora/RHEL include per-file cryptographic
signatures in RPMs, not just an overall RPM signature.  This work
extends debuginfod client & server to extract, transfer, and verify
those signatures.  These allow clients to assure users that the
downloaded files have not been corrupted since their original
packaging.  Downloads that fail the test are rejected.

Clients may select a desired level of enforcement for sets of URLs in
the DEBUGINFOD_URLS by inserting special markers ahead of them:

ima:ignore       pay no attention to absence or presence of signatures
ima:permissive   require signatures to be correct, but accept absent signatures
ima:enforcing    require every file to be correctly signed

The default is ima:permissive mode, which allows signatures to
function like a checksum to detect accidental corruption, but accepts
operation in a mix of signed and unsigned packages & servers.

NB: debuginfod section queries are excluded from signature
verification at this time, and function as though ima:ignore were in
effect.

IMA signatures are verified against a set of signing certificates.
These are normally published by distributions.  A selection of such
certificates is included with the debuginfod client, but some system
directories are also searched.  See $DEBUGINFOD_IMA_CERT_PATH.  These
certificates are assumed trusted.

Signed-off-by: Ryan Goldberg <rgoldber@redhat.com>
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
7 months agotests: Fix system_elf_gelf_test build without system libelf.h
Mark Wielaard [Sun, 3 Sep 2023 16:25:56 +0000 (18:25 +0200)] 
tests: Fix system_elf_gelf_test build without system libelf.h

If there is no system libelf.h then the building of system-elf-gelf-test
fails with:

../libelf/gelf.h:32:10: fatal error: libelf.h: No such file or directory

This is because although the testcase includes the headers as
../libelf/libelf.h and ../libelf/gelf.h, gelf.h itself does an

Fix this by putting a copy of libelf.h in the build test directory
and using -I. for building system-elf-gelf-test.

* tests/Makefile.am (BUILT_SOURCES): New for libelf.h.
(CLEANFILES): Add libelf.h.
(libelf.h): New target that copies srdir libelf.h.
(system_elf_gelf_test_CPPFLAGS): Add -I.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
8 months agoPR30809: improve debuginfod client progress-callback parameters
Frank Ch. Eigler [Tue, 29 Aug 2023 18:08:04 +0000 (14:08 -0400)] 
PR30809: improve debuginfod client progress-callback parameters

* debuginfod-client.c (debuginfod_query_server): Use fstat(3)
  of the file handle being downloaded into as the preferred
  source of download progress.

Tested by hand, as the testsuite doesn't have enough machinery to
simulate compressed vs. uncompressed service.  Hand testing with
(unmodified) fedora-38 gdb and debuginfod-find shows dramatically
improved progress displays: all have quantitative figures when
fetching from real (unmodified) upstream servers.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
8 months agobackends: Update list of LoongArch relocations
Xi Ruoyao [Tue, 29 Aug 2023 13:14:22 +0000 (21:14 +0800)] 
backends: Update list of LoongArch relocations

* backends/loongarch_reloc.def: Add DELETE, ALIGN, PCREL20_S2,
CFA, ADD6, SUB6, ADD_ULEB128, SUB_ULEB128, 64_PCREL.

Signed-off-by: Xi Ruoyao <xry111@xry111.site>
8 months agolibelf: Sync elf.h from Glibc
Xi Ruoyao [Tue, 29 Aug 2023 13:14:21 +0000 (21:14 +0800)] 
libelf: Sync elf.h from Glibc

Adds new LoongArch relocations.

* elf.h: Update from glibc.

Signed-off-by: Xi Ruoyao <xry111@xry111.site>
8 months agolibelf, readelf, elflint: Add RELR support
Mark Wielaard [Sun, 23 Jul 2023 21:14:31 +0000 (23:14 +0200)] 
libelf, readelf, elflint: Add RELR support

Handle RELR as defined here:
https://groups.google.com/g/generic-abi/c/bX460iggiKg/m/YT2RrjpMAwAJ

Introduce new ELF_T_RELR Elf_Type and handle it for SHT_RELR.  Check
various properties in elflint.  Print RELR relocations in
readelf. Just the entries with -U.  Just the addresses with -N. And
addresses plus symbol/offsets by default.

Also add a test to check that gelf.h works with the system elf.h.

* libebl/eblsectiontypename.c (ebl_section_type_name): Add RELR
to knownstype.
* libelf/elf32_updatenull.c (updatenull_wrlock): Handle
sh_entsize for SHT_RELR.
* libelf/gelf.h (GElf_Relr): New typedef for Elf64_Relr.
* libelf/gelf_fsize.c (__libelf_type_sizes): Add ELF_T_RELR.
* libelf/gelf_xlate.c (__elf_xfctstom): Likewise.
* libelf/gelf_xlate.h: Add RELR as FUNDAMENTAL.
* libelf/libelf.h (Elf_Type): Add ELF_T_RELR. Add RELR
defines/typedefs if undefined in system elf.h.
* libelf/libelfP.h: Define ELF32_FSZ_RELR and ELF64_FSZ_RELR.
* src/elflint.c (check_reloc_shdr): Check she_entsize for
ELF_T_RELR.
(check_relr): New function.
(check_dynamic): Handle DT_RELR.
(special_sections): Add SHT_RELR.
(check_sections): Call check_relr.
* src/readelf.c (print_relocs): Also accept a Dwfl_Module.
(handle_relocs_relr): New function.
(print_dwarf_addr): Make static and declare early.
(process_elf_file): Pass dwflmod to print_relocs.
(handle_dynamic): Handle DT_RELRSZ and DTRELRENT.
* system-elf-gelf-test.c: New test.
* Makefile.am (TESTS): Add system-elf-gelf-test.
(check_PROGRAMS): Likewise.
(system_elf_gelf_test_CPPFLAGS): New variable.
(system_elf_gelf_test_LDADD): Likewise.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
8 months agolibelf: Remove elf_scncnt from libelf.map
Mark Wielaard [Mon, 28 Aug 2023 18:23:41 +0000 (20:23 +0200)] 
libelf: Remove elf_scncnt from libelf.map

elf_scncnt was never implemented. It was probably an old name for
elf_getshnum (which was the deprecated name of the elf_getshdrnum
alias). Just remove it from the map file

* libelf/libelf.map (ELFUTILS_1.0): Remove elf_scncnt.

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

Reported-by: Kostadin Shishmanov <kocelfc@tutanota.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
8 months agolibelf: Free and clear rawdata_base and zdata_base consistently
Mark Wielaard [Sun, 30 Jul 2023 15:28:00 +0000 (17:28 +0200)] 
libelf: Free and clear rawdata_base and zdata_base consistently

There could be a leak if a program called elf_strptr on a compressed
section, but the program never requests the (uncompressed) section data,
but does explicitly (re)compress that same section data.

Fix this by explicitly always freeing and clearing the zdata_base
and rawdata_base in __libelf_reset_rawdata and elf_compress. Also
clear zdata_base in elf_end so the pointer isn't indeterminate when
it is being used in a later comparison against rawdata_base.

* libelf/elf_compress.c (elf_compress): Explicitly free
zdata_base before clearing.
(__libelf_reset_rawdata): Free zdata_base if it isn't
(going to be) used for rawdata_base. Explicitly clear
rawdata_base and zdata_base after free.
* libelf/elf_end.c (elf_end): Clear zdata_base after free.

Signed-off-by: Mark Wielaard <mark@klomp.org>
9 months agotests: run-lfs-symbols.sh needs gawk
Sam James [Wed, 19 Jul 2023 23:16:38 +0000 (00:16 +0100)] 
tests: run-lfs-symbols.sh needs gawk

With awk=mawk, I get:
```
FAIL: run-lfs-symbols.sh
========================

First sanity-check that LFS detection works.
checking ./testfile-nolfs
awk: line 3: syntax error at or near /
FAIL run-lfs-symbols.sh (exit status: 2)
```

* tests/run-lfs-symbols.sh: Call 'gawk' instead of 'awk'.

Signed-off-by: Sam James <sam@gentoo.org>
9 months agoSECURITY: new file
Frank Ch. Eigler [Mon, 3 Jul 2023 14:19:23 +0000 (10:19 -0400)] 
SECURITY: new file

Policy drafted in April 2023.

https://inbox.sourceware.org/elfutils-devel/20230407005600.GB10746@redhat.com/

Added links to README, and mentioned in configury/spec files for installation.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
10 months agolibelf: Replace list of elf_getdata_rawchunk results with a tree
Mark Wielaard [Wed, 21 Jun 2023 16:05:12 +0000 (18:05 +0200)] 
libelf: Replace list of elf_getdata_rawchunk results with a tree

elf_getdata_rawchunks did a linear search to see if a chunk was
already fetched. Replace this list with a binary search tree to make
lookup faster when a lot of Elf_Data_Chunk were created.

       * libelf/libelfP.h (Elf_Data_Chunk): Remove next field.
       (struct Elf): Change the rawchunks type from Elf_Data_Chunk *
       to void *.
       * elf_getdata_rawchunk.c (chunk_compare): New static function.
       (elf_getdata_rawchunk): Use tsearch instead of a manual linked
       list.
       * elf_end.c (free_chunk): New static function.
       (elf_end): Call tdestroy instead of walking linked list.

Signed-off-by: Mark Wielaard <mark@klomp.org>
10 months agobackends: Update list of RISC-V relocations
Andreas Schwab [Mon, 26 Jun 2023 14:32:13 +0000 (16:32 +0200)] 
backends: Update list of RISC-V relocations

* backends/riscv_reloc.def: Add IRELATIVE, PLT32, SET_ULEB128,
SUB_ULEB128.

Signed-off-by: Andreas Schwab <schwab@suse.de>
10 months agolibelf: Sync elf.h from glibc
Andreas Schwab [Mon, 26 Jun 2023 14:30:19 +0000 (16:30 +0200)] 
libelf: Sync elf.h from glibc

Adds new RISC-V relocations.

* elf.h: Update from glibc.

Signed-off-by: Andreas Schwab <schwab@suse.de>
10 months agodebuginfod: Fix formatting in debuginfod_config_cache
Mark Wielaard [Thu, 22 Jun 2023 12:45:56 +0000 (14:45 +0200)] 
debuginfod: Fix formatting in debuginfod_config_cache

The formatting of debuginfod_config_cache in debuginfod-client.c was
slightly off making it hard to see the program logic. Make sure lines
are < 76 chars, and if { } else { } indentation follows GNU style.

Signed-off-by: Mark Wielaard <mark@klomp.org>
10 months agotests: Use -N for run-readelf-self.sh.
Mark Wielaard [Sat, 17 Jun 2023 19:57:59 +0000 (21:57 +0200)] 
tests: Use -N for run-readelf-self.sh.

The test doesn't really need to resolve all addresses
and -N is really slow.

* tests/run-readelf-self.sh: Add -N.

Signed-off-by: Mark Wielaard <mark@klomp.org>
10 months agotests: Split up run-strip-reloc.sh test in three subtests
Mark Wielaard [Sat, 17 Jun 2023 19:37:41 +0000 (21:37 +0200)] 
tests: Split up run-strip-reloc.sh test in three subtests

This test can take a very long time under valgrind (on s390x).
Split it into three tests for kernel modules, self-test and ppc64.
That way the tests can run in parallel and each individual
test produces a result (so the buildbot won't time out).

Also change the comparison to elfcmp instead of doing
readelf -a on both and compare the textual output.

* tests/run-strip-reloc.sh: Split out generic part into...
* tests/strip-reloc-subr.sh: ...this file.
* tests/run-strip-reloc-ko.sh: New file.
* tests/run-strip-reloc-ppc64.sh: New file.
* tests/run-strip-reloc-self.sh: New file.
* tests/Makefile.am (TESTS): Remove run-strip-reloc.sh.
Add run-strip-reloc-ko.sh, run-strip-reloc-self.sh and
run-strip-reloc-ppc64.sh
(EXTRA_DIST): Remove run-strip-reloc.sh. Add
strip-reloc-subr.sh, run-strip-reloc-ko.sh,
run-strip-reloc-self.sh and run-strip-reloc-ppc64.sh.

Signed-off-by: Mark Wielaard <mark@klomp.org>
10 months agotests: Really split run-copymany-sections.sh into separate tests
Mark Wielaard [Sat, 17 Jun 2023 12:56:12 +0000 (14:56 +0200)] 
tests: Really split run-copymany-sections.sh into separate tests

The previous commit 4fac1627c "tests: Split run-copymany-sections.sh
into separate tests" duplicated the tests because they were still
also done in the new test-copymany-subr.sh. Remove them really this
time. Also don't source test-subr.sh twice, test-copymany-subr.sh
already sources it, so the subtests don't have to also do it again.

* tests/test-copymany-subr.sh: Remove actual tests.
* tests/run-copymany-be32.sh: Remove . $srcdir/test-subr.sh.
* tests/run-copymany-be64.sh: Likewise.
* tests/run-copymany-le32.sh: Likewise.
* tests/run-copymany-le64.sh: Likewise.

Signed-off-by: Mark Wielaard <mark@klomp.org>
10 months agotests: Split run-copymany-sections.sh into separate tests
Mark Wielaard [Sat, 17 Jun 2023 12:03:36 +0000 (14:03 +0200)] 
tests: Split run-copymany-sections.sh into separate tests

This test can take a very long time under valgrind (on s390x).
Split it into four tests for big/little endian, 32/64 bit.
That way the tests can run in parallel and each individual
test produces a result (so the buildbot won't time out).

* tests/run-copymany-sections.sh: Delete and move
generic part into...
* tests/test-copymany-subr.sh: ... here.
* tests/run-copymany-be32.sh: New big endian 32 bit tests.
* tests/run-copymany-be64.sh: New big endian 64 bit tests.
* tests/run-copymany-le32.sh: New little endian 32 bit tests.
* tests/run-copymany-le64.sh: New little endian 64 bit tests.
* tests/Makefile.am (TESTS): Remove run-copymany-sections.sh,
add run-copymany-be32.sh, run-copymany-le32.sh,
run-copymany-be64.sh and run-copymany-le64.sh.
(EXTRA_DIST): Remove run-copymany-sections.sh. Add
test-copymany-subr.sh, run-copymany-be32.sh,
run-copymany-le32.sh, run-copymany-be64.sh and
run-copymany-le64.sh.

Signed-off-by: Mark Wielaard <mark@klomp.org>
10 months agotests: Use readelf -N -w in run-strip-reloc.sh
Mark Wielaard [Sat, 17 Jun 2023 00:33:33 +0000 (02:33 +0200)] 
tests: Use readelf -N -w in run-strip-reloc.sh

With -N the test runs 4 times faster. And the address lookup is not
essential for the test.

* tests/run-strip-reloc.sh: Use readelf -N -w.

Signed-off-by: Mark Wielaard <mark@klomp.org>
10 months agotests: Add a bit less and slightly smaller sections for addsections
Mark Wielaard [Fri, 16 Jun 2023 23:40:38 +0000 (01:40 +0200)] 
tests: Add a bit less and slightly smaller sections for addsections

The run-copymany-sections.sh testcase adds 64K sections (twice)
to a couple of times. Each section is just 6 bytes long, but each
data section is malloced and freed. That adds up. And is especially
slow when running under valgrind.

Reduce the number of sections added to 32K (twice) and make each
section data just one single zero byte.

* tests/addsections.c (add_sections): Don't strdup and free
the string ".extra", but just add the empty string.
* tests/run-copymany-sections.sh: Call addsections with
32768 instead of 65535.

Signed-off-by: Mark Wielaard <mark@klomp.org>
10 months agodebuginfod: PR29696: enlarge run-debuginfod-federation-metrics.sh workload again
Frank Ch. Eigler [Fri, 16 Jun 2023 15:18:19 +0000 (11:18 -0400)] 
debuginfod: PR29696: enlarge run-debuginfod-federation-metrics.sh workload again

Now that the bug is fixed, we can let debuginfod have all the traffic.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
10 months agodebuginfod: PR29696: Removed secondary fd close in cache config causing a race condition
Ryan Goldberg [Fri, 16 Jun 2023 14:20:04 +0000 (10:20 -0400)] 
debuginfod: PR29696: Removed secondary fd close in cache config causing a race condition

Signed-off-by: Ryan Goldberg <rgoldber@redhat.com>
11 months agoreport_r_debug: handle `-z separate-code' and find more modules
Luke Diamand [Fri, 12 May 2023 19:11:45 +0000 (20:11 +0100)] 
report_r_debug: handle `-z separate-code' and find more modules

Looking at some cores in eu-stack, I found that they were not being
backtraced.

This was because elfutils had not found some modules (e.g. libc-2.22.so)
in report_r_debug.

That is because it has a limit on the number of link map entries it will
look at, to avoid loops in corrupted core files.

The example I found had:
- 36 elements
- 109 iterations

See also discussion here:

    https://sourceware.org/pipermail/elfutils-devel/2023q2/006149.html

Signed-off-by: Luke Diamand <ldiamand@roku.com>
11 months agoPR30316: debuginfod wal checkpointing
Frank Ch. Eigler [Mon, 8 May 2023 15:05:48 +0000 (11:05 -0400)] 
PR30316: debuginfod wal checkpointing

Add a "--scan-checkpoint=NUM" option to debuginfod to control forced
synchronization & sqlite -wal checkpointing for the multithreaded
scanning process.  In absence of this, a server that's busy with other
read & write operations can accumulate potentially large SQLITE WAL
temporary files.  This option causes the server to take intermittent
quiescent breaks during scanning, during which the -wal file can be
processed and truncated.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
11 months agodebuginfod: PR30378: better compression for _files table
Frank Ch. Eigler [Fri, 5 May 2023 17:56:23 +0000 (13:56 -0400)] 
debuginfod: PR30378: better compression for _files table

Split the _files table into two links into a new _fileparts table,
interning the dirname and basename of each file name string.  This
reduces storage requirements for many thousands of almost-identical
long paths that are evident in large builds like kernels.

This is unfortunately a schema-breaking change, so requires reindexing
of the corpus.

While in the vicinity, the file scan work queue is changed from a
<set> to an <unordered_set>.  The intent is that files be scanned in a
more random sequence instead of sorted.  If they're sorted, then files
that contain errors will tend to be retried over and over again at the
next scan cycle, even at the expense of making progress on the other
files in the queue.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
11 months agobackends: Add set_initial_registers_tid callback for LoongArch
Youling Tang [Tue, 9 May 2023 11:20:31 +0000 (19:20 +0800)] 
backends: Add set_initial_registers_tid callback for LoongArch

This patch implements the set_initial_registers_tid hook for LoongArch.

Signed-off-by: Liwei Ge <geliwei@openanolis.org>
Signed-off-by: Youling Tang <tangyouling@loongson.cn>
11 months agobackends: Add core_note callback for LoongArch
Youling Tang [Fri, 7 Apr 2023 02:59:28 +0000 (10:59 +0800)] 
backends: Add core_note callback for LoongArch

Signed-off-by: Youling Tang <tangyouling@loongson.cn>
11 months agobackends: Add frame pointer unwinding for LoongArch
Youling Tang [Fri, 7 Apr 2023 02:59:27 +0000 (10:59 +0800)] 
backends: Add frame pointer unwinding for LoongArch

If we don't find any debug information for a given frame, we usually
cannot unwind any further. However, the binary in question might have
been compiled with frame pointers, in which case we can look up the
well known frame pointer locations in the stack snapshot and use them
to bridge the frames without debug information.

Signed-off-by: Liwei Ge <geliwei@openanolis.org>
Signed-off-by: Youling Tang <tangyouling@loongson.cn>
11 months agobackends: Add initial return value location support for LoongArch
Youling Tang [Fri, 7 Apr 2023 02:59:26 +0000 (10:59 +0800)] 
backends: Add initial return value location support for LoongArch

LoongArch ELF ABI specification - Return values:
https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html#_return_values

Signed-off-by: Liwei Ge <geliwei@openanolis.org>
Signed-off-by: Youling Tang <tangyouling@loongson.cn>
11 months agobackends: Add abi_cfi and register_info callbacks for LoongArch
Youling Tang [Fri, 7 Apr 2023 02:59:24 +0000 (10:59 +0800)] 
backends: Add abi_cfi and register_info callbacks for LoongArch

LoongArch Reference Manual - Volume 1:
https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html

LoongArch ELF ABI:
https://loongson.github.io/LoongArch-Documentation/LoongArch-ELF-ABI-EN.html

Signed-off-by: Liwei Ge <geliwei@openanolis.org>
Signed-off-by: Youling Tang <tangyouling@loongson.cn>
11 months agoelfcompress: Don't compress if section already compressed unless forced
Mark Wielaard [Fri, 21 Apr 2023 23:45:43 +0000 (01:45 +0200)] 
elfcompress: Don't compress if section already compressed unless forced

Before commit a5b07cdf9 "support ZSTD compression algorithm"
elfcompress would not try to compress a section if it already
had the requested compression type (or was already uncompressed)
unless the --force flag was given. An else if construct was changed
to an if in the commit causing elfcompress to warn (in verbose mode)
but then still try to (re)compress the section.

Add an explicit check so if nothing needs (un)compressing, the file
isn't changed.

The diff looks large, but git diff -b -w is just:

+     if (force || type != schtype)
+       {
          if (shdr->sh_type != SHT_NOBITS
              && (shdr->sh_flags & SHF_ALLOC) == 0)
            {
@@ -554,6 +556,7 @@ process_file (const char *fname)
              printf ("[%zd] %s ignoring %s section\n", ndx, sname,
                      (shdr->sh_type == SHT_NOBITS ? "no bits" : "allocated"));
        }
+   }

Signed-off-by: Mark Wielaard <mark@klomp.org>
11 months agolibdwfl: Fix memory leak in unzip()
John Gallagher [Fri, 28 Apr 2023 06:04:31 +0000 (23:04 -0700)] 
libdwfl: Fix memory leak in unzip()

state.input_buffer is not freed if the file is found to not be
compressed with the compression algorithm unzip() is trying to use.

Signed-off-by: John Gallagher <john@gllghr.com>
12 months agoPR30377: fix debuginfod -r -X combination
Frank Ch. Eigler [Fri, 21 Apr 2023 21:04:08 +0000 (17:04 -0400)] 
PR30377: fix debuginfod -r -X combination

Until this fix, debuginfod -r -X '.*' didn't trigger groom-time removal
of everything, because the -I include regex overrode it.  Corrected logic
to match the scan-time tie-breaking between -I / -X.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
12 months agotestsuite: Avoid C99 compatibility issues in run-native-test.sh
Florian Weimer [Sat, 22 Apr 2023 19:37:09 +0000 (21:37 +0200)] 
testsuite: Avoid C99 compatibility issues in run-native-test.sh

Include <unistd.h> for the pause function, and add the return type
of main.  Avoids an implicit function declaration and implicit int.

Signed-off-by: Florian Weimer <fweimer@redhat.com>
12 months agoreadelf: display dynamic symtab without section headers
Di Chen [Mon, 27 Mar 2023 02:01:05 +0000 (10:01 +0800)] 
readelf: display dynamic symtab without section headers

This commit adds a new option "-D/--use-dynamic" to support printing the
dynamic symbol table from the PT_DYNAMIC segment. By using the
PT_DYNAMIC segment, eu-readelf can go through the contents of dynamic
section entries and the values of each tag. From that, we can get the
address and size of the dynamic symbol table, the address of the string
table, etc.

By using the new option "-D/--use-dynamic", eu-readelf can list the
symbols without section headers.

Example:
  $ ./src/readelf -Ds a.out
      0: 0000000000000000      0 NOTYPE  LOCAL  DEFAULT    UNDEF
      1: 0000000000000000      0 FUNC    GLOBAL DEFAULT    UNDEF __libc_start_main@GLIBC_2.34 (2)
      2: 0000000000000000      0 NOTYPE  WEAK   DEFAULT    UNDEF __gmon_start__

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

Signed-off-by: Di Chen <dichen@redhat.com>
12 months agotests: Limit the number of concurrent requests in debuginfod-federation
Mark Wielaard [Fri, 14 Apr 2023 16:10:48 +0000 (18:10 +0200)] 
tests: Limit the number of concurrent requests in debuginfod-federation

It seems doing 100 parallel requests can crash some versions of
libmicrohttpd so limit the number a little to the number of processors
times 4, with a max of 64.

      * tests/run-debuginfod-federation-metrics.sh: Use nproc * 4, or 64
      for seq curl requests.
      * tests/run-debuginfod-federation-sqlite.sh: Likewise.

Signed-off-by: Mark Wielaard <mark@klomp.org>
12 months agoreadelf: Handle NULL shdr in section_name
Mark Wielaard [Thu, 6 Apr 2023 14:58:13 +0000 (16:58 +0200)] 
readelf: Handle NULL shdr in section_name

In some error cases we want to show the section name but cannot
because the section header is corrupt or NULL. Make sure the
section_name always returns "???" in that case.

* src/readelf.c (section_name): Check for shdr == NULL.

Signed-off-by: Mark Wielaard <mark@klomp.org>
12 months agobackends: Check results for NULL early in dwarf_peeled_die_type
Mark Wielaard [Thu, 6 Apr 2023 14:49:27 +0000 (16:49 +0200)] 
backends: Check results for NULL early in dwarf_peeled_die_type

Calling dwarf_peeled_die_type with a NULL results pointer is an error,
check early that result is not NULL so dwarf_formref_die and
dwarf_peel_type won't try to set the NULL Dwarf_Die.

* backends/libebl_CPU.h (dwarf_peeled_die_type): Move check
        for results == NULL to start of function.

Signed-off-by: Mark Wielaard <mark@klomp.org>
12 months agoPR30348: debuginfod: retry partial archive scans
Frank Ch. Eigler [Thu, 13 Apr 2023 17:11:56 +0000 (13:11 -0400)] 
PR30348: debuginfod: retry partial archive scans

On some public debuginfod servers, it was observed that errors
may occur during individual archive scanning operations.  That's
fine, but previous code still went ahead and marked the archive
"done" by inserting a record into the *_file_mtime_scanned table.

New code ensures that exceptions propagate for these cases, and an
archive that encountered an error while scanning will be retried
later.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
12 months agobackends: add checks for _GLOBAL_OFFSET_TABLE_ on loongarch
Youling Tang [Sat, 1 Apr 2023 03:18:53 +0000 (11:18 +0800)] 
backends: add checks for _GLOBAL_OFFSET_TABLE_ on loongarch

Add handling of _GLOBAL_OFFSET_TABLE_.

Before applying the patch:
$ ./src/elflint --gnu-ld ./src/elflint
section [35] '.symtab': _GLOBAL_OFFSET_TABLE_ symbol value 0x68548
does not match .got.plt section address 0x68238

After applying the patch:
$ ./src/elflint --gnu-ld ./src/elflint
No errors

Signed-off-by: Liwei Ge <geliwei@openanolis.org>
Signed-off-by: Youling Tang <tangyouling@loongson.cn>
12 months agobackends: Add new relocation type handling for LoongArch
Youling Tang [Sat, 1 Apr 2023 06:43:44 +0000 (14:43 +0800)] 
backends: Add new relocation type handling for LoongArch

Add new relocation type handling.

Signed-off-by: Youling Tang <tangyouling@loongson.cn>
12 months agolibelf: Sync elf.h from glibc.
Youling Tang [Sat, 1 Apr 2023 06:43:43 +0000 (14:43 +0800)] 
libelf: Sync elf.h from glibc.

Adds R_LARCH_*.

Signed-off-by: Youling Tang <tangyouling@loongson.cn>
13 months agodebuginfod: When retrieving files from cache, update atime manually
Jan Alexander Steffens (heftig) [Fri, 24 Mar 2023 00:48:05 +0000 (01:48 +0100)] 
debuginfod: When retrieving files from cache, update atime manually

The cache cleaning logic requires atime to be correct (strictatime or
relatime) but some users on Linux only have noatime.

Attempt to update the atime manually so that the cache works properly.

Signed-off-by: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
13 months agodebuginfod: Don't touch access time of new files
Jan Alexander Steffens (heftig) [Fri, 24 Mar 2023 00:48:04 +0000 (01:48 +0100)] 
debuginfod: Don't touch access time of new files

Instead of copying the mtime, which might be far in the past, don't
touch the access time. This will prevent cache cleaning from considering
the file as old immediately.

Signed-off-by: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
13 months agodebuginfod-client.c: Avoid sscanf on mixed-case component of string
Aaron Merey [Thu, 30 Mar 2023 18:11:23 +0000 (14:11 -0400)] 
debuginfod-client.c: Avoid sscanf on mixed-case component of string

sscanf is used to get the value of x-debuginfod-size from the http
headers.  The format string used assumes that the header field name
is entirely lower case.  However mixed-case field names are possible,
resulting in the value not being read.

Fix this by removing "x-debuginfod-size" from the format string.

Signed-off-by: Aaron Merey <amerey@redhat.com>
13 months agonuke a top-level ChangeLog blurb that duplicated the debuginfod/ChangeLog
Frank Ch. Eigler [Wed, 29 Mar 2023 20:48:15 +0000 (16:48 -0400)] 
nuke a top-level ChangeLog blurb that duplicated the debuginfod/ChangeLog

13 months agodebuginfod: Replace futimes with futimens
Jan Alexander Steffens (heftig) [Fri, 24 Mar 2023 00:48:03 +0000 (01:48 +0100)] 
debuginfod: Replace futimes with futimens

Similar to what 8c4aa0ef998191ed828a37190dc179b91649938a did for ar and
strip, replace the non-standard futimes with the POSIX futimens.

Signed-off-by: Jan Alexander Steffens (heftig) <heftig@archlinux.org>
13 months agodebuginfod-client.c: Fix download size not correctly fallbacks to x-debuginfod-size...
lilydjwg [Wed, 29 Mar 2023 15:02:36 +0000 (23:02 +0800)] 
debuginfod-client.c: Fix download size not correctly fallbacks to x-debuginfod-size header

Signed-off-by: lilydjwg <lilydjwg@gmail.com>
13 months agoLoongArch: implemented a basic machine flag check
Alexey Sheplyakov [Mon, 20 Mar 2023 14:45:02 +0000 (18:45 +0400)] 
LoongArch: implemented a basic machine flag check

With this patch I can use eu-elflint to verify LoongArch ELF
binaries. Previously eu-elflint was complaining about invalid
machine flags:

$ ./src/elflint --gnu-ld ./src/elflint
invalid machine flags: 0x43
$ echo $?
1

    * backends/loongarch_symbol.c (loongarch_init): Hook
    machine_flag_check.
    * backends/loongarch_symbol.c (loongarch_machine_flag_check):
    New function.

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

Signed-off-by: Alexey Sheplyakov <asheplyakov@basealt.ru>
13 months agodebuginfod-client.c: Skip empty file creation for cancelled queries
Aaron Merey [Fri, 17 Mar 2023 15:20:50 +0000 (11:20 -0400)] 
debuginfod-client.c: Skip empty file creation for cancelled queries

Empty files in the client cache are used to indicate that contacted
servers could not find a requested resource.  Future queries for this
resource will not be attempted until the cache_miss_s duration has
passed.

Currently these empty files are also created when a query is cancelled
through the client's progressfn.  This can occur, for example, when a
user cancels a download with ctrl-c.

This prevents user-cancelled queries from being retried promptly without
having to modify cache_miss_s.  Fix this by skipping the creation of an
empty cache file when progressfn cancels a query.

Signed-off-by: Aaron Merey <amerey@redhat.com>
13 months agotests: skip '(null)' symname frames in backtrace tests
Mark Wielaard [Sat, 4 Mar 2023 20:55:56 +0000 (21:55 +0100)] 
tests: skip '(null)' symname frames in backtrace tests

Some setups might have some frames for unknown (null) functions
in the thread backtrace. Skip these frames instead of failing
immediately.

    * tests/backtrace.c (callback_verify): Check and skip nulls_seen.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
13 months agoconfigure.ac contains Bashisms
Mark Wielaard [Sun, 5 Mar 2023 12:09:34 +0000 (13:09 +0100)] 
configure.ac contains Bashisms

Autoconf scripts are supposed to be written in POSIX-compatible shell
language. elfutils commits 0ffe2874e75d48cb88936e119e5284ff2bf664d9
and 3fa98a6f29b0f370e32549ead7eb897c839af980 introduced Bashisms to
configure.ac that cause errors when /bin/sh is not Bash.

Example error when /bin/sh is Dash:

./configure: 8748: test: xyes: unexpected operator

The cause of the error is the use of a non-existent == operator in
expressions passed to the 'test' built-in command. POSIX shell
specifies only an = operator for testing string equality.

  * configure.ac: Replace == by = in use_msan and enable_demangler
  comparisons.

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

Reported-by: Matt Whitlock <sourceware@mattwhitlock.name>
Signed-off-by: Mark Wielaard <mark@klomp.org>
13 months agoFix static build when zstd is enabled for libelf
Mark Wielaard [Fri, 3 Mar 2023 16:10:30 +0000 (17:10 +0100)] 
Fix static build when zstd is enabled for libelf

When doing a static build (as with --enable-gcov) the build fails
because the executables aren't linked with -lzstd. Also the
run-debuginfod-query-retry.sh test relies on libdebuginfod.so.1 which
isn't there.

Fix by adding $(zstd_LIBS) to the static libelf lines and using the
debuginfod-find executable itself in the testcase.

    * src/Makefile.am (libelf): When BUILD_STATIC add $(zstd_LIBS)
    * tests/Makefile.am (libelf): Likewise.
    * tests/run-debuginfod-query-retry.sh: Use debuginfod-find instead
      of libdebuginfod.so.1

Signed-off-by: Mark Wielaard <mark@klomp.org>
13 months agoPrepare for 0.189 elfutils-0.189
Mark Wielaard [Fri, 3 Mar 2023 15:13:52 +0000 (16:13 +0100)] 
Prepare for 0.189

Set version to 0.189
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>
13 months agolibelf: Document and make ELFCOMPRESS_ZSTD usable with old system elf.h
Mark Wielaard [Fri, 3 Mar 2023 14:37:18 +0000 (15:37 +0100)] 
libelf: Document and make ELFCOMPRESS_ZSTD usable with old system elf.h

Make sure that even if the system elf.h doesn't have ELF_COMPRESS_ZSTD
defined it can still be used as constant. Also update libelf.h
documentation and add new feature to NEWS.

Signed-off-by: Mark Wielaard <mark@klomp.org>
13 months agoreadelf: Fix use-after-free ebl pointer issue
Mark Wielaard [Fri, 3 Mar 2023 13:13:49 +0000 (14:13 +0100)] 
readelf: Fix use-after-free ebl pointer issue

With -flto gcc 13 sees that we use the ebl pointer after closing and
freeing it.

In function ‘process_elf_file’,
    inlined from ‘process_dwflmod’ at readelf.c:818:3:
readelf.c:1070:6: error: pointer ‘ebl_18’ used after ‘free’ [-Werror=use-after-free]
 1070 |   if (pure_ebl != ebl)
      |      ^
In function ‘ebl_closebackend’,
    inlined from ‘process_elf_file’ at readelf.c:1068:3,
    inlined from ‘process_dwflmod’ at readelf.c:818:3:
../libebl/eblclosebackend.c:47:7: note: call to ‘free’ here
   47 |       free (ebl);
      |       ^

Fix by only calling ebl_closebackend after using it in the comparison.

Signed-off-by: Mark Wielaard <mark@klomp.org>
14 months agolibdw: Fix dwarf_getscopes memory leak on error
Mark Wielaard [Wed, 22 Feb 2023 22:34:00 +0000 (23:34 +0100)] 
libdw: Fix dwarf_getscopes memory leak on error

When there is an error in dwarf_getscopes after the initial scopes
have been allocated, e.g. when looking for the inlined scopes, then
the scopes would leak. Fix this by explicitly free the scopes on error.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
14 months agolibcpu: Remove the need of NMNES by using enum
Yonggang Luo [Sat, 17 Dec 2022 16:52:02 +0000 (00:52 +0800)] 
libcpu: Remove the need of NMNES by using enum

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
14 months agolibdw: Use elf_rawdata when checking .debug section
Mark Wielaard [Mon, 20 Feb 2023 15:42:56 +0000 (16:42 +0100)] 
libdw: Use elf_rawdata when checking .debug section

.debug sections are raw bytes and don't need conversion even when host
and file have different endian order.

Signed-off-by: Mark Wielaard <mark@klomp.org>
14 months agolibelf: memmove any extra bytes left by elf_cvt_gnuhash conversion
Mark Wielaard [Mon, 20 Feb 2023 15:32:57 +0000 (16:32 +0100)] 
libelf: memmove any extra bytes left by elf_cvt_gnuhash conversion

Otherwise some undefined bytes might be left in the buffer. Now they
might still be not useful, but at least they are as defined in the
file.

Signed-off-by: Mark Wielaard <mark@klomp.org>
14 months agoNEWS: Add old version code names
Mark Wielaard [Thu, 23 Feb 2023 09:42:15 +0000 (10:42 +0100)] 
NEWS: Add old version code names

Signed-off-by: Mark Wielaard <mark@klomp.org>
14 months agoUpdate m4 files from autoconf-archive
Mark Wielaard [Tue, 21 Feb 2023 21:27:59 +0000 (22:27 +0100)] 
Update m4 files from autoconf-archive

Update m4/ax_check_compile_flag.m4 and m4/ax_cxx_compile_stdcxx.m4
to autoconf-archive-2023.02.20.

Signed-off-by: Mark Wielaard <mark@klomp.org>
14 months agoconfigure: Check for and -Wuse-after-free=3 when available
Mark Wielaard [Tue, 21 Feb 2023 12:12:38 +0000 (13:12 +0100)] 
configure: Check for and -Wuse-after-free=3 when available

gcc already includes -Wuse-after-free=2 in -Wall. -Wuse-after-free=3
also warns for indeterminate pointers in equality expressions.

Signed-off-by: Mark Wielaard <mark@klomp.org>
14 months agolibasm: Fix use-after-free issue with circular single linked list cleanup
Mark Wielaard [Fri, 17 Feb 2023 13:52:04 +0000 (14:52 +0100)] 
libasm: Fix use-after-free issue with circular single linked list cleanup

Pointed out by gcc 12 with -Wuse-after-free=3

In function ‘free_section’
asm_end.c:552:17: error: pointer ‘data’ used after ‘free’ [-Werror=use-after-free]
  552 |     while (oldp != scnp->content);
      |            ~~~~~^~~~~~~~~~~~~~~~
asm_end.c:550:9: note: call to ‘free’ here
  550 |         free (oldp);
      |         ^~~~~~~~~~~

Fix by freeing scnp->content last.

Signed-off-by: Mark Wielaard <mark@klomp.org>
14 months agoNEWS: Mention linking with libstdc++ or using --disable-demangler
Mark Wielaard [Fri, 17 Feb 2023 20:17:10 +0000 (21:17 +0100)] 
NEWS: Mention linking with libstdc++ or using --disable-demangler

Signed-off-by: Mark Wielaard <mark@klomp.org>
14 months agolibdw: check that DWARF strings are null-terminated
Aleksei Vetrov [Tue, 14 Feb 2023 20:30:02 +0000 (20:30 +0000)] 
libdw: check that DWARF strings are null-terminated

It is expected from libdw to return strings that are null-terminated to
avoid overflowing ELF data.

* Add calculation of a safe prefix inside string sections, where any
  string will be null-terminated.

* Check if offset overflows the safe prefix in dwarf_formstring.

Signed-off-by: Aleksei Vetrov <vvvvvv@google.com>
14 months agoconfigure: Error when demangler is enabled, but libstdc++ support isn't
Mark Wielaard [Wed, 15 Feb 2023 16:00:30 +0000 (17:00 +0100)] 
configure: Error when demangler is enabled, but libstdc++ support isn't

There have been a couple of cases where demangler support has been
accidentially been disabled because libstdc++ wasn't there/installed
during build. Make it an error if --disable-demangler isn't explicitly
given.

Signed-off-by: Mark Wielaard <mark@klomp.org>
14 months agodoc: Add .TP before -g in debuginfod.8
Mark Wielaard [Tue, 14 Feb 2023 20:03:38 +0000 (21:03 +0100)] 
doc: Add .TP before -g in debuginfod.8

Fixes indentation of -g option.

Signed-off-by: Mark Wielaard <mark@klomp.org>
14 months agolibdw: Correct data end checkfor deref_type operand in dwarf_getlocation
Mark Wielaard [Tue, 14 Feb 2023 19:24:30 +0000 (20:24 +0100)] 
libdw: Correct data end checkfor deref_type operand in dwarf_getlocation

In __libdw_intern_expression we checked for one byte too many.
We only need one byte for the size and (at least one) for the uleb128
DIE reference.

Signed-off-by: Mark Wielaard <mark@klomp.org>
14 months agolibdw: Handle DW_OP_GNU_uninit in dwarf_getlocation
Mark Wielaard [Fri, 10 Feb 2023 12:56:58 +0000 (13:56 +0100)] 
libdw: Handle DW_OP_GNU_uninit in dwarf_getlocation

dwarf_getlocation would return an error when it saw a
DW_OP_GNU_uninit. Handle it by simply recognizing as a no argument
operation.

DW_OP_GNU_uninit is emitted by GCC as a marker to flag the location
expression as referring to an uninitialized value.

Signed-off-by: Mark Wielaard <mark@klomp.org>
14 months agolibdw, readelf, elflint: Add get_(u|s)leb128 guards
Mark Wielaard [Wed, 8 Feb 2023 15:53:24 +0000 (16:53 +0100)] 
libdw, readelf, elflint: Add get_(u|s)leb128 guards

Add sanity check making sure an leb128 isn't being read beyond the
end of the current data segment. Most code already had these guards,
but some were missing. This makes sure an appropriate error is
generated instead.

Signed-off-by: Mark Wielaard <mark@klomp.org>
14 months agolibdw: check memory access in get_(u|s)leb128
Aleksei Vetrov [Mon, 13 Feb 2023 20:10:05 +0000 (20:10 +0000)] 
libdw: check memory access in get_(u|s)leb128

__libdw_get_uleb128 and __libdw_get_sleb128 should check if addrp has
already reached the end before unrolling the first step. It is done by
moving __libdw_max_len to the beginning of the function, which can
notice, that addrp is beyond the end. Then we just check the result of
this function.

Signed-off-by: Aleksei Vetrov <vvvvvv@google.com>
14 months agobackends: Handle DW_TAG_unspecified_type in dwarf_peeled_die_type
Mark Wielaard [Thu, 26 Jan 2023 17:19:15 +0000 (18:19 +0100)] 
backends: Handle DW_TAG_unspecified_type in dwarf_peeled_die_type

binutils 2.40 introduces DW_TAG_unspecified_type for assembly
functions with an unknown return type. This breaks the
run-funcretval.sh testcase because dwfl_module_return_value_location
returns an error for such functions because it cannot determine the
return value location. Fix that by treating DW_TAG_unspecified_type
as if the DIE doesn't have a DW_AT_type.

Also update the testcase to explicitly checking for
DW_TAG_unspecified_type and printing "returns unspecified type".

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
14 months agoconfigure: Add --enable-sanitize-memory
Ilya Leoshkevich [Mon, 13 Feb 2023 16:45:51 +0000 (17:45 +0100)] 
configure: Add --enable-sanitize-memory

Add support for clang Memory Sanitizer [1], which detects the usage of
uninitialized values. While elfutils itself is already checked with
valgrind, checking code that depends on elfutils requires elfutils to
be built with MSan.

MSan is not linked into shared libraries, and is linked into
executables statically. Therefore, unlike the other sanitizers, MSan
needs to be configured fairly early, since we need to drop
-D_FORTIFY_SOURCE [2], -Wl,-z,defs and --no-undefined.

Disable a few tests that run for more than 5 minutes due to test files
being statically linked with MSan.

[1] https://clang.llvm.org/docs/MemorySanitizer.html
[2] https://github.com/google/sanitizers/issues/247

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
14 months agobackends: Support returning lvalue and rvalue references
Ilya Leoshkevich [Mon, 13 Feb 2023 16:45:50 +0000 (17:45 +0100)] 
backends: Support returning lvalue and rvalue references

On the low level, they are the same as pointers. The change needs to be
done for all backends, so define a function and a macro to avoid
repetition. Also add a native test, which has to be implemented in C++.
Add the configure check for it.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
14 months agoprintversion: Fix unused variable
Ilya Leoshkevich [Mon, 13 Feb 2023 16:45:49 +0000 (17:45 +0100)] 
printversion: Fix unused variable

clang complains:

    debuginfod.cxx:354:1: error: unused variable 'apba__' [-Werror,-Wunused-const-variable]
    ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT;
    ^
    ../lib/printversion.h:47:21: note: expanded from macro 'ARGP_PROGRAM_BUG_ADDRESS_DEF'
      const char *const apba__ __asm ("argp_program_bug_address")
                        ^

The default linkage for consts in C++ is internal, so declare them
extern. While at it, remove the debuginfod workaround for
argp_program_version_hook.

Co-developed-by: Mark Wielaard <mark@klomp.org>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
14 months agotests: Ignore dwfl-report-offline-memory
Ilya Leoshkevich [Mon, 13 Feb 2023 16:45:48 +0000 (17:45 +0100)] 
tests: Ignore dwfl-report-offline-memory

It's showing up in git status when configuring in the source directory.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
14 months agoconfigure: Add --disable-demangler
Ilya Leoshkevich [Wed, 8 Feb 2023 19:52:25 +0000 (20:52 +0100)] 
configure: Add --disable-demangler

__cxa_demangle is normally implemented in the C++ runtime library,
instrumenting which for MSan is a hassle. Add a knob for disbling it.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
14 months agoconfigure: Use -fno-addrsig if possible
Ilya Leoshkevich [Wed, 8 Feb 2023 19:52:24 +0000 (20:52 +0100)] 
configure: Use -fno-addrsig if possible

By default, clang produces .llvm_addrsig sections [1]. The GNU
toolchain does not know how to handle them yet [2], so just ask clang
not to generate them for the time being.

[1] https://llvm.org/docs/Extensions.html#sht-llvm-addrsig-section-address-significance-table
[2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105625

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
14 months agoreadelf: Fix set but not used parameter
Ilya Leoshkevich [Wed, 8 Feb 2023 19:52:22 +0000 (20:52 +0100)] 
readelf: Fix set but not used parameter

clang complains:

    readelf.c:12205:72: error: parameter 'desc' set but not used [-Werror,-Wunused-but-set-parameter]
    handle_bit_registers (const Ebl_Register_Location *regloc, const void *desc,
                                                                           ^

Mark Wielaard says:

    It is never really used since as far as I can see we don't have any
    backend with a core register sets where a register doesn't have a
    number of bits which isn't a multiple of 8 (only ia64 has some 1
    bit registers, but those don't seem part of the core register set).

    If we do accidentally try to handle such a register having an abort
    is also not very nice. Lets just warn and return/continue.

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

Co-developed-by: Mark Wielaard <mark@klomp.org>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
14 months agolibasm: Fix xdefault_pattern initialization
Ilya Leoshkevich [Wed, 8 Feb 2023 19:52:20 +0000 (20:52 +0100)] 
libasm: Fix xdefault_pattern initialization

clang complains:

    asm_newscn.c:48:22: error: field 'pattern' with variable sized type 'struct FillPattern' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end]
      struct FillPattern pattern;
                         ^

Fix by using a union instead. Define the second union member to be a
char array 1 byte larger than struct FillPattern. This should be legal
according to 6.7.9:

    If an object that has static or thread storage duration is not
    initialized explicitly, then ... if it is a union, the first named
    member is initialized (recursively) according to these rules, and
    any padding is initialized to zero bits.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
14 months agoaddr2line: Do not test demangling in run-addr2line-i-test.sh
Ilya Leoshkevich [Mon, 6 Feb 2023 22:25:09 +0000 (23:25 +0100)] 
addr2line: Do not test demangling in run-addr2line-i-test.sh

There is run-addr2line-i-demangle-test.sh for that.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
14 months agoInitialize reglocs for VMCOREINFO
Ilya Leoshkevich [Mon, 6 Feb 2023 22:25:08 +0000 (23:25 +0100)] 
Initialize reglocs for VMCOREINFO

MSan complains:

    Uninitialized value was created by an allocation of 'reglocs' in the stack frame
       #0 0x562d35c686f0 in handle_core_note elfutils/src/readelf.c:12674:3
       #const Ebl_Register_Location *reglocs;
    ==1006199==WARNING: MemorySanitizer: use-of-uninitialized-value
       #0 0x562d35c68a2a in handle_core_note elfutils/src/readelf.c:12692:11
       #colno = handle_core_registers (ebl, ebl->elf, desc + regs_offset,
       #                               reglocs, nregloc);

Strictly speaking, this is not a problem, because nregloc == 0, but for
other note types we initialize it anyway, so do it here as well.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
14 months agoreadelf: Fix set but not used variable
Ilya Leoshkevich [Mon, 6 Feb 2023 22:25:07 +0000 (23:25 +0100)] 
readelf: Fix set but not used variable

clang complains:

    readelf.c:10250:10: error: variable 'nculist' set but not used [-Werror,-Wunused-but-set-variable]
      size_t nculist = 0;
             ^

Fix by deleting it.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
14 months agodebuginfod-client.c: Download section even if cached executable didn't contain it.
Aaron Merey [Wed, 8 Feb 2023 02:15:33 +0000 (21:15 -0500)] 
debuginfod-client.c: Download section even if cached executable didn't contain it.

Before attempting to download a section, cache_find_section tries to
extract the section from existing files in the cache. If it's determined
that the section must not exist, cache_find_section returns -ENOENT to
indicate that the download should be skipped.

This patch fixes a bug where cache_find_section returns -ENOENT even
though the section exists.  If the cache contains the executable but
not the debuginfo with the given build-id and the section only exists
in the debuginfo (such as any of the .debug_* sections), then
debuginfod_find_section returns -ENOENT even if the section could be
downloaded.

Fix this by having cache_find_section not return -ENOENT unless cached
debuginfo was able to be read.

Signed-off-by: Aaron Merey <amerey@redhat.com>
14 months agodebuginfod: Make sure there is only one typedef for debuginfod_client
Mark Wielaard [Mon, 6 Feb 2023 09:21:58 +0000 (10:21 +0100)] 
debuginfod: Make sure there is only one typedef for debuginfod_client

Both debuginfod.h and libdwfl.h have a simple typedef for struct
debuginfod_client. Some compilers pedantically warn when including
both headers that such typedefs are only officially supported in
C11. So guard them with _ELFUTILS_DEBUGINFOD_CLIENT_TYPEDEF to
make them happy.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
14 months agotests: Check ELFUTILS_DISABLE_DEMANGLE in run-addr2line-C-test.sh
Mark Wielaard [Fri, 3 Feb 2023 12:44:17 +0000 (13:44 +0100)] 
tests: Check ELFUTILS_DISABLE_DEMANGLE in run-addr2line-C-test.sh

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
15 months agolibdw: Search for abstract origin in the correct CU
Mark Wielaard [Sat, 21 Jan 2023 23:31:57 +0000 (00:31 +0100)] 
libdw: Search for abstract origin in the correct CU

With gcc -flto the abstract origin of an inlined subroutine
could be in a different CU. dwarf_getscopes might return an
empty scope if it cannot find the abstract origin scope. So
make sure to search in the

We also tried to add the origin match in pc_record directly
in the current inlined scope. This always failed, causing
to do a needless traversal, followed by the full CU scan in
dwarf_getscopes. Just always stop the pc_record search and
then do the CU origin_match in dwarf_getscopes.

Signed-off-by: Mark Wielaard <mark@klomp.org>
15 months agoaddr2line: -C should not try to handle optional (ignored) argument
Mark Wielaard [Sun, 22 Jan 2023 19:50:53 +0000 (20:50 +0100)] 
addr2line: -C should not try to handle optional (ignored) argument

The --demangle option takes an option (ignored) argument. Since -C
is the short option of --demangle it also takes that optional
argument. But that means that something like -Cfi is like -C got
fi as argument, while the user expects -Cfi to be like -C -f -i.

Separate the --demangle and -C options. --demangle still takes
an optional (ignored) argument, but -C doesn't take any arguments
so -Cfi acts the same as -fiC.

Also fix --target, -b, so that it is properly ignored (and not
accidentially enables demangling).

Signed-off-by: Mark Wielaard <mark@klomp.org>
15 months agolibdwfl: add check for elf_memory return value
Aleksei Vetrov [Wed, 25 Jan 2023 14:16:57 +0000 (14:16 +0000)] 
libdwfl: add check for elf_memory return value

elf_memory call in __libdw_open_elf_memory can return NULL. It was not
checked and led to the null pointer dereference.

Signed-off-by: Aleksei Vetrov <vvvvvv@google.com>
15 months agotests: run-debuginfod-query-retry.sh /bin/sh might not have a build-id
Mark Wielaard [Thu, 19 Jan 2023 22:53:33 +0000 (23:53 +0100)] 
tests: run-debuginfod-query-retry.sh /bin/sh might not have a build-id

If /bin/sh wasn't build with build-id the test fails because
debuginfod-find will not be able to even try to fetch something.
Use libdebuginfod.so.1 instead as test file because we just
build that and configure makes sure we always produce a build-id.

Signed-off-by: Mark Wielaard <mark@klomp.org>
15 months agobackends: sparc uses NONE relocation type in ET_EXEC and ET_DYN files
Mark Wielaard [Thu, 19 Jan 2023 22:04:04 +0000 (23:04 +0100)] 
backends: sparc uses NONE relocation type in ET_EXEC and ET_DYN files

Using the NONE relocation doesn't do anything, but is harmless.

This fixes several (self) tests on sparc that use elflint to
check files are valid ELF.

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