]> git.ipfire.org Git - thirdparty/elfutils.git/log
thirdparty/elfutils.git
4 months agolibdwfl: add dwfl_thread_ebl users/serhei/eu-stacktrace.v1
Serhei Makarov [Thu, 27 Feb 2025 19:38:55 +0000 (14:38 -0500)] 
libdwfl: add dwfl_thread_ebl

Exposing the Ebl * here allows libdwfl users to access the
ebl_set_initial_regs_sample callback for a given process.

* libdw/libdw.map: Add dwfl_thread_ebl.
* libdwfl/dwfl_frame.c (dwfl_thread_ebl): New function.
* libdwfl/dwfl_frame.c (dwfl_thread_ebl): New function.

4 months agoDRAFT eu-stacktrace: use dwfl_process_tracker_find_pid
Serhei Makarov [Fri, 14 Feb 2025 21:57:14 +0000 (16:57 -0500)] 
DRAFT eu-stacktrace: use dwfl_process_tracker_find_pid

Will need to switch to storing statistics in
dwfl->process->callbacks_arg? Requires a more careful design for how
table entries are replaced when a pid is reused.

* src/stacktrace.c (sysprof_init_dwfl): New function.
  (sysprof_find_dwfl): Rename the existing sysprof_init_dwfl.
  Also use dwfl_process_tracker_find_pid with callback.
  (sysprof_unwind_cb): Rename the existing sysprof_init_dwfl.

4 months agofixup for DRAFT 97df2fc6: elftab should retain Elf * via refcount
Serhei Makarov [Fri, 14 Feb 2025 21:45:46 +0000 (16:45 -0500)] 
fixup for DRAFT 97df2fc6: elftab should retain Elf * via refcount

* libdwfl/dwfl_module_getdwarf.c (open_elf): Increment Elf * refcount.
* libdwfl/dwfl_process_tracker_find_elf.c (dwfl_process_tracker_find_elf):
  Increment Elf * refcount.

4 months agofixup for DRAFT e38ce78: should return ent->fd
Serhei Makarov [Fri, 14 Feb 2025 21:43:36 +0000 (16:43 -0500)] 
fixup for DRAFT e38ce78: should return ent->fd

Previous fixup commit erroneously removed this line.

4 months agoDRAFT libdwfl: add dwfl_process_tracker_find_pid
Serhei Makarov [Fri, 14 Feb 2025 15:02:49 +0000 (10:02 -0500)] 
DRAFT libdwfl: add dwfl_process_tracker_find_pid

* libdwfl/libdwfl.h (dwfl_process_tracker_find_pid): New function.
* libdwfl/dwfl_process_tracker.h (dwfl_process_tracker_find_pid):
  New function; find a Dwfl in the dwfltab or create one using the
  provided callback.
* libdw/libdw.map: Add dwfl_process_tracker_find_pid.

4 months agoDRAWF libdwfl: Dwfl* caching via dwfl_process_tracker
Serhei Makarov [Thu, 13 Feb 2025 21:31:54 +0000 (16:31 -0500)] 
DRAWF libdwfl: Dwfl* caching via dwfl_process_tracker

* libdwfl/libdwflP.h (dwfltracker_dwfl_info): New typedef, provides
  indirection to allow a dwfltab entry to be invalidated.
  (struct Dwfl_Process_Tracker): add dwfltab.
  (__libdwfl_add_dwfl_to_tracker): New function.
  (__libdwfl_remove_dwfl_from_tracker): New function.
* libdwfl/dwfl_process_tracker_dwfltab.h: New file.
* libdwfl/dwfl_process_tracker_dwfltab.c: New file.
* libdwfl/dwfl_process_tracker.c (dwfl_process_tracker_begin): Init dwfltab.
  (__libdwfl_add_dwfl_to_tracker): New function; add dwfl to dwfltab.
  (__libdwfl_remove_dwfl_from_tracker): New function; invalidate dwfl entry.
  (dwfl_process_tracker_end): Clean up dwfltab.
* libdwfl/dwfl_frame.c (dwfl_attach_state): Call __libdwfl_add_dwfl_to_tracker.
* libdwfl/dwfl_end.c (dwfl_end): Call __libdwfl_remove_dwfl_from_tracker.
* libdwfl/Makefile.am (libdwfl_a_SOURCES): Add dwfl_process_tracker_dwfltab.c.

4 months agofixup for DRAFT e38ce78: switch to using lib/dynamicsizehash_concurrent.c
Serhei Makarov [Fri, 7 Feb 2025 21:45:41 +0000 (16:45 -0500)] 
fixup for DRAFT e38ce78: switch to using lib/dynamicsizehash_concurrent.c

4 months agofixup for DRAFT e38ce78: cache Elf * in open_elf
Serhei Makarov [Mon, 3 Feb 2025 21:45:20 +0000 (16:45 -0500)] 
fixup for DRAFT e38ce78: cache Elf * in open_elf

Caching behaviour is improving. The commented assert still catches
some cases where a redundant Elf * is being created.

* dwfl_module_getdwarf.c (open_elf): Cache file->elf in Dwfl_Process_Tracker.

5 months agoeu-stacktrace: use Dwfl_Process_Tracker for Elf * caching
Serhei Makarov [Tue, 28 Jan 2025 17:27:34 +0000 (12:27 -0500)] 
eu-stacktrace: use Dwfl_Process_Tracker for Elf * caching

* src/stacktrace.c (tracker): New global variable.
  (sample_callbacks): Use dwfl_process_tracker_find_elf for caching.
  (sysprof_init_dwfl): Use dwfl_begin_with_tracker.
  (main): Initialize and clean up tracker.

5 months agoDRAFT libdwfl: Elf* caching via dwfl_process_tracker
Serhei Makarov [Tue, 28 Jan 2025 17:20:36 +0000 (12:20 -0500)] 
DRAFT libdwfl: Elf* caching via dwfl_process_tracker

(Work in progress, based on my testing it's still missing a couple of
pieces in open_elf. Also need to look into using
lib/dynamicsizehash_concurrent.c rather than the boilerplate imitation
here.)

* libdwfl/libdwfl.h (dwfl_process_tracker_find_elf): New function,
  serves as a cached version of the dwfl_linux_proc_find_elf callback.
* libdwfl/libdwflP.h (DWFFL_ELFTAB_ENT_USED): New macro.
  (dwfltracker_elftab_ent): New struct typedef.
  (struct Dwfl_Process_Tracker): Add fields for table of Elf*.
  (__libdwfl_process_tracker_elftab_find): New function.
  (__libdwfl_process_tracker_elftab_mark_used): New function.
* libdwfl/dwfl_process_tracker.c (dwfl_process_tracker_begin): Init elftab.
  (dwfl_process_tracker_end): Free elftab.
  (__libdwfl_process_tracker_elftab_resize): New function.
  (djb2_hash): New function.
  (__libdwfl_process_tracker_elftab_find): New function.
  (__libdwfl_process_tracker_elftab_mark_used): New function.
* libdwfl/dwfl_process_tracker_find_elf.c: New file.
* libdwfl/Makefile.am (libdwfl_a_SOURCES): Add dwfl_process_tracker_find_elf.c.
* libdw/libdw.map: Add dwfl_process_tracker_find_elf.

5 months agolibdwfl: introduce Dwfl_Process_Tracker
Serhei Makarov [Mon, 20 Jan 2025 21:38:42 +0000 (16:38 -0500)] 
libdwfl: introduce Dwfl_Process_Tracker

New data structure to coordinate caching Elf data among multiple Dwfl
structs attached to different processes. Meant to reduce the overhead
for profilers that use elfutils for unwinding.

The caching is well-justified, as the current approach (e.g. in
eu-stacktrace, sysprof-live-unwinder) of creating a separate Dwfl per
process

Initial patch just introduces the struct, to be filled in by the rest
of the patch series.

* libdwfl/libdwfl.h (Dwfl_Process_Tracker): New struct.
  (dwfl_process_tracker_begin): New function.
  (dwfl_begin_with_tracker): New function.
  (dwfl_process_tracker_end): New function.
* libdw/libdw.map: Add new functions.
* libdwfl/libdwflP.h (struct Dwfl_Process_Tracker): New struct.
  (struct Dwfl): Add 'tracker' field.
* libdwfl/Makefile.am (libdwfl_a_SOURCES): Add dwfl_process_tracker.c.
* libdwfl/dwfl_process_tracker.c: New file.
  (dwfl_process_tracker_begin): Initialize the tracker.
  (dwfl_begin_with_tracker): Initialize Dwfl * with specified tracker.
  (dwfl_process_tracker_end): Deallocate the tracker.

6 months agoREADME.eu-stacktrace: link to chergert's sysprof-live-unwinder work
Serhei Makarov [Thu, 5 Dec 2024 21:19:52 +0000 (16:19 -0500)] 
README.eu-stacktrace: link to chergert's sysprof-live-unwinder work

The main fruition of the code so far has been incorporated into
Sysprof project, hence a link to the relevant blog post in our
README. For the time being it's the most direct way of trying out the
work.

6 months agoeu-stacktrace: use libebl register handling api
Serhei Makarov [Thu, 5 Dec 2024 21:16:00 +0000 (16:16 -0500)] 
eu-stacktrace: use libebl register handling api

Change the sample_set_initial_registers callback in eu-stacktrace to
use the proper libebl ebl_set_initial_registers_sample function.

* src/Makefile.am (stacktrace_LDADD): Add libebl.
* src/stacktrace.c (sample_registers_cb): New function,
  though identical to pid_thread_state_registers_cb.
  (sample_set_initial_registers): Invoke
  ebl_set_initial_registers_sample instead of containing
  platform-specific code directly.

6 months agolibebl: api for perf register handling, start with x86_64
Serhei Makarov [Fri, 29 Nov 2024 21:30:43 +0000 (16:30 -0500)] 
libebl: api for perf register handling, start with x86_64

As it happens, Linux perf_events and DWARF can prescribe completely
different layouts for the register file, requiring non-obvious code
for translation. This makes sense to put in libebl if we want
profilers to handle perf sample data with elfutils.

Start with the x86_64 implementation taken from eu-stacktrace. Needs
some additional testing as the code has been generalized to accept
other perf register masks besides the 'preferred' one.

* backends/Makefile.am (x86_64_SRCS): Add x86_64_initreg_sample.c.
* backends/libebl_PERF_FLAGS.h: New file.
* backends/x86_64_initreg_sample.c: New file, implements a generalized
  version of the eu-stacktrace register shuffling for x86_64.
* backends/x86_64_init.c (x86_64_init): Add initialization for
  set_initial_registers_sample, perf_frame_regs_mask.
* libebl/Makefile.am (libebl_a_SOURCES): Add eblinitreg_sample.c.
* libebl/ebl-hooks.h (set_initial_registers_sample): New hook.
* libebl/eblinitreg_sample.c: New file, implements ebl interface to
  set_initial_registers_sample backend hook.
* libebl/libebl.h (ebl_set_initial_registers_sample): New function.
  (ebl_perf_frame_regs_mask): New function.
* libebl/libeblP.h (struct ebl): Add perf_frame_regs_mask field
  giving the preferred register mask.

8 months agoREADME.eu-stacktrace: note env LD_LIBRARY_PATH may be needed
Serhei Makarov [Fri, 18 Oct 2024 21:06:22 +0000 (17:06 -0400)] 
README.eu-stacktrace: note env LD_LIBRARY_PATH may be needed

8 months agoREADME.eu-stacktrace: begin 2nd round of development based on merged code
Serhei Makarov [Fri, 18 Oct 2024 21:02:38 +0000 (17:02 -0400)] 
README.eu-stacktrace: begin 2nd round of development based on merged code

8 months agoconfig/elfutils.spec.in: Add missing wildcard elfutils-0.192
Aaron Merey [Fri, 18 Oct 2024 17:50:38 +0000 (13:50 -0400)] 
config/elfutils.spec.in: Add missing wildcard

Replace %{_mandir}/man3/libelf.3 with %{_mandir}/man3/libelf.3*
to account for possible compression-related file extension.

Signed-off-by: Aaron Merey <amerey@redhat.com>
8 months agoPrepare for 0.192
Aaron Merey [Fri, 18 Oct 2024 17:24:18 +0000 (13:24 -0400)] 
Prepare for 0.192

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

Signed-off-by: Aaron Merey <amerey@redhat.com>
8 months agodoc: Add libelf man page
Aaron Merey [Fri, 18 Oct 2024 04:02:33 +0000 (00:02 -0400)] 
doc: Add libelf man page

Signed-off-by: Aaron Merey <amerey@redhat.com>
8 months agolibelf: Treat elf_memory image as writable users/mark/try-elf_memory
Mark Wielaard [Fri, 18 Oct 2024 14:52:49 +0000 (16:52 +0200)] 
libelf: Treat elf_memory image as writable

There are use cases where the Elf image created by elf_memory is
manipulated, through the libelf interfaces, in place. This doesn't
work anymore since we changed elf_memory to assume the memory is
read-only in elfutils 0.191. commit cc44ac674 ('libelf: Treat
elf_memory as if using ELF_C_READ_MMAP').

The reason for that change was that if elf_memory was given a
read-only memory image then decompressing a section with elf_compress
would crash. Since it directly writes the updated Shdr size. If you do
want to use elf_compress on an Elf created by elf_memory you have make
sure the memory is writable. You can do this for example by using mmap
PROTE_WRITE and MAP_PRIVATE.

* libelf/elf_memory.c (elf_memory): Call
__libelf_read_mmaped_file with ELF_C_READ_MMAP_PRIVATE.
* tests/elfgetzdata.c (main): Use mmap PROT_WRITE and MAP_PRIVATE.

Signed-off-by: Mark Wielaard <mark@klomp.org>
8 months agolibelf: elf_compress doesn't handle multiple elf_newdata chunks correctly
Mark Wielaard [Tue, 20 Aug 2024 15:59:01 +0000 (17:59 +0200)] 
libelf: elf_compress doesn't handle multiple elf_newdata chunks correctly

elf_compress would compress all (new) data chunks, but didn't reset
the section data_list. This would cause extra data to be returned
after decompression or create bad compressed data. Add a new testcase
for this and explicitly zap the scn->data_list before resetting the
elf section raw data after (de)compression.

 * libelf/elf_compress.c (__libelf_reset_rawdata): Cleanup
         scn->data_list.
 * tests/newzdata.c: New testcase.
 * tests/Makefile.am (check_PROGRAMS): Add newzdata.
 (TESTS): Likewise.
 (newzdata_LDADD): New variable.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
8 months agoeu-stacktrace [5/5]: NEWS: add entry for new tool
Serhei Makarov [Tue, 15 Oct 2024 15:39:36 +0000 (11:39 -0400)] 
eu-stacktrace [5/5]: NEWS: add entry for new tool

Signed-off-by: Serhei Makarov <serhei@serhei.io>
8 months agoeu-stacktrace [4/5]: src: add unwind origin diagnostics to eu-stack
Serhei Makarov [Sat, 12 Oct 2024 19:26:06 +0000 (15:26 -0400)] 
eu-stacktrace [4/5]: src: add unwind origin diagnostics to eu-stack

Since we obtain diagnostics about unwind method, another logical place
to show them is in eu-stack.

* src/stack.c (show_unwound_source): New global variable.
  (struct frame): Add unwound_source field.
  (frame_callback): Copy over unwound_source from Dwfl_Frame.
  (print_frame): Take unwound_source string and print it.
  (print_inline_frames): Take unwound_source argument and pass it on,
  except for subsequent frames where we pass the string "inline".
  (print_frames): Take unwound_source field from struct frame and pass
  it on.
  (parse_opt): Add --cfi-type,-c option to set show_unwound_source.
  (main): Ditto.
* tests/run-stack-i-test.sh: Add testcase for --cfi-type.

Signed-off-by: Serhei Makarov <serhei@serhei.io>
8 months agoeu-stacktrace [3/5]: libdwfl: add unwind origin diagnostics
Serhei Makarov [Sat, 12 Oct 2024 15:06:15 +0000 (11:06 -0400)] 
eu-stacktrace [3/5]: libdwfl: add unwind origin diagnostics

Track the method used to unwind each Dwfl_Frame using an enum field
unwound_source; provide access to the field. Then use that in
eu-stacktrace to display the unwind methods used for each process.

This is an important diagnostic to verify how many processes are
adequately covered by the eh_frame unwinder.

* libdw/libdw.map (ELFUTILS_0.192): Add dwfl_frame_unwound_source,
  dwfl_unwound_source_str.
* libdwfl/libdwfl.h (Dwfl_Unwound_Source): New enum.
  (dwfl_frame_unwound_source)
  (dwfl_unwound_source_str): New functions.
* libdwfl/dwfl_frame.c (dwfl_frame_unwound_source)
  (dwfl_unwound_source_str): New functions.
* libdwfl/libdwflP.h: Add INTDECL for dwfl_frame_unwound_source,
  dwfl_unwound_source_str.
  (struct Dwfl_Frame): Add unwound_source field.
* libdwfl/frame_unwind.c (__libdwfl_frame_unwind): Set
  state->unwound_source depending on the unwind method used.
* src/stacktrace.c (struct sysprof_unwind_info): Add last_pid
  field to provide access to the current sample's dwfltab entry.
  (sysprof_unwind_frame_cb): Add unwound_source to the data displayed
  with the show_frames option.
  (sysprof_unwind_cb): Set last_pid when processing a sample.
  (main): Add unwind_source to the data displayed in the final summary
  table.

Signed-off-by: Serhei Makarov <serhei@serhei.io>
8 months agoeu-stacktrace [2/5]: configure.ac: initial version (x86/sysprof only)
Serhei Makarov [Fri, 11 Oct 2024 21:14:41 +0000 (17:14 -0400)] 
eu-stacktrace [2/5]: configure.ac: initial version (x86/sysprof only)

Due to the x86-specific code in the initial version the configury has
significant restrictions. If --enable-stacktrace is not explicitly
provided, then eu-stacktrace will be disabled by default.

The way we test for x86 is a bit unusual. What we actually care about
is that the register file provided by perf_events on the system is an
x86 register file; this is done by checking that <asm/perf_regs.h> is
Linux kernel arch/x86/include/uapi/asm/perf_regs.h.

Once eu-stacktrace is properly portable across architectures,
these grody checks can be simplified. Enablement of the feature
by default depends on a released Sysprof version we can point to
for the patches.

* configure.ac: Add configure checks and conditionals for stacktrace tool.
* src/Makefile.am: Add stacktrace tool conditional on ENABLE_STACKTRACE.

Signed-off-by: Serhei Makarov <serhei@serhei.io>
8 months agoeu-stacktrace [1/5]: src: add eu-stacktrace tool
Serhei Makarov [Fri, 11 Oct 2024 21:05:54 +0000 (17:05 -0400)] 
eu-stacktrace [1/5]: src: add eu-stacktrace tool

eu-stacktrace is a utility to process a stream of raw stack
samples (such as those obtained from the Linux kernel's
PERF_SAMPLE_STACK facility) into a stream of stack traces (such as
those obtained from PERF_SAMPLE_CALLCHAIN), freeing other profiling
utilities from having to implement their own backtracing logic.

eu-stacktrace accepts data from a profiling tool via a pipe or
fifo. The initial version of the tool works on x86 architectures and
accepts data from Sysprof [1]. For future work, it will make sense
to expand support to other profilers, in particular perf tool.

Further patches in this series provide configury, docs, and improved
diagnostics for tracking the method used to unwind each frame in the
stack trace.

[1]: The following patched version of Sysprof (upstream submission ETA
~very_soon) can produce data with stack samples:

https://git.sr.ht/~serhei/sysprof-experiments/log/serhei/samples-via-fifo

Invoking the patched sysprof with eu-stacktrace:

$ sudo sysprof-cli --use-stacktrace
$ sudo sysprof-cli --use-stacktrace --stacktrace-path=/path/to/eu-stacktrace

Invoking the patched sysprof and eu-stacktrace manually through a fifo:

$ mkfifo /tmp/test.fifo
$ sudo eu-stacktrace --input /tmp/test.fifo --output test.syscap &
$ sysprof-cli --sample-method=stack --use-fifo=/tmp/test.fifo test.syscap

Note that sysprof polkit actions must be installed systemwide
(e.g. installing the system sysprof package will provide these).
Otherwise, "Action org.gnome.sysprof3.profile is not registered"
error will result.

* src/stacktrace.c: Add new tool.

Signed-off-by: Serhei Makarov <serhei@serhei.io>
8 months agoRemove usage of "unlocked" variant of stdio print functions
Michael Pratt [Wed, 16 Oct 2024 19:53:52 +0000 (19:53 +0000)] 
Remove usage of "unlocked" variant of stdio print functions

These "unlocked" Linux Standard Base variants of standard functions
are not available on some systems that are still capable
of building Linux and ELFs.

The difference is negligible for simple printing to stdout.

POSIX also states for the similar putc_unlocked():

  These functions can safely be used in a multi-threaded program
  if and only if they are called while the invoking thread owns
  the (FILE *) object, as is the case after a successful call
  to the flockfile() or ftrylockfile() functions.

...

  These unlocked versions can be safely used
  only within explicitly locked program regions,
  using exported locking primitives.

and these precautions were never done.

Use the standard forms of these print functions.

There is inconsistent use of fputc_unlocked() with putc_unlocked(),
so consistently use the safer fputc() instead.

Signed-off-by: Michael Pratt <mcpratt@pm.me>
8 months agodoc/Makefile.am: Add man pages
Aaron Merey [Thu, 3 Oct 2024 02:26:10 +0000 (22:26 -0400)] 
doc/Makefile.am: Add man pages

Add the following man pages to notrans_dist_man3_MANS:

elf32_xlatetom.3 elf64_xlatetom.3 elf32_xlatetof.3 elf64_xlatetof.3
elf32_newphdr.3 elf64_newphdr.3 elf32_newehdr.3 elf64_newehdr.3
elf32_getshdr.3 elf64_getshdr.3 elf32_getphdr.3 elf64_getphdr.3
elf32_getchdr.3 elf64_getchdr.3 elf32_fsize.3 elf64_fsize.3
elf32_checksum.3 elf64_checksum.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
8 months agodoc: Add elf{32,64}_xlatetof.3 and elf{32,64}_xlatetom.3
Aaron Merey [Thu, 3 Oct 2024 02:26:09 +0000 (22:26 -0400)] 
doc: Add elf{32,64}_xlatetof.3 and elf{32,64}_xlatetom.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
8 months agodoc: Add elf32_newphdr.3 and elf64_newphdr.3
Aaron Merey [Thu, 3 Oct 2024 02:26:08 +0000 (22:26 -0400)] 
doc: Add elf32_newphdr.3 and elf64_newphdr.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
8 months agodoc: Add elf32_newehdr.3 and elf64_newehdr.3
Aaron Merey [Thu, 3 Oct 2024 02:26:07 +0000 (22:26 -0400)] 
doc: Add elf32_newehdr.3 and elf64_newehdr.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
8 months agodoc: Add elf32_getshdr.3 and elf64_getshdr.3
Aaron Merey [Thu, 3 Oct 2024 02:26:06 +0000 (22:26 -0400)] 
doc: Add elf32_getshdr.3 and elf64_getshdr.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
8 months agodoc: Add elf32_getphdr.3 and elf64_getphdr.3
Aaron Merey [Thu, 3 Oct 2024 02:26:05 +0000 (22:26 -0400)] 
doc: Add elf32_getphdr.3 and elf64_getphdr.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
8 months agodoc: Add elf32_getchdr.3 and elf64_getchdr.3
Aaron Merey [Thu, 3 Oct 2024 02:26:04 +0000 (22:26 -0400)] 
doc: Add elf32_getchdr.3 and elf64_getchdr.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
8 months agodoc: Add elf32_fsize.3 and elf64_fsize.3
Aaron Merey [Thu, 3 Oct 2024 02:26:03 +0000 (22:26 -0400)] 
doc: Add elf32_fsize.3 and elf64_fsize.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
8 months agodoc: Add elf32_checksum.3 and elf64_checksum.3
Aaron Merey [Thu, 3 Oct 2024 02:26:02 +0000 (22:26 -0400)] 
doc: Add elf32_checksum.3 and elf64_checksum.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
8 months agoPR32218: debuginfod-client: support very long source file names
Frank Ch. Eigler [Thu, 10 Oct 2024 20:30:19 +0000 (16:30 -0400)] 
PR32218: debuginfod-client: support very long source file names

debuginfod clients & servers may sometimes encounter very long source
file names.  Previously, the client would synthesize a path name like
   $CACHEDIR/$BUILDID/source-$PATHNAME
where $PATHNAME was a funky ##-encoded version of the entire source
path name.  See https://sourceware.org/PR32218 for a horror case.
This can get too long to store as a single component of a file system
pathname (e.g. linux/limits.h NAME_MAX), resulting on client-side
errors even after a successful download.

New code switches encoding of the $PATHNAME part to use less escaping,
and a merciless truncation to the tail part of the filename.  (We keep
the tail rather than the head, so that the extension is preserved,
which makes some consumers happier.)  To limit collision damage from
truncation, we add also insert a goofy hash (4-byte DJBX33A) of the
name into the path name.  The result is a relatively short name:

   $CACHEDIR/$BUILDID/source-$HASH-$NAMETAIL

This is a transparent change to clients, who are not to make any
assumptions about cache file naming structure.  However, one existing
test did make such assumptions, so is fixed with some globness.  A new
test is also added, using a pre-baked tarball with a very long srcfile
name.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
8 months agolibdw: Let clean targets be unconditional
Michael Pratt [Thu, 10 Oct 2024 10:27:09 +0000 (10:27 +0000)] 
libdw: Let clean targets be unconditional

The automake rule "maintainer-clean-generic"
is always available and never conditional,
so let the variable that uses it be define
non-conditionally.

If one actually wants conditional cleaning
they should write a custom rule and set it
as a dependency of a "*clean-local" automake rule.

There is no need to do conditional cleaning here,
so move the MAINTAINERCLEANFILES variable definition
to the end of the Makefile.am file as it is
in the rest of the project.

      * libdw/Makefile.am: move MAINTAINERCLEANFILES
      variable to the end of the file
      as a non-conditional definition.

Signed-off-by: Michael Pratt <mcpratt@pm.me>
8 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>
8 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>
8 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>
8 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>
9 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>
9 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>
9 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>
9 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>
9 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>
9 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>
9 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>
9 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>
9 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>
10 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>
10 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>
10 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>
10 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>
10 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>
10 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>
10 months agotests: When BUILD_STATIC always link against libeu users/mark/try-build-static
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>
10 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>
10 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>
10 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>
10 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>
10 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>
10 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>
10 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>
10 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>
10 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>
10 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>
10 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>
10 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>
10 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.

11 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>
11 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>
11 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>
11 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>
11 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>
11 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>
11 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>
11 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>
11 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>
11 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>
11 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>
11 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>
11 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>
11 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>
11 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>
11 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

11 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>
11 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>
11 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>
12 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>
12 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>
12 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>
12 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>
12 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>
12 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>
12 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>
12 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>
12 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>
12 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>