]> git.ipfire.org Git - thirdparty/elfutils.git/log
thirdparty/elfutils.git
9 months agolibcpu: Include config.h before standard headers in lexer source
Michael Pratt [Thu, 10 Oct 2024 10:27:02 +0000 (10:27 +0000)] 
libcpu: Include config.h before standard headers in lexer source

As part of the processing of flex, definitions and headers
are added to output source before any literal text or generated code.

This causes standard headers to come before config.h
unless config.h is included in a %top block instead
as specified in the flex manual, section 5.1 "Format of the Definitions".

The %top block is non-POSIX, so using it reinforces
the requirement of "flex" over a standardized "lex" even more.

      * libcpu/i386_lex.l (%top): add flex %top block
      and move config.h header inclusion to it.

Signed-off-by: Michael Pratt <mcpratt@pm.me>
9 months agolib: Add missing config.h include to next_prime.c
Michael Pratt [Thu, 10 Oct 2024 10:26:54 +0000 (10:26 +0000)] 
lib: Add missing config.h include to next_prime.c

This is the last remaining C source file as of this commit
without the standard conditional inclusion of config.h
as the very first header.

      * lib/next_prime.c: add missing config.h header.

Signed-off-by: Michael Pratt <mcpratt@pm.me>
9 months agotests/test-subr.sh: Put test_dir under /var/tmp.
Frank Ch. Eigler [Wed, 9 Oct 2024 17:41:14 +0000 (13:41 -0400)] 
tests/test-subr.sh: Put test_dir under /var/tmp.

Every individual test in elfutils involves a temporary directory.
Previous version of this script put that directory under the build
tree.  That's OK if it's a local disk, but if it's on NFS, then some
tests - run-large-elf-file.sh, several run-debuginfod-*.sh - take long
enough to run to fail tests intermittently.

This patch moves the temp_dir under ${TMPDIR-/var/tmp/}, so it
operates at local disk speed rather than whatever-build-filesystem
speed.  Individual test scripts are all unaffected.  (One could
consider /tmp instead, which is a RAM disk on modern systems, except
that some of the elfutils tests produce GB-sized temporary files.
That's probably too big for RAM.)

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
9 months agotests: Fix specifying constant of double type
Khem Raj [Thu, 3 Oct 2024 00:04:08 +0000 (17:04 -0700)] 
tests: Fix specifying constant of double type

'd' suffix seems to be not acceptable by clang compiler
Using 'e0' fixes this by keeping value to be same

Fixes
funcretval_test_struct.c:83:27: error: invalid suffix 'd' on floating constant
   83 |   dpoint_t dp = dmkpt (3.0d, 1.0d);
      |                           ^
funcretval_test_struct.c:83:33: error: invalid suffix 'd' on floating constant
   83 |   dpoint_t dp = dmkpt (3.0d, 1.0d);
      |

Signed-off-by: Khem Raj <raj.khem@gmail.com>
10 months agoelflint: Fix memory leak in check_gnu_hash function
Maks Mishin [Wed, 18 Sep 2024 08:58:07 +0000 (11:58 +0300)] 
elflint: Fix memory leak in check_gnu_hash function

Dynamic memory, referenced by 'collected', is allocated at elflint.c:2235
and lost at elflint.c:2296.

Found by RASU JSC with SVACE.

Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
10 months agolibelf: Don't crash elf[32|64]_xlateto[fm] on bad arguments.
Mark Wielaard [Wed, 28 Aug 2024 21:58:58 +0000 (23:58 +0200)] 
libelf: Don't crash elf[32|64]_xlateto[fm] on bad arguments.

Check that src and dest aren't NULL and that src->d_type < ELF_T_NUM.

      * elf32_xlatetof.c (elfw2(LIBELFBITS, xlatetof)): Check src, dest
      and src->d_type are valid.
      * elf32_xlatetom.c (elfw2(LIBELFBITS, xlatetom)): Likewise.

Signed-off-by: Mark Wielaard <mark@klomp.org>
10 months agoelf*_xlatetof: do not check ELF_T_NHDR[8] has integer number of records
Mark Wielaard [Wed, 28 Aug 2024 21:43:02 +0000 (23:43 +0200)] 
elf*_xlatetof: do not check ELF_T_NHDR[8] has integer number of records

commit bc0f7450c "elf*_xlatetom: do not check ELF_T_NHDR has integer
number of records" fixed
https://bugzilla.redhat.com/show_bug.cgi?id=835877
But only for xlatetom. Do the same for xlatetof.

       * elf32_xlatetof.c (elfw2(LIBELFBITS, xlatetof)): Do not check for
       integer number of records in case of ELF_T_NHDR[8].

Signed-off-by: Mark Wielaard <mark@klomp.org>
10 months agoreadelf: Allow .gdb_index const table to be empty
Mark Wielaard [Sat, 7 Sep 2024 22:00:05 +0000 (00:00 +0200)] 
readelf: Allow .gdb_index const table to be empty

The .gdb_index const table can be empty, if no symbol table entry
refers to a name or CU. Which technically means the symbol table is
empty or has only zero members.

      * src/readelf.c (print_gdb_index_section): Check const_off is
      not past the end of the data section, it can be at the end.

Signed-off-by: Mark Wielaard <mark@klomp.org>
10 months agosrcfiles: Fix compile with --disable-libdebuginfod
Mark Wielaard [Mon, 9 Sep 2024 08:24:07 +0000 (10:24 +0200)] 
srcfiles: Fix compile with --disable-libdebuginfod

The eu-srcfiles --no-backup option is only valid when build with
libdebuginfod support. Adjust the ENABLE_LIBDEBUGINFOD conditional
to not use no_backup anywhere. Also only run the run-srcfiles-self.sh
test when debuginfod is enabled.

     * src/srcfiles.cxx (zip_files): Move endif ENABLE_LIBDEBUGINFOD
     after no_backup check.
     * tests/Makefile.am (TESTS): Only add run-srcfiles-self.sh
     if DEBUGINFOD and !DUMMY_LIBDEBUGINFOD.
     * tests/run-srcfiles.self.sh: Use local DEBUGINFOD_CACHE_PATH.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
10 months agoreadelf: Fix printing of .gdb_index symbol table offset.
Mark Wielaard [Sat, 7 Sep 2024 00:15:18 +0000 (02:15 +0200)] 
readelf: Fix printing of .gdb_index symbol table offset.

We were printing the addr_off instead of the sym_off. And the
testcases all expected the address offset instead of the symbol table
offset.

        * src/readelf.c (print_gdb_index_section): Print sym_off as
        Symbol table offset.
* tests/run-readelf-gdb_index.sh: Fix up all symbol table
        offsets that were the same as the address offset.

Signed-off-by: Mark Wielaard <mark@klomp.org>
10 months agodebuginfod: Make sure extra libs are also included in static link in src/ too
Frank Ch. Eigler [Fri, 6 Sep 2024 23:26:36 +0000 (19:26 -0400)] 
debuginfod: Make sure extra libs are also included in static link in src/ too

commit 742fb81f3 did most of the work for supporting --enable-gcov,
but one debuginfod client is hiding in the src/ directory, namely
srcfiles, which also needs this enumeration of dependent libraries
for static linkage.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
10 months agoconfigure.ac: Restore HAVE_LIBARCHIVE
Aaron Merey [Fri, 6 Sep 2024 22:32:41 +0000 (18:32 -0400)] 
configure.ac: Restore HAVE_LIBARCHIVE

src/srcfiles.cxx depends on the HAVE_LIBARCHIVE macro to enable
the srcfiles --zip option.  Defining this macro was accidentally
removed from configure.ac in commit 30b5592a3.

Signed-off-by: Aaron Merey <amerey@redhat.com>
10 months agodebuginfod: service metadata queries in separate, timed-out connections
Frank Ch. Eigler [Tue, 3 Sep 2024 15:27:36 +0000 (11:27 -0400)] 
debuginfod: service metadata queries in separate, timed-out connections

The --metadata-maxtime=SECONDS parameter was intended to limit elapsed
time debuginfod spends attempting to answer metadata queries.  These
can be slow because they have to apply glob matches across a large set
of strings, potentially taking many seconds.

However, this option was not implemented fully.  It checked for
timeouts only when rows of data were finally served up by the
database, not during.  Also, it used the same database connection that
normal debuginfod queries were using, locking them out.

New code creates a new temporary database connection for these
infrequent(?)  metadata queries, and enforces timeouts using the
sqlite3 progress-handler callback.  This effectively limits total
query runtime, inside or outside the database.

The elfutils testsuite dataset is not large enough to show either the
slow-glob or the locking-out-normal-queries phenomenon, so the
behavioral impact was hand-tested on a moderate sized debuginfod index
on a live federation server.  A full valgrind leak check indicated
it's clean.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
11 months agoaarch64: Add NT_ARM_PAC_* regset
Kuan-Ying Lee [Wed, 14 Aug 2024 08:51:19 +0000 (16:51 +0800)] 
aarch64: Add NT_ARM_PAC_* regset

Add the NT_ARM_PAC_MASK and NT_ARM_PAC_ENABLED_KEYS for aarch64.
Recognize and print the new core item.

Signed-off-by: Kuan-Ying Lee <kuan-ying.lee@canonical.com>
11 months agolibdwfl, aarch64: Read PAC mask from core
Steve Capper [Mon, 26 Aug 2024 10:52:57 +0000 (11:52 +0100)] 
libdwfl, aarch64: Read PAC mask from core

We need to read the PAC mask from a core file when debugging offline
as the information is still needed to demangle return addresses.

This commit pulls out the NT_ARM_PAC_MASK info from the core and feeds
it through to dwfl_thread_state_registers for each thread.

Signed-off-by: Steve Capper <steve.capper@arm.com>
11 months agolibdwfl, aarch64: extend dwfl_thread_state_registers to handle PAC
Steve Capper [Mon, 26 Aug 2024 10:52:56 +0000 (11:52 +0100)] 
libdwfl, aarch64: extend dwfl_thread_state_registers to handle PAC

On AArch64 systems with pointer authentication enabled, one needs to
know the PAC mask in order to unwind functions that employ PAC.

This patch extends dwfl_thread_state_registers to handle the PAC mask
information by introducing a special register -2. (-1 is used in a
similar manner already for handling the program counter).

The AArch64 linux process attach logic is also extended to query ptrace
for the PAC mask.

A subsequent patch will add support for retrieving the PAC mask from an
AArch64 linux core file.

Signed-off-by: Steve Capper <steve.capper@arm.com>
11 months agolibdwfl, aarch64: Demangle return addresses using a PAC mask
German Gomez [Mon, 26 Aug 2024 10:52:55 +0000 (11:52 +0100)] 
libdwfl, aarch64: Demangle return addresses using a PAC mask

Demangle mangled return addresses on AARCH64. The value of the masks is
stored in the struct Dwfl_Thread.

Signed-off-by: German Gomez <german.gomez@arm.com>
[SteveC: remove dwfl_thread_state_aarch64_pauth]
Signed-off-by: Steve Capper <steve.capper@arm.com>
11 months agolibdw, aarch64: Implement DW_CFA_AARCH64_negate_ra_state CFI instruction
German Gomez [Mon, 26 Aug 2024 10:52:54 +0000 (11:52 +0100)] 
libdw, aarch64: Implement DW_CFA_AARCH64_negate_ra_state CFI instruction

Implement DW_CFA_AARCH64_negate_ra_state in accordance with the DWARF
AARCH64 ABI [1].

Followup commits will use the value of this register to remove the PAC
from return addresses.

[1] https://github.com/ARM-software/abi-aa/blob/main/aadwarf64/aadwarf64.rst#44call-frame-instructions

Signed-off-by: German Gomez <german.gomez@arm.com>
Signed-off-by: Steve Capper <steve.capper@arm.com>
11 months agoaarch64: Create definitions for AARCH64_RA_SIGN_STATE register
German Gomez [Mon, 26 Aug 2024 10:52:53 +0000 (11:52 +0100)] 
aarch64: Create definitions for AARCH64_RA_SIGN_STATE register

This register will be used to indicate whether a return address is
mangled with a PAC or not, in accordance with the DWARF AARCH64 ABI [1].

[1] https://github.com/ARM-software/abi-aa/blob/main/aadwarf64/aadwarf64.rst#41dwarf-register-names

Signed-off-by: German Gomez <german.gomez@arm.com>
[SteveC: move DW_AARCH64_RA_SIGN_STATE to cfi.h, fix comments]
Signed-off-by: Steve Capper <steve.capper@arm.com>
11 months agotests: When BUILD_STATIC always link against libeu
Mark Wielaard [Wed, 21 Aug 2024 13:52:20 +0000 (15:52 +0200)] 
tests: When BUILD_STATIC always link against libeu

libeu is a static library with internal helper functions normally
included in all shared libraries. But when linking static (with
--enable-gcov) we need to explicitly link it into the test binaries.

       * tests/Makefile.am (libelf): Add $(libeu) when BUILD_STATIC.

Signed-off-by: Mark Wielaard <mark@klomp.org>
11 months agodebuginfod: Make sure crypto and jsonc are also included in static link
Mark Wielaard [Wed, 21 Aug 2024 13:32:59 +0000 (15:32 +0200)] 
debuginfod: Make sure crypto and jsonc are also included in static link

When doing a --enable-gcov build we link all binaries static.
libdebuginfod.so now depends on crypto an jsonc. So also add those
when linking against libdebuginfod.a

      debuginfod/Makefile.am (libdebuginfod): Add $(crypto_LIBS)
      $(jsonc_LIBS) when BUILD_STATIC.

Signed-off-by: Mark Wielaard <mark@klomp.org>
11 months agolibdw: Make libdw_findcu thread-safe
Heather McIntyre [Tue, 16 Jul 2024 16:37:32 +0000 (12:37 -0400)] 
libdw: Make libdw_findcu thread-safe

* libdw/libdw_findcu.c (__libdw_findcu): Add locking.

Signed-off-by: Heather S. McIntyre <hsm2@rice.edu>
Signed-off-by: Aaron Merey <amerey@redhat.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
11 months agolibdw: Make libdw_find_split_unit thread-safe
Heather McIntyre [Tue, 20 Aug 2024 20:42:03 +0000 (16:42 -0400)] 
libdw: Make libdw_find_split_unit thread-safe

* libdw/dwarf_end.c (cu_free): Free split_lock.
* libdw/dwarf_formref_die.c (dwarf_formref_die): Add locking
  around call to __libdw_intern_next_unit.
* libdw/libdwP.h (struct Dwarf_CU): Add split_lock.
* libdw/libdw_find_split_unit.c (__libdw_find_split_unit):
  Add locking.
* libdw/libdw_findcu.c (__libdw_intern_next_unit): Init
  split_lock.

Signed-off-by: Heather S. McIntyre <hsm2@rice.edu>
Signed-off-by: Aaron Merey <amerey@redhat.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
11 months agolibdwP.h: Add locking to __libdw_dieabbrev
Heather McIntyre [Tue, 16 Jul 2024 16:25:57 +0000 (12:25 -0400)] 
libdwP.h: Add locking to __libdw_dieabbrev

* libdw/dwarf_end.c (cu_free): Free abbrev_lock.
        * libdw/libdwP.h (__libdw_dieabbrev): Add locking.
  (struct Dwarf_CU): Define abbrev_lock.
* libdw/libdw_findcu.c (__libdw_intern_next_unit): Init
  abbrev_lock.

Signed-off-by: Heather S. McIntyre <hsm2@rice.edu>
Signed-off-by: Aaron Merey <amerey@redhat.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
11 months agolibdw: make dwarf_getalt and dwarf_setalt thread-safe
Heather McIntyre [Fri, 12 Jul 2024 22:35:00 +0000 (18:35 -0400)] 
libdw: make dwarf_getalt and dwarf_setalt thread-safe

* libdw/dwarf_begin_elf.c (dwarf_begin_elf): Init dwarf_lock.
* libdw/dwarf_end.c (dwarf_end): Free dwarf_lock.
* libdw/dwarf_getalt.c (dwarf_getalt): Add locking.
* libdw/dwarf_setalt.c (dwarf_setalt): Ditto.
* libdw/libdwP.h (struct Dwarf): Define dwarf_lock.

Signed-off-by: Heather S. McIntyre <hsm2@rice.edu>
Signed-off-by: Aaron Merey <amerey@redhat.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
11 months agolib: Add eu_tsearch, eu_tfind, eu_tdelete and eu_tdestroy
Heather McIntyre [Fri, 12 Jul 2024 22:23:56 +0000 (18:23 -0400)] 
lib: Add eu_tsearch, eu_tfind, eu_tdelete and eu_tdestroy

Add struct search_tree to hold tree root and lock.  Add new eu_t*
functions for ensuring synchronized tree access.

Replace tsearch, tfind, etc with eu_t* equivalents.

lib:
* Makefile.am (libeu_a_SOURCES): Add eu-search.c.
(noinst_HEADERS): Add eu-search.h and locks.h.
* eu-config.h: Move rwlock macros to locks.h.
* eu-search.c: New file containing tree search functions with
  locking.
* eu-search.h: New file.
* locks.h: New file containing rwlock macros previously in
  eu-config.h.
libdw:
* cfi.h (struct Dwarf_CFI_s): Change type of search tree members
  from void * to search_tree.
* cie.c: Replace tree search functions with eu-search equivalents.
* dwarf_begin_elf.c (valid_p): Initialize search trees.
* dwarf_end.c (cu_free): Replace tree search functions
  with eu-search equivalents.
* dwarf_getcfi.c (dwarf_getcfi): Initialize search trees.
* dwarf_getlocations.c: Replace search tree functions with
  eu-search equivalents.
  (__libdw_intern_expression): Change type of cache parameter to
  search_tree *.
* dwarf_getmacros.c: Replace tree search functions with
  eu-search equivalents.
* dwarf_getsrclines.c: Ditto.
* fde.c: Ditto.
* frame-cache.c (__libdw_destroy_frame_cache): Initialize search
  trees.
* libdwP.h (struct Dwarf): Change type of search tree members
  from void * to search_tree.
  (struct Dwarf_CU): Ditto.
  (__libdw_intern_expression): Change type of cache parameter to
  search_tree *.
* libdw_find_split_unit.c: Replace tree search functions with
  eu-search equivalents.
* libdw_findcu.c: Ditto.
libdwfl:
* cu.c: Ditto.
* libdwflP.h (struct Dwfl_Module): Replace void *lazy_cu_root
  with search_tree lazy_cu_tree.
libelf:
* elf_begin.c (file_read_elf): Initialize rawchunck_tree.
* elf_end.c (elf_end): Replace tree search function with
  eu-search equivalent.
* elf_getdata_rawchunck.c: Ditto.
* libelfP.h (struct Elf): Replace void * rawchuncks member with
search_tree rawchunk_tree.

Signed-off-by: Heather S. McIntyre <hsm2@rice.edu>
Signed-off-by: Aaron Merey <amerey@redhat.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
11 months agolibelf: Fix deadlock in elf_cntl
Heather McIntyre [Fri, 12 Jul 2024 22:32:34 +0000 (18:32 -0400)] 
libelf: Fix deadlock in elf_cntl

        * libelf/elf_cntl.c (elf_cntl): Move rwlock_wrlock, rwlock_unlock,
        inside case switch statements.  Remove unnecessary early return.

Signed-off-by: Heather S. McIntyre <hsm2@rice.edu>
Signed-off-by: Aaron Merey <amerey@redhat.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
11 months agolibelf: Fix deadlock in __libelf_readall
Heather McIntyre [Fri, 12 Jul 2024 22:28:13 +0000 (18:28 -0400)] 
libelf: Fix deadlock in __libelf_readall

Apply locking during __libelf_readall.

Signed-off-by: Heather S. McIntyre <hsm2@rice.edu>
Signed-off-by: Aaron Merey <amerey@redhat.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
11 months agoaarch64: add some new core note types name
Kuan-Ying Lee [Wed, 14 Aug 2024 08:51:20 +0000 (16:51 +0800)] 
aarch64: add some new core note types name

Recognize names of some new core note types in ebl_core_note_type_name.

Signed-off-by: Kuan-Ying Lee <kuan-ying.lee@canonical.com>
11 months agoaarch64: Add NT_ARM_TAGGED_ADDR_CTRL regset
Kuan-Ying Lee [Wed, 14 Aug 2024 08:51:18 +0000 (16:51 +0800)] 
aarch64: Add NT_ARM_TAGGED_ADDR_CTRL regset

Add the NT_ARM_TAGGED_ADDR_CTRL regset for aarch64.
Recognize and print this new core itme.

Signed-off-by: Kuan-Ying Lee <kuan-ying.lee@canonical.com>
11 months agolibelf: Sync elf.h from glibc
Mark Wielaard [Fri, 16 Aug 2024 22:48:17 +0000 (00:48 +0200)] 
libelf: Sync elf.h from glibc

* libelf/elf.h: Adds NT_ARM_{SSVE,ZA,ZT,FPRM}

Signed-off-by: Mark Wielaard <mark@klomp.org>
11 months agoAvoid overriding libcxx system header
Alfred Wingate [Wed, 14 Aug 2024 16:14:38 +0000 (12:14 -0400)] 
Avoid overriding libcxx system header

Replace -I with -iquote to avoid overriding stack system header from libcxx-18
with the previously built stack binary. Override DEFAULT_INLCUDES because m4
adds -I. by default.

https://bugs.gentoo.org/925241

Signed-off-by: Aaron Merey <amerey@redhat.com>
11 months agobackends/riscv: Remove unused relocations
Andreas Schwab [Wed, 31 Jul 2024 13:03:35 +0000 (15:03 +0200)] 
backends/riscv: Remove unused relocations

None of these relocations were ever part of any object file.  The
GNU_VTINHERIT and GNU_VTINHERIT relocations were part of the obsolete
--gc-sections support which was never implemented for RISC-V.  The other
relocations are only used internally by libbfd during the relaxation pass
and eliminated before writing the object file.

* riscv_reloc.def: Remove GNU_VTINHERIT, GNU_VTENTRY, RVC_LUI,
GPREL_I, GPREL_S, TPREL_I, TPREL_S.

12 months agodebuginfod: populate _r_seekable on request
Omar Sandoval [Tue, 23 Jul 2024 22:35:43 +0000 (15:35 -0700)] 
debuginfod: populate _r_seekable on request

Since the schema change adding _r_seekable was done in a backward
compatible way, seekable archives that were previously scanned will not
be in _r_seekable.  Whenever an archive is going to be extracted to
satisfy a request, check if it is seekable.  If so, populate _r_seekable
while extracting it so that future requests use the optimized path.

The next time that BUILDIDS is bumped, all archives will be checked at
scan time.  At that point, checking again will be unnecessary and this
commit (including the test case modification) can be reverted.

Signed-off-by: Omar Sandoval <osandov@fb.com>
12 months agodebuginfod: populate _r_seekable on scan
Omar Sandoval [Tue, 23 Jul 2024 22:35:42 +0000 (15:35 -0700)] 
debuginfod: populate _r_seekable on scan

Whenever a new archive is scanned, check if it is seekable with a little
liblzma magic, and populate _r_seekable if so.  With this, newly scanned
seekable archives will used the optimized extraction path added in the
previous commit.  Also add a test case using some artificial packages.

Signed-off-by: Omar Sandoval <osandov@fb.com>
12 months agodebuginfod: optimize extraction from seekable xz archives
Omar Sandoval [Tue, 23 Jul 2024 22:35:41 +0000 (15:35 -0700)] 
debuginfod: optimize extraction from seekable xz archives

The kernel debuginfo packages on Fedora, Debian, and Ubuntu, and many of
their downstreams, are all compressed with xz in multi-threaded mode,
which allows random access.  We can use this to bypass the full archive
extraction and dramatically speed up kernel debuginfo requests (from ~50
seconds in the worst case to < 0.25 seconds).

This works because multi-threaded xz compression splits up the stream
into many independently compressed blocks.  The stream ends with an
index of blocks.  So, to seek to an offset, we find the block containing
that offset in the index and then decompress and throw away data until
we reach the offset within the block.  We can then decompress the
desired amount of data, possibly from subsequent blocks.  There's no
high-level API in liblzma to do this, but we can do it by stitching
together a few low-level APIs.

We need to pass down the file ids then look up the size, uncompressed
offset, and mtime in the _r_seekable table.  Note that this table is not
yet populated, so this commit has no functional change on its own.

Signed-off-by: Omar Sandoval <osandov@fb.com>
12 months agodebugifod: add new table and views for seekable archives
Omar Sandoval [Tue, 23 Jul 2024 22:35:40 +0000 (15:35 -0700)] 
debugifod: add new table and views for seekable archives

In order to extract a file from a seekable archive, we need to know
where in the uncompressed archive the file data starts and its size.
Additionally, in order to populate the response headers, we need the
file modification time (since we won't be able to get it from the
archive metadata).  Add a new table, _r_seekable, keyed on the archive
file id and entry file id and containing the size, offset, and mtime.
It also contains the compression type just in case new seekable formats
are supported in the future.

In order to search this table when we get a request, we need the file
ids available.  Add the ids to the _query_d and _query_e views, and
rename them to _query_d2 and _query_e2.

This schema change is backward compatible and doesn't require
reindexing.  _query_d2 and _query_e2 can be renamed back the next time
BUILDIDS needs to be bumped.

Before this change, the database for a single kernel debuginfo RPM
(kernel-debuginfo-6.9.6-200.fc40.x86_64.rpm) was about 15MB.  This
change increases that by about 70kB, only a 0.5% increase.

Signed-off-by: Omar Sandoval <osandov@fb.com>
12 months agodebuginfod: factor out common code for responding from an archive
Omar Sandoval [Tue, 23 Jul 2024 22:35:39 +0000 (15:35 -0700)] 
debuginfod: factor out common code for responding from an archive

handle_buildid_r_match has two very similar branches where it optionally
extracts a section and then creates a microhttpd response.  In
preparation for adding a third one, factor it out into a function.

Signed-off-by: Omar Sandoval <osandov@fb.com>
12 months agotests/run-debuginfod-fd-prefetch-caches.sh: disable fdcache limit check
Omar Sandoval [Tue, 23 Jul 2024 22:35:38 +0000 (15:35 -0700)] 
tests/run-debuginfod-fd-prefetch-caches.sh: disable fdcache limit check

Since commit acd9525e93d7 ("PR31265 - rework debuginfod archive-extract
fdcache"), the fdcache limit is only applied when a new file is interned
and it has been at least 10 seconds since the limit was last applied.
This means that the fdcache can go over the limit temporarily.

run-debuginfod-fd-prefetch-caches.sh happens to avoid tripping over this
because of lucky sizes of the files used in the test.  However, adding
new files for an upcoming test exposed this failure.

Disable this part of the test for now.

Signed-off-by: Omar Sandoval <osandov@fb.com>
12 months agodebuginfod: fix skipping <built-in> source file
Omar Sandoval [Tue, 23 Jul 2024 22:35:37 +0000 (15:35 -0700)] 
debuginfod: fix skipping <built-in> source file

dwarf_extract_source_paths explicitly skips source files that equal
"<built-in>", but dwarf_filesrc may return a path like "dir/<built-in>".
Check for and skip that case, too.

In particular, the test debuginfod RPMs have paths like this.  However,
the test cases didn't catch this because they have a bug, too: they
follow symlinks, which results in double-counting every file.  Fix that,
too.

Signed-off-by: Omar Sandoval <osandov@fb.com>
12 months agoAdd man pages for some libelf functions
Aaron Merey [Fri, 19 Jul 2024 02:03:02 +0000 (22:03 -0400)] 
Add man pages for some libelf functions

Add man pages for elf32_offscn.3, elf64_offscn.3, elf_getscn.3 and
elf_ndxscn.3.

Signed-off-by: Aaron Merey <amerey@redhat.com>
12 months agostrip.c: Apply --permissive when writing the debug file
Aaron Merey [Tue, 23 Jul 2024 19:26:26 +0000 (15:26 -0400)] 
strip.c: Apply --permissive when writing the debug file

The --permissive command line option is applied when writing the binary
being stripped but is not applied when writing its separate debug file.

Change this so that --permissive applies to writing the debug file as well.

Signed-off-by: Aaron Merey <amerey@redhat.com>
12 months agobackends: allocate enough stace for null terminator
Sergei Trofimovich [Wed, 17 Jul 2024 22:03:34 +0000 (23:03 +0100)] 
backends: allocate enough stace for null terminator

`gcc-15` added a new warning in https://gcc.gnu.org/PR115185:

    i386_regs.c:88:11: error: initializer-string for array of 'char' is too long [-Werror=unterminated-string-initialization]
       88 |           "ax", "cx", "dx", "bx", "sp", "bp", "si", "di", "ip"
          |           ^~~~

`elfutils` does not need to store '\0'. We could either initialize the
arrays with individual bytes or allocate extra byte for null.

This change initializes the array bytewise.

* backends/i386_regs.c (i386_register_info): Initialize the
array bytewise to fix gcc-15 warning.
* backends/x86_64_regs.c (x86_64_register_info): Ditto.

Signed-off-by: Sergei Trofimovich <slyich@gmail.com>
12 months agolibdwfl: Make dwfl_report_offline_memory work with ELF_C_READ_MMAP
Aleksei Vetrov [Thu, 11 Jul 2024 20:35:21 +0000 (20:35 +0000)] 
libdwfl: Make dwfl_report_offline_memory work with ELF_C_READ_MMAP

elf_memory open mode recently changed from ELF_C_READ to
ELF_C_READ_MMAP. This broken dwfl_report_offline_memory that changes
mode to ELF_C_READ_MMAP_PRIVATE to be compatible with subsequent
elf_begin on embedded ELF files.

The proper implementation of dwfl_report_offline_memory doesn't change
open mode and subsequent elf_begin invocations simply use cmd from the
reference Elf*.

Add tests to exercise Elf* to trigger the bug caused by incorrect cmd
set to Elf*.

  * libdwfl/offline.c (process_archive): Use archive->cmd
  instead of hardcoded ELF_C_READ_MMAP_PRIVATE.
  * libdwfl/open.c (libdw_open_elf): Use elf->cmd instead of
  hardcoded ELF_C_READ_MMAP_PRIVATE.
  (__libdw_open_elf_memory): Don't override (*elfp)->cmd.
  * tests/Makefile.am (dwfl_report_offline_memory): Add libelf
  as dependency.
  * tests/dwfl-report-offline-memory.c: Add count_sections to
  exercise Elf* from dwfl_report_offline_memory.
  * tests/run-dwfl-report-offline-memory.sh: Add expected number
  of sections to test invocations.

Signed-off-by: Aleksei Vetrov <vvvvvv@google.com>
12 months agotests/run-sysroot.sh: Call exit_cleanup directly
Aaron Merey [Fri, 12 Jul 2024 01:32:12 +0000 (21:32 -0400)] 
tests/run-sysroot.sh: Call exit_cleanup directly

exit_cleanup needs to be called directly since this test traps EXIT.

Signed-off-by: Aaron Merey <amerey@redhat.com>
12 months agotests/run-sysroot.sh: Delete file with tempfiles
Aaron Merey [Fri, 12 Jul 2024 00:02:23 +0000 (20:02 -0400)] 
tests/run-sysroot.sh: Delete file with tempfiles

Signed-off-by: Aaron Merey <amerey@redhat.com>
12 months agotests/run-sysroot.sh: Avoid testing output that depends on LZMA support
Aaron Merey [Thu, 11 Jul 2024 23:30:41 +0000 (19:30 -0400)] 
tests/run-sysroot.sh: Avoid testing output that depends on LZMA support

run-sysroot.sh checks whether a backtrace generated by eu-stack contains
symbol names found in binaries under a test sysroot.  Two frames in
the backtrace contain symbol names that must be read from .gnu_debugdata.

However this section can only be read if elfutils was built with LZMA
support.  If not, then the symbol names will be absent from the
backtrace.

Test the eu-stack output with these 2 frames removed in order to prevent
a test failure when LZMA support is missing.

Signed-off-by: Aaron Merey <amerey@redhat.com>
12 months agotests/Makefile.am: Add run-sysroot.sh to EXTRA_DIST
Aaron Merey [Thu, 4 Jul 2024 23:28:27 +0000 (19:28 -0400)] 
tests/Makefile.am: Add run-sysroot.sh to EXTRA_DIST

Signed-off-by: Aaron Merey <amerey@redhat.com>
12 months agotests: add test for eu-stack --sysroot
Michal Sekletar [Tue, 2 Jul 2024 17:31:00 +0000 (19:31 +0200)] 
tests: add test for eu-stack --sysroot

12 months agoeu-stack: add support for sysroot option
Luke Diamand [Tue, 2 Jul 2024 17:30:59 +0000 (19:30 +0200)] 
eu-stack: add support for sysroot option

Use the dwfl_set_sysroot() function to set the sysroot to be
used when analysing a core:

e.g.
   $ eu-stack --core core --sysroot /path/to/sysroot -e crashing_prog

Signed-off-by: Luke Diamand <ldiamand@roku.com>
Signed-off-by: Michal Sekletar <msekleta@redhat.com>
12 months agolibdwfl: specify optional sysroot to search for shared libraries and binaries
Luke Diamand [Tue, 2 Jul 2024 17:30:58 +0000 (19:30 +0200)] 
libdwfl: specify optional sysroot to search for shared libraries and binaries

When searching the list of modules in a core file, if the core was
generated on a different system to the current one, we need to look
in a sysroot for the various shared objects.

For example, we might be looking at a core file from an ARM system
using elfutils running on an x86 host.

This change adds a new function, dwfl_set_sysroot(), which then
gets used when searching for libraries and binaries.

Signed-off-by: Luke Diamand <ldiamand@roku.com>
Signed-off-by: Michal Sekletar <msekleta@redhat.com>
12 months agoreadelf: Fix memory leak in print_hash_info()
Maks Mishin [Mon, 1 Jul 2024 21:05:34 +0000 (00:05 +0300)] 
readelf: Fix memory leak in print_hash_info()

Signed-off-by: Maks Mishin <maks.mishinFZ@gmail.com>
13 months agoelfutils.spec.in: Package elf32_* and elf64_* man pages
Aaron Merey [Fri, 28 Jun 2024 19:46:02 +0000 (15:46 -0400)] 
elfutils.spec.in: Package elf32_* and elf64_* man pages

Previously only elf_* man pages were included during rpmbuild.

Signed-off-by: Aaron Merey <amerey@redhat.com>
13 months agoAdd man pages for some libelf functions
Aaron Merey [Thu, 27 Jun 2024 00:22:39 +0000 (20:22 -0400)] 
Add man pages for some libelf functions

Add man pages for elf32_getehdr.3, elf64_getehdr.3, elf_errmsg.3,
elf_errno.3 and elf_version.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
13 months agoar, ranlib: Don't double close file descriptors
Mark Wielaard [Sat, 22 Jun 2024 23:29:42 +0000 (01:29 +0200)] 
ar, ranlib: Don't double close file descriptors

Found by GCC14 -Wanalyzer-fd-double-close.

close always closes the given file descriptor even on error. So don't
try to close a file descriptor again on error (even on EINTR). This
could be bad in a multi-threaded environment.

      * src/ar.c (do_oper_extract): Call close and set newfd to -1.
      (do_oper_delete): Likewise.
      (do_oper_insert): Likewise.
      * src/ranlib.c (handle_file): Likewise.

Signed-off-by: Mark Wielaard <mark@klomp.org>
13 months agodebuginfod-client: Don't leak id/version with duplicate os-release entries
Mark Wielaard [Sat, 22 Jun 2024 23:22:54 +0000 (01:22 +0200)] 
debuginfod-client: Don't leak id/version with duplicate os-release entries

Found by GCC14 -Wanalyzer-double-free.

If the os-release file would contain multiple ID or VERSION_ID entries
we would leak the originally parsed one. Fix by seeing whether id or
version is already set and ignore any future entries.

* debuginfod/debuginfod-client.c (add_default_headers): Check
whether id or version is already set before resetting them.

Signed-off-by: Mark Wielaard <mark@klomp.org>
13 months agolibelf: elf32_getshdr might leak section header when out of memory
Mark Wielaard [Sat, 22 Jun 2024 23:09:29 +0000 (01:09 +0200)] 
libelf: elf32_getshdr might leak section header when out of memory

Found by GCC -fanalyzer.

When allocating the notcvt buffer fails we leak the shdr. goto
free_and_out on malloc failure.

     * libelf/elf32_getshdr.c (load_shdr_wrlock): goto
             free_and_out on second malloc failure.

Signed-off-by: Mark Wielaard <mark@klomp.org>
13 months agolibdwfl: Make sure mapped is always set in unzip
Mark Wielaard [Sat, 22 Jun 2024 22:52:06 +0000 (00:52 +0200)] 
libdwfl: Make sure mapped is always set in unzip

Found by GCC14 -Wanalyzer-null-argument.

When unzip is called with mapped NULL, but *_whole not NULL, *_whole
contains the first part of the input. But we check against mapped to
make sure the MAGIC bytes are there.

This only worked because this code path was never taken, unzip is
currently always called with *_whole being NULL.

  * libdwfl/gzip.c (unzip): Set mapped = state.input_buffer
          when *whole is not NULL.

Signed-off-by: Mark Wielaard <mark@klomp.org>
13 months agodoc: Always distribute all man pages
Mark Wielaard [Tue, 11 Jun 2024 16:48:49 +0000 (18:48 +0200)] 
doc: Always distribute all man pages

dist targets shouldn't depend on configure conditionals.

     * doc/Makefile.am: Remove DEBUGINFOD and LIBDEBUGINFOD from
     dist targets. Add comments about which man pages go into which
     section.

Signed-off-by: Mark Wielaard <mark@klomp.org>
13 months agoPR31866: reenable --enable-libdebuginfod=dummy
Frank Ch. Eigler [Sat, 8 Jun 2024 17:31:09 +0000 (13:31 -0400)] 
PR31866: reenable --enable-libdebuginfod=dummy

Tweak configure.ac to support $subject again.  Also tweak
debuginfod-find.c to not unconditionally include json-c.h, since it
may just be compiled in "dummy" mode, sans such prerequisites.  It
turns out debuginfod-find fails at run time very early in such a
configuration, long before it gets to jsonic activities.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
13 months agoUpdate code of conduct
Aaron Merey [Tue, 28 May 2024 19:29:04 +0000 (15:29 -0400)] 
Update code of conduct

Adopt a new code of conduct based on the Contributor Covenant.

See the new CONDUCT file for more information.

Signed-off-by: Aaron Merey <amerey@redhat.com>
13 months agorework debuginfod configury
Frank Ch. Eigler [Mon, 3 Jun 2024 22:14:52 +0000 (18:14 -0400)] 
rework debuginfod configury

Rework the top level configure.ac to systematize the
debuginfod-related checks, inferences, rejections,
and configuration outputs.

Tested by hand on a F39 machine, installing/uninstalling
the various dependencies one at a time, and rerunning
the configury with / without --enable-*debuginfod* flags.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
13 months agodebuginfod-client tweak for alma buildbot
Frank Ch. Eigler [Tue, 4 Jun 2024 15:17:17 +0000 (11:17 -0400)] 
debuginfod-client tweak for alma buildbot

Tweak a switch/case statement for gcc8 compatibility.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
13 months agoPR29472: debuginfod: add metadata query webapi, C api, client
Frank Ch. Eigler [Mon, 31 Oct 2022 21:40:01 +0000 (17:40 -0400)] 
PR29472: debuginfod: add metadata query webapi, C api, client

This patch extends the debuginfod API with a "metadata query"
operation.  It allows clients to request an enumeration of file names
known to debuginfod servers, returning a JSON response including the
matching buildids.  This lets clients later download debuginfo for a
range of versions of the same named binaries, in case they need to to
prospective work (like systemtap-based live-patching).  It also lets
server operators implement prefetch triggering operations for popular
but slow debuginfo slivers like kernel vdso.debug files on fedora.

Implementation requires a modern enough json-c library, namely 0.11,
which dates from 2014.  Without that, debuginfod client/server bits
will refuse to build.

% debuginfod-find metadata file /bin/ls
% debuginfod-find metadata glob "/usr/local/bin/c*"

Refactored several functions in debuginfod-client.c, because the
metadata search logic is different for multiple servers (merge all
responses instead of first responder wins).

Documentation and testing are included.

Signed-off-by: Ryan Goldberg <rgoldber@redhat.com>
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
14 months agoreadelf: add pretty printing for FDO Dlopen Metadata note
Luca Boccassi [Fri, 10 May 2024 21:58:02 +0000 (22:58 +0100)] 
readelf: add pretty printing for FDO Dlopen Metadata note

The node ID and the string format are now fixed, even if the content
of the string might change, it will still be a string.

     * libebl/eblobjnote.c (ebl_object_note): Handle both type
     being NT_FDO_PACKAGING_METADATA or NT_FDO_DLOPEN_METADATA when
     name is "FDO".
     * libebl/eblobjnotetypename.c (ebl_object_note_type_name): Handle
     "FDO" name and type NT_FDO_DLOPEN_METADATA.

Signed-off-by: Luca Boccassi <bluca@debian.org>
14 months agolibelf: Sync elf.h from glibc
Mark Wielaard [Fri, 31 May 2024 12:25:27 +0000 (14:25 +0200)] 
libelf: Sync elf.h from glibc

* libelf/elf.h: Adds AT_HWCAP{3,4}, NT_FDO_DLOPEN_METADATA
and R_LARCH_TLS_DESC{32,64}.

Signed-off-by: Mark Wielaard <mark@klomp.org>
14 months agoreadelf: Fix printing of DW_FORM_strx and DW_MACRO parsing
Mark Wielaard [Sat, 4 May 2024 21:34:24 +0000 (23:34 +0200)] 
readelf: Fix printing of DW_FORM_strx and DW_MACRO parsing

print_form_data didn't take the offset_len (4 or 8 bytes) into account
causing the wrong entry to be read from .debug_str_offsets.
print_debug_macro_section did sanity checking before calling
print_form_data, which does sanity checking itself. The sanity check
for DW_FORM_strx was wrong in print_debug_macro_section (but correct
in print_form_data).

Add a new testfile for run-readelf-macro.sh, this one compiled with
clang -gdwarf-5 -fdebug-macro.

      * src/readelf.c (print_form_data): Multiply by offset_len for
      strx_val.
      (print_debug_macro_section): Remove sanity checks before calling
      print_form_data.
      * tests/testfileclangmacro.bz2: New testfile.
      * tests/Makefile.am (EXTRA_DIST): Add testfileclangmacro.bz2.
      * tests/run-readelf-macro.sh: Add testfileclangmacro output.

Signed-off-by: Mark Wielaard <mark@klomp.org>
14 months agoSupport nullglob in profile.sh.in
Frank Ch. Eigler [Mon, 13 May 2024 15:07:32 +0000 (11:07 -0400)] 
Support nullglob in profile.sh.in

Don't block on stdin when /etc/debuginfod/*.certpath expands to nothing.

Signed-off-by: Andreas Schwab <schwab@suse.de>
14 months agoar: Replace one alloca use by xmalloc
Mark Wielaard [Tue, 30 Apr 2024 14:39:17 +0000 (16:39 +0200)] 
ar: Replace one alloca use by xmalloc

This alloca use is inside a lexical block and is used to replace one
element of argv. Use a function local variable, xmalloc and free to
make memory usage pattern more clear.

    * src/ar.c (main): Move newp char pointer declaration up.
    Use xmalloc to allocate space. free at end of main.

Signed-off-by: Mark Wielaard <mark@klomp.org>
14 months agoconfig/Makefile.am: Modify profile.fish in all-local
Aaron Merey [Fri, 10 May 2024 21:46:24 +0000 (17:46 -0400)] 
config/Makefile.am: Modify profile.fish in all-local

Fish shell scripts do not support bracketed variables.
config/Makefile.am removes brackets from a variable in
config/fish.profile in order to prevent an error when running the
script.

Currently the brackets are removed during make install.  This causes
testsuite failures if make check is run before make install.

Fix this by removing the brackets in all-local instead of
install-data-local.

Signed-off-by: Aaron Merey <amerey@redhat.com>
14 months agodebuginfod: PR28204 config/profile.fish.in
Aaron Merey [Fri, 10 May 2024 15:24:05 +0000 (11:24 -0400)] 
debuginfod: PR28204 config/profile.fish.in

Extend config/profile.fish.in for DEBUGINFOD_IMA_CERT_PATH.

Signed-off-by: <Aaron Merey <amerey@redhat.com>
14 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:enforcing    require every file to be correctly signed

The default is ima:ignore mode.  In ima:enforcing mode, section
queries are forced to be entire-file downloads, as it is not
possible to crypto-verify just sections.

IMA signatures are verified against a set of signing certificates.
These are normally published by distributions.  The environment
variable $DEBUGINFOD_IMA_CERT_PATH contains a colon-separated path for
finding DER or PEM formatted certificates / public keys.  These
certificates are assumed trusted.  The profile.d scripts transcribe
/etc/debuginfod/*.certdir files into that variable.

As for implementation:

* configure.ac: Add --enable-debuginfod-ima-verification parameter.
  Add --enable-default-ima-cert-path=PATH parameter.
  Check for libimaevm (using headers only).

* config/Makefile.am: Install defaults into /etc files.
* config/profile.{csh,sh}.in: Process defaults into env variables.
* config/elfutils.spec.in: Add more buildrequires.

* debuginfod/debuginfod.cxx (handle_buildid_r_match): Added extraction of the
  per-file IMA signature for the queried file and store in http header.
  (find_globbed_koji_filepath): New function.
  (parse_opt): New flag --koji-sigcache.
* debuginfod/debuginfod-client.c (debuginfod_query_server): Added policy for
  validating IMA signatures
  (debuginfod_validate_imasig): New function, with friends.
* debuginfod/debuginfod.h.in: Added DEBUGINFOD_IMA_CERT_PATH_ENV_VAR.
* debuginfod/Makefile.am: Add linker flags for rpm and crypto.

* doc/debuginfod-client-config.7: Document DEBUGINFOD_IMA_CERT_PATH,
  update DEBUGINFOD_URLS.
* doc/debuginfod.8: Document --koji-sigcache.
* doc/debuginfod-find.1, doc/debuginfod_find_debuginfo.3: Update SECURITY.

* tests/run-debuginfod-ima-verification.sh: New test.
* tests/debuginfod-ima: Some new files for the tests.
* tests/Makefile.am: run/distribute them.

Signed-off-by: Ryan Goldberg <rgoldber@redhat.com>
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
14 months agoMakefile.am: Avoid code duplication
Aaron Merey [Thu, 9 May 2024 23:17:20 +0000 (19:17 -0400)] 
Makefile.am: Avoid code duplication

Parameterize lcov/genhtml option ignore-errors in order to avoid code
duplication.

Signed-off-by: Aaron Merey <amerey@redhat.com>
14 months agoFix 'make coverage' when used with lcov version 2.0+
Aaron Merey [Mon, 6 May 2024 20:30:46 +0000 (16:30 -0400)] 
Fix 'make coverage' when used with lcov version 2.0+

Starting with version 2.0, various lcov warnings now trigger an error
exit.  This results in 'make coverage' terminating before completion.

Fix this by invoking lcov and genhtml with --ignore-errors to prevent
the error exit when version 2.0+ is in use.

Manually tested by running elfutils-htdocs/update-coverage.sh with
lcov 1.14 and 2.0.

Signed-off-by: Aaron Merey <amerey@redhat.com>
15 months agoconfig/profile.fish.in: Prevent bracketed variables and unmatched wildcard errors
Aaron Merey [Tue, 16 Apr 2024 15:49:43 +0000 (11:49 -0400)] 
config/profile.fish.in: Prevent bracketed variables and unmatched wildcard errors

Fish does not support bracketed variables in scripts.  Remove brackets
from the variable ${prefix} in profile.fish before installation to
prevent this error.

Fish also raises an error for unmatched wildcards, except for special
cases like the set command.  Use a wildcard to match .urls files using
the set command instead of cat to prevent an unmatched wildcard error
when no .urls files are found.

Signed-off-by: Aaron Merey <amerey@redhat.com>
15 months agotests/.gitignore: Use correct spelling for get-files-define-file
Aaron Merey [Tue, 16 Apr 2024 15:51:26 +0000 (11:51 -0400)] 
tests/.gitignore: Use correct spelling for get-files-define-file

Replace get-files-define_file with get-files-define-file.

Signed-off-by: Aaron Merey <amerey@redhat.com>
15 months agoPR31620: debuginfod-client.c: Test for https support in libcurl
Norbert Lange [Fri, 12 Apr 2024 20:03:08 +0000 (22:03 +0200)] 
PR31620: debuginfod-client.c: Test for https support in libcurl

libcurl will fail if a protocol is requested that is not available.

Signed-off-by: Norbert Lange <nolange79@gmail.com>
15 months agoPR31637: debuginfod-find -v SIGSEGV
Frank Ch. Eigler [Fri, 12 Apr 2024 21:39:21 +0000 (17:39 -0400)] 
PR31637: debuginfod-find -v SIGSEGV

Correct an off-by-one error in argv parsing.

Reported-By: <nolange79@gmail.com>
Signed-Off-By: Frank Ch. Eigler <fche@redhat.com>
15 months agolibdw: dwarf_getsrcfiles should not imply dwarf_getsrclines
Aaron Merey [Mon, 25 Mar 2024 19:57:25 +0000 (15:57 -0400)] 
libdw: dwarf_getsrcfiles should not imply dwarf_getsrclines

dwarf_getsrcfiles causes line data to be read in addition to file data.
This is wasteful for programs which only need file or directory names.
Debuginfod server is one such example.

Fix this by moving the srcfile reading in read_srclines into a separate
function read_srcfiles.  This change improves debuginfod server's max
resident set size by up to 75% during rpm indexing.

* libdw/dwarf_getsrcfiles.c (dwarf_getsrcfiles): Replace
dwarf_getsrclines and __libdw_getsrclines with
__libdw_getsrcfiles.
* libdw/dwarf_getsrclines.c (read_line_header): New function.
(read_srcfiles): New function.
(read_srclines): Move srcfile reading into read_srcfiles.
Add parameter to use cached srcfiles if available.
Also merge srcfiles with any files from DW_LNE_define_file.
(__libdw_getsrclines): Changed to call get_lines_or_files.
(__libdw_getsrcfiles): New function.  Calls get_lines_or_files.
(get_lines_or_files): New function based on the old
__libdw_getsrclines.  Call read_srcfiles if linesp is NULL,
otherwise call read_srclines.  Pass previously read srcfiles
to read_srclines if available.
* libdw/dwarf_macro_getsrcfiles.c (dwarf_macro_getsrcfiles):
Replace __libdw_getsrclines with __libdw_getsrcfiles.
* libdw/libdwP.h (__libdw_getsrcfiles): New declaration.
* tests/.gitignore: Add new test binary.
* tests/get-files.c: Verify that dwarf_getsrcfiles does
not cause srclines to be read.
* tests/get-lines.c: Verify that srclines can be read
after srcfiles have been read.
* tests/Makefile.am: Add new testfiles.
* tests/get-files-define-file.c: Print file names before
and after reading DW_LNE_define_file.
* tests/run-get-files.sh: Add get-files-define-file test.
* tests/testfile-define-file.bz2: New testfile.  Copy of
testfile36.debug but with a line program consisting of two
DW_LNE_define_file opcodes.

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

Signed-off-by: Aaron Merey <amerey@redhat.com>
15 months agobackends: Add register_info, return_value_location, core_note on mips
Ying Huang [Tue, 5 Mar 2024 09:51:22 +0000 (17:51 +0800)] 
backends: Add register_info, return_value_location, core_note on mips

* backends/Makefile.am (mips_SRCS): Add mips_regs.c,
mips_retval.c and mips_corenote.c.
* backends/mips_init.c (mips_init): HOOK register_info,
return_value_location and core_note.
* backends/mips_corenote.c: New file.
* backends/mips_regs.c: Likewise.
* backends/mips_retval.c: Likewise.

Signed-off-by: Ying Huang <ying.huang@oss.cipunited.com>
15 months agostack: Fix stack unwind failure on mips
Ying Huang [Tue, 5 Mar 2024 09:51:21 +0000 (17:51 +0800)] 
stack: Fix stack unwind failure on mips

Add abi_cfi, set_initial_registers_tid, unwind on mips.

* backends/Makefile.am (mips_SRCS): Add mips_initreg.c,
mips_cfi.c and mips_unwind.c.
* backends/mips_init.c (mips_init): HOOK abi_cfi, unwind and
set_initial_registers_tid. Set frame_nregs to 71.
* backends/mips_cfi.c: New file.
* backends/mips_initreg.c: Likewise.
* backends/mips_unwind.c: Likewise.

Signed-off-by: Ying Huang <ying.huang@oss.cipunited.com>
15 months agoHexagon: implement machine flag check
Matheus Tavares Bernardino [Thu, 4 Apr 2024 17:19:40 +0000 (14:19 -0300)] 
Hexagon: implement machine flag check

This fixes the "invalid machine flag" error from eu-elflint when passing
hexagon binaries.

        * backends/hexagon_init.c (hexagon_init): Hook
        machine_flag_check
        * backends/hexagon_symbol.c (hexagon_machine_flag_check):
new function
        * libelf/elf-knowledge.h: add EF_HEXAGON_TINY constant

Signed-off-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
15 months agoAdd support for Hexagon
Matheus Tavares Bernardino [Tue, 2 Apr 2024 19:55:45 +0000 (16:55 -0300)] 
Add support for Hexagon

This implements initial support for the Hexagon architecture. The
Hexagon ABI spec can be seen at
https://lists.llvm.org/pipermail/llvm-dev/attachments/20190916/21516a52/attachment-0001.pdf

A hello_hexagon.ko test is also added.

$ head tests/test-suite.log
  [...]
  # TOTAL: 275
  # PASS:  269
  # SKIP:  6
  # XFAIL: 0
  # FAIL:  0
  # XPASS: 0
  # ERROR: 0

$ cat tests/run-strip-reloc-ko.sh.log
  [...]
  runtest hello_hexagon.ko
  PASS run-strip-reloc-ko.sh (exit status: 0)

* backends/Makefile.am (modules): Add hexagon.
(hexagon_SRCS): New var for hexagon_init.c and hexagon_symbol.c.
(libebl_backends_a_SOURCES): Add hexagon_SRCS.
* backends/hexagon_init.c: New file.
* backends/hexagon_reloc.def: Likewise.
* backends/hexagon_symbol.c: Likewise.
* libebl/eblopenbackend.c (hexagon_init): Declare.
(machines): Add hexagon.
* libelf/elf-knowledge.h: Add hexagon e_flags values, section
        indices and and relocs.
* src/elflint.c (valid_e_machine): Add EM_QDSP6.
* tests/Makefile.am (EXTRA_DIST): Add hello_hexagon.ko.bz2.
* tests/hello_hexagon.ko.bz2: New test file.
* tests/run-strip-reloc-ko.sh: Add hello_hexagon.ko.

Signed-off-by: Matheus Tavares Bernardino <quic_mathbern@quicinc.com>
15 months agotests, config: Add more .gitignore files
Mark Wielaard [Thu, 28 Mar 2024 23:43:08 +0000 (00:43 +0100)] 
tests, config: Add more .gitignore files

Some new tests and one configure file weren't in .gitignore. Also
we made a copy of libelf.h in tests/ which should be an symlink.

* config/.gitignore: Add profile.fish.
* tests/.gitignore: Add funcretval_test_struct, libelf.h
and system-elf-gelf-test.
* tests/Makefile.am (libelf.h): Make symlink instead of copy.

Signed-off-by: Mark Wielaard <mark@klomp.org>
16 months agoSupport Mips architecture
Ying Huang [Tue, 5 Mar 2024 09:51:17 +0000 (17:51 +0800)] 
Support Mips architecture

* backends/Makefile.am (modules): Add mips.
(mips_SRCS): New var for mips_init.c mips_symbol.c.
(libebl_backends_a_SOURCES): Add mips_SRCS.
* backends/mips_init.c: New file.
* backends/mips_reloc.def: Likewise.
* backends/mips_symbol.c: Likewise.
* libebl/eblopenbackend.c (mips_init): Declare.
(machines): Add mips.
* libelf/libelfP.h: Add ELF64_MIPS_R_TYPE{1,2,3}

Signed-off-by: Ying Huang <ying.huang@oss.cipunited.com>
16 months agotests: Use bash for run-debuginfod-client-profile.sh
Mark Wielaard [Wed, 27 Mar 2024 14:25:16 +0000 (15:25 +0100)] 
tests: Use bash for run-debuginfod-client-profile.sh

The test uses set -o pipefail which is a bashism and so the test fails
on systems where /bin/sh isn't bash.

    * tests/run-debuginfod-client-profile.sh: Use bash.

Signed-off-by: Mark Wielaard <mark@klomp.org>
16 months agoconfig: Make sure profile.sh succeeds with set -e and set -o pipefail
Mark Wielaard [Tue, 26 Mar 2024 20:42:39 +0000 (21:42 +0100)] 
config: Make sure profile.sh succeeds with set -e and set -o pipefail

profile.sh might fail with set -o pipefail because:

cat /dev/null "${prefix}/etc/debuginfod"/*.urls 2>/dev/null | tr '\n' ' '

might fail when there isn't an *.urls file the first command in the
pipe fails (the 2>/dev/null is there to hide that failure).

This can be fixed by adding || : at the end.

This works because : always succeeds and  produces no outpur which is
what the script expects when the command would fail.

Also add a new testcase that runs profile.sh with bout  set -e
and set -o pipefail.

* config/profile.sh.in: Add || : at end of pipe.
* tests/run-debuginfod-client-profile.sh: New test.
* tests/Makefile.am (TESTS): Add run-debuginfod-client-profile.sh.
(EXTRA_DIST): Likewise.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
16 months agoconfig: Add debuginfod.fish to elfutils.spec as config file.
Mark Wielaard [Sun, 24 Mar 2024 17:46:02 +0000 (18:46 +0100)] 
config: Add debuginfod.fish to elfutils.spec as config file.

* config/elfutils.spec.in (debuginfod-client): %files add
%{_datadir}/fish/vendor_conf.d/debuginfod.fish as config file.

Signed-off-by: Mark Wielaard <mark@klomp.org>
16 months agoconfig: Add profile script for fish shell
Frederik “Freso” S. Olesen [Fri, 22 Mar 2024 17:21:04 +0000 (18:21 +0100)] 
config: Add profile script for fish shell

Add support for setting $DEBUGINFOD_URLS automatically in the fish shell
similar to the profile scripts for POSIX and csh shells.

Makefile is set to install this into fish’s $XDG_DATA_DIRS vendor
directory instead of under /etc:
https://fishshell.com/docs/current/language.html#configuration-files

* config/profile.fish.in: Set $DEBUGINFOD_URLS in fish shells.
* configure.ac, config/Makefile.am: Include profile.fish in
  install and uninstall targets.

Signed-off-by: Frederik “Freso” S. Olesen <freso.dk@gmail.com>
16 months agoriscv: Partial implementation of flatten_aggregate
Mark Wielaard [Tue, 19 Mar 2024 22:43:10 +0000 (22:43 +0000)] 
riscv: Partial implementation of flatten_aggregate

dwfl_module_return_value_location would fail on riscv for functions
which return a (small) struct. This patch implements the simplest
cases of flatten_aggregate in backends/riscv_retval.c. It just handles
structs containing one or two members of the same base type which fit
completely or in pieces in one or two general or floating point
registers.

It also adds a specific test case run-funcretval-struct.sh containing
small structs of ints, longs, floats and doubles. All these testscases
now work for riscv. There is already a slightly more extensive
testcase for this in tests/run-funcretval.sh but that only has a
testcase for aarch64.

 * backends/riscv_retval.c (flatten_aggregate_arg): Implement
         for the simple cases where we have a struct with one or two
         members of the same base type.
 (pass_by_flattened_arg): Likewise. Call either
 pass_in_gpr_lp64 or pass_in_fpr_lp64d.
 (riscv_return_value_location_lp64ifd): Call
 flatten_aggregate_arg including size.
 * tests/Makefile.am (TESTS): Add run-funcretval-struct.sh
 and run-funcretval-struct-native.sh.
 (check_PROGRAMS): Add funcretval_test_struct.
 (funcretval_test_struct_SOURCES): New.
 (EXTRA_DIST): Add run-funcretval-struct.sh,
 funcretval_test_struct_riscv.bz2 and
 run-funcretval-struct-native.sh.
 * tests/funcretval_test_struct_riscv.bz2: New test binary.
 * tests/run-funcretval-struct-native.sh: New test.
 * tests/run-funcretval-struct.sh: Likewise.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
16 months agosrcfiles: fix unused variable BUFFER_SIZE
Jose Quaresma [Tue, 19 Mar 2024 10:34:33 +0000 (10:34 +0000)] 
srcfiles: fix unused variable BUFFER_SIZE

The const variable BUFFER_SIZE is used only on the zip_files
function witch is only available with LIBARCHIVE.

| ../../elfutils-0.191/src/srcfiles.cxx:81:18: error: unused variable 'BUFFER_SIZE' [-Werror,-Wunused-const-variable]
|    81 | constexpr size_t BUFFER_SIZE = 8192;
|       |                  ^~~~~~~~~~~

Signed-off-by: Jose Quaresma <jose.quaresma@foundries.io>
16 months agoPR31103: git authorship correction
Di Chen [Tue, 19 Mar 2024 11:04:28 +0000 (07:04 -0400)] 
PR31103: git authorship correction

16 months agoPR31103: debuginfod: periodically call malloc_trim(0)
Frank Ch. Eigler [Mon, 18 Mar 2024 20:06:02 +0000 (16:06 -0400)] 
PR31103: debuginfod: periodically call malloc_trim(0)

Add malloc_trim() for releasing memory which is allocated for
temporary purposes, e.g. answering queries, adding data to the
database during scans.  This patch just adds one call after the groom
cycle, but others could be added around webapi query handling or
scanning ops too.

Signed-off-by: Di Chen <dichen@redhat.com>
16 months agodebuginfod: Remove unused variable
Khem Raj [Sat, 9 Mar 2024 23:54:35 +0000 (15:54 -0800)] 
debuginfod: Remove unused variable

Recent commit acd9525e9 has removed all references to max_fds
therefore remove it, moreover clang18 is happier

| ../../elfutils-0.191/debuginfod/debuginfod.cxx:1448:8: error: private field 'max_fds' is not used [-Werror,-Wunused-private-field]
|  1448 |   long max_fds;
|       |        ^
| 1 error generated.

Signed-off-by: Khem Raj <raj.khem@gmail.com>
16 months agolibdw: Don't use INTUSE in libdwP.h str_offsets_base_off
Mark Wielaard [Sat, 2 Mar 2024 23:45:34 +0000 (00:45 +0100)] 
libdw: Don't use INTUSE in libdwP.h str_offsets_base_off

readelf.c cheats and include libdwP.h, which is an internal only
header of libdw. It really shouldn't do that, but there are some
internals that readelf currently needs. The str_offsets_base_off
function used by readelf uses INTUSE when calling dwarf_get_units.
This is a micro optimization useful inside libdw so a public
function can be called directly, skipping a PLT call. This can
cause issues linking readelf since it might not be able to call
the internal function, since readelf.c isn't part of libdw itself.
Just drop the INTUSE.

* libdw/libdwP.h (str_offsets_base_off): Don't use INTUSE
when calling dwarf_get_units.

Signed-off-by: Mark Wielaard <mark@klomp.org>
17 months agoPrepare for 0.191 elfutils-0.191
Aaron Merey [Fri, 1 Mar 2024 17:31:49 +0000 (12:31 -0500)] 
Prepare for 0.191

Set version to 0.191
Update NEWS, elfutils.spec.in and printversion.c.
Regenerate po/*.po files.

Signed-off-by: Aaron Merey <amerey@redhat.com>
17 months agoGPG-KEY: Add key for Aaron Merey
Mark Wielaard [Fri, 1 Mar 2024 17:10:33 +0000 (18:10 +0100)] 
GPG-KEY: Add key for Aaron Merey

Signed-off-by: Mark Wielaard <mark@klomp.org>
17 months agolibdw: Initialize tu_offset in __libdw_package_index
Mark Wielaard [Fri, 1 Mar 2024 16:05:16 +0000 (17:05 +0100)] 
libdw: Initialize tu_offset in __libdw_package_index

dwarf_cu_dwp_section_info.c: In function ‘__libdw_package_index’:
dwarf_cu_dwp_section_info.c:306:25: error: ‘tu_offset’ may be used uninitialized [-Werror=maybe-uninitialized]
  306 |               tu_offset += tu_index->section_count * 4;
      |               ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dwarf_cu_dwp_section_info.c:268:28: note: ‘tu_offset’ was declared here
  268 |       const unsigned char *tu_offset;
      |                            ^~~~~~~~~

Which is the same issue we thought to have fixed by checking for
tu_index != NULL but not all gcc versions seem able to see that.
So just explicitly initialize tu_offset to NULL. We keep the older
check, so the NULL pointer should never be used.

       * libdw/dwarf_cu_dwp_section_info.c (__libdw_package_index):
       Initialize tu_offset.

Signed-off-by: Mark Wielaard <mark@klomp.org>
17 months agolibdw: Handle overflowed DW_SECT_INFO offsets in DWARF package file indexes
Omar Sandoval [Mon, 26 Feb 2024 19:32:51 +0000 (11:32 -0800)] 
libdw: Handle overflowed DW_SECT_INFO offsets in DWARF package file indexes

Meta uses DWARF package files for our large, statically-linked C++
applications.  Some of our largest applications have more than 4GB in
.debug_info.dwo, but the section offsets in .debug_cu_index and
.debug_tu_index are 32 bits; see the discussion here [1].  We
implemented a workaround/extension for this in LLVM.  Implement the
equivalent in libdw.

To test this, we need files with more than 4GB in .debug_info.dwo.  I
created these artificially by editing GCC's assembly output.  They
compress down to 6KB.  I test them from run-large-elf-file.sh to take
advantage of the existing checks for large file support.

1: https://discourse.llvm.org/t/dwarf-dwp-4gb-limit/63902.

  * libdw/dwarf_end.c (dwarf_package_index_free): New function.
* tests/testfile-dwp-4-cu-index-overflow.bz2: New test file.
* tests/testfile-dwp-4-cu-index-overflow.dwp.bz2: New test file.
* tests/testfile-dwp-5-cu-index-overflow.bz2: New test file.
* tests/testfile-dwp-5-cu-index-overflow.dwp.bz2: New test file.
* tests/testfile-dwp-cu-index-overflow.source: New file.
* tests/run-large-elf-file.sh: Check
testfile-dwp-5-cu-index-overflow and
testfile-dwp-4-cu-index-overflow.

Signed-off-by: Omar Sandoval <osandov@fb.com>
17 months agotests/run-getsrc-die.sh: Skip tests if objcopy fails
Aaron Merey [Fri, 1 Mar 2024 00:46:09 +0000 (19:46 -0500)] 
tests/run-getsrc-die.sh: Skip tests if objcopy fails

run-getsrc-die.sh uses objcopy to remove .debug_aranges from testfiles.
Depending how objcopy is built, it may fail to recognize the format of
the testfiles.  Skip the remaining tests if objcopy fails.

Signed-off-by: Aaron Merey <amerey@redhat.com>