]> git.ipfire.org Git - thirdparty/elfutils.git/log
thirdparty/elfutils.git
5 weeks agobackends/: sketch s390 sample_regs support users/serhei/try-libdwfl-stacktrace
Serhei Makarov [Fri, 13 Mar 2026 17:32:29 +0000 (13:32 -0400)] 
backends/: sketch s390 sample_regs support

{speculative, but it should look roughly like this,
modulo proper PSW handling}

5 weeks agobackends/: sketch powerpc sample_regs support
Serhei Makarov [Thu, 12 Mar 2026 19:29:04 +0000 (15:29 -0400)] 
backends/: sketch powerpc sample_regs support

{speculative, but it should look roughly like this}

5 weeks agobackends/: sketch 32-bit arm sample_regs support
Serhei Makarov [Fri, 6 Mar 2026 20:49:45 +0000 (15:49 -0500)] 
backends/: sketch 32-bit arm sample_regs support

{detailed changelog TBA pending testing}

5 weeks agobackends/: fixup stray uint32_t n_regs_mapping
Serhei Makarov [Fri, 6 Mar 2026 20:25:16 +0000 (15:25 -0500)] 
backends/: fixup stray uint32_t n_regs_mapping

These should have been size_t.

{changelog TBA}

5 weeks agobackends/: fixup x86 initreg_sample to share code with aarch64
Serhei Makarov [Fri, 6 Mar 2026 17:33:49 +0000 (12:33 -0500)] 
backends/: fixup x86 initreg_sample to share code with aarch64

In particular, sample_sp_pc() implementation looks to be uniform
across architectures apart from the register positions.

{changelog TBA pending testing}

5 weeks agolibebl/eblinitreg_sample.c: potential off-by-one fix
Serhei Makarov [Fri, 6 Mar 2026 17:21:47 +0000 (12:21 -0500)] 
libebl/eblinitreg_sample.c: potential off-by-one fix

{I believe the way things were setup on x86 meant this was never
triggered, but it looks incorrect.}

5 weeks agobackends/: draft aarch64 sample_regs support
Serhei Makarov [Fri, 6 Mar 2026 17:10:29 +0000 (12:10 -0500)] 
backends/: draft aarch64 sample_regs support

{detailed changelog TBA pending testing}

7 weeks agosrc/stacktrace.c: Add an option to print build-ids.
Serhei Makarov [Thu, 6 Nov 2025 17:28:35 +0000 (12:28 -0500)] 
src/stacktrace.c: Add an option to print build-ids.

In preparation for adapting eu-stacktrace to gmon.out generation,
print out per-frame build-ids to sanitycheck the data.

* src/stacktrace.c (show_buildids): New global variable.
  (struct sysprof_unwind_info): Enable sui->last_dwfl.
  (sysprof_unwind_frame_cb): Obtain and print build-id.
  (sysprof_unwind_cb): Enable sui->last_dwfl.
  (parse_opt): Accept --buildid option.
  (main): Accept --buildid option and env var setting.

7 weeks agolibdwfl_stacktrace + libebl: dwflst_sample_getframes non-perf api
Serhei Makarov [Fri, 12 Sep 2025 20:00:16 +0000 (16:00 -0400)] 
libdwfl_stacktrace + libebl: dwflst_sample_getframes non-perf api

This patch adds a generic dwflst_sample_getframes() API that does not
depend on perf_events concepts, in particular the
linux-kernel-specific enum defining the perf_regs_mask register order.
This involves reworking the register-handling backend to use
regs_mapping arrays rather than perf_regs_mask, and provide a way to
translate perf_regs_mask to regs_mapping.

A regs_mapping array, for each item in a provided regs[] array,
specifies its position in the full register file expected by the DWARF
functionality.

Changes for v3:
- Added dwflst_sample_getframes to libdw.map.

Changes for v2:
- Addressed Aaron Merey's review comments.
- Removed dwflst_sample_frame.c dependency on perf_events abi constants.

* libdwfl_stacktrace/Makefile.am: Rename dwflst_sample_frame.c from
  dwflst_perf_frame.c.
* libdwfl_stacktrace/libdwfl_stacktrace.h (dwflst_sample_getframes):
  New function providing unwinding functionality with a regs_mapping
  array rather than a linux-kernel-dependent perf_regs_mask.
* libdw/libdw.map (ELFUTILS_0.193_EXPERIMENTAL): Add dwflst_sample_getframes.
* libdwfl_stacktrace/dwflst_sample_frame.c: Renamed from
  dwflst_perf_frame.c. Remove linux/perf_event.h dependency.
  (struct sample_info): Rename from perf_sample_info, include
  regs_mapping field, replace abi with elfclass field.
  (sample_next_thread): Renamed struct sample_info.
  (sample_getthread): Renamed struct sample_info.
  (copy_word): Use elfclass instead of perf abi field.
  (elf_memory_read): Renamed struct sample_info, use elfclass.
  (sample_memory_read): Renamed struct sample_info, use elfclass.
  (sample_set_initial_registers): Renamed struct sample_info,
  pass regs_mapping to ebl_set_initial_registers_sample.
  (dwflst_sample_getframes): New function.
  (dwflst_perf_sample_getframes): Reimplement in terms of
  dwflst_sample_getframes and ebl_sample_perf_regs_mapping.
* libebl/ebl-hooks.h (set_initial_registers_sample): Now
  takes regs_mapping instead of regs_mask.
  (sample_base_addr): Removed.
  (sample_pc): Removed.
  (sample_sp_pc): New function combining the removed functions for
  efficiency.
  (sample_perf_regs_mapping): New function translating
  perf_regs_mask to regs_mapping array.
* libebl/eblinitreg_sample.c (ebl_sample_base_addr): Removed.
  (ebl_sample_pc): Removed.
  (ebl_sample_sp_pc): New function.
  (ebl_set_initial_registers_sample): Take regs_mapping, provide
  a default implementation for contiguous dwarf_regs array.
  (ebl_sample_perf_regs_mapping): New function.
* libebl/eblclosebackend.c (ebl_closebackend):
  Free cached_regs_mapping.
* libebl/libebl.h (ebl_set_initial_registers_sample): Now takes
  regs_mapping instead of regs_mask.
  (ebl_sample_base_addr): Removed.
  (ebl_sample_pc): Removed.
  (ebl_sample_sp_pc): New function.
  (ebl_sample_perf_regs_mapping): New function.
* libebl/libeblP.h (struct ebl): Add caching fields to remove the
  need to repeat a sample_perf_regs_mapping() computation for
  every frame when the perf_regs_mask is consistent.
* backends/Makefile.am: Remove no-longer-needed linux-perf-regs.c.
* backends/i386_init.c (i386_init): Renamed sample_* functions,
  added cached_regs_mapping and related fields/functions.
* backends/i386_initreg_sample.c (i386_sample_base_addr): Removed.
  (i386_sample_pc): Removed.
  (i386_sample_sp_pc): New function combining the removed functions.
  (i386_set_initial_registers_sample): Removed.
  (i386_sample_perf_regs_mapping): New function translating
  perf_regs_mask to regs_mapping array.
* backends/linux-perf-regs.c: Removed as perf_sample_find_reg is no
  longer needed.
* backends/x86_64_init.c (x86_64_init): Renamed sample_* functions,
  added cached_regs_mapping and related fields/functions.
* backends/x86_64_initreg_sample.c (x86_64_sample_base_addr): Removed.
  (x86_64_sample_pc): Removed.
  (x86_64_sample_sp_pc): New function combining the removed functions.
  (x86_64_set_initial_registers_sample): Removed.
  (x86_64_sample_perf_regs_mapping): New function translating
  perf_regs_mask to regs_mapping array.
* backends/x86_initreg_sample.c (x86_set_initial_registers_sample):
  Removed.
  (x86_sample_sp_pc): New function.
  (x86_sample_perf_regs_mapping): New function translating
  perf_regs_mask to regs_mapping array.

7 weeks agotests/run-stack-live-test.sh: document buildbot results
Serhei Makarov [Fri, 9 May 2025 13:39:43 +0000 (09:39 -0400)] 
tests/run-stack-live-test.sh: document buildbot results

Gives an idea of how much more flexibility is needed for the munging
to work across a variety of systems. Also concerned that elfutils
certainly runs on non-linux non-GLIBC systems too, worth a brief test
on musl and bsd?

7 weeks agotests/run-stack-live-test.sh: misc fixes
Serhei Makarov [Fri, 9 May 2025 13:37:55 +0000 (09:37 -0400)] 
tests/run-stack-live-test.sh: misc fixes

* tests/Makefile.am (EXTRA_DIST): Add run-stack-live-test.sh for
  distcheck.
* tests/run-stack-live-test.sh: Fix whitespace.

7 weeks agotests/run-stack-live-test.sh: prototype 'live' eu-stack testing
Serhei Makarov [Thu, 8 May 2025 22:17:45 +0000 (18:17 -0400)] 
tests/run-stack-live-test.sh: prototype 'live' eu-stack testing

Missing a few pieces, but worth sharing as an RFC. My idea is to
ensure better test coverage for eu-stack and then
eu-stacktrace+libdwfl_stacktrace by running against a live process
with known content, stopped at a known location, and aggressively
scrubbing output that's known to vary from testrun to testrun.

This is a very basic preview of how that might look. If the approach
is sound, I hope to make it more sophisticated/reliable.

Unanswered questions:
- Scrub more data (e.g. libc symvers) from a more known program.
  Scrub stack frame numbers to account for a case where extra frames
  appear / are missing at the bottom of the stack?
- Something better than sed for the scrubbing?
- An equivalent eu-stacktrace test will require privileged perf_events
  access for profiling data and therefore likely to be skipped by
  default. How feasible is it to be enabled on the buildbots, though?

* tests/run-stack-live-test.sh: New test with wild and fuzzy
  testrun_compare variant that scrubs inherently unpredictable parts of
  the data. Needs to scrub even more.
* tests/Makefile.am (TESTS): Add run-stack-live-test.sh.

7 weeks agoREADME.eu-stacktrace: re-add for development branch
Serhei Makarov [Fri, 18 Oct 2024 21:02:38 +0000 (17:02 -0400)] 
README.eu-stacktrace: re-add for development branch

8 weeks agoPR33937: docs: catch up debuginfod-find / client docs to code
Frank Ch. Eigler [Tue, 3 Mar 2026 13:17:17 +0000 (08:17 -0500)] 
PR33937: docs: catch up debuginfod-find / client docs to code

Some options the code has supported forever were not documented in the
man pages, and the general client docs were a little too confident.

Signed-off-by: Frank Ch. Eigler <fche@elastic.org>
8 weeks agodwarf_tag.c: Protect cu->last_abbrev_offset with lock
Aaron Merey [Thu, 26 Feb 2026 18:41:27 +0000 (13:41 -0500)] 
dwarf_tag.c: Protect cu->last_abbrev_offset with lock

Acquire abbrev_lock before reading cu->last_abbrev_offset in dwarf_tag.

Also double check for abbrev hash table entry once lock is held to
avoid multiple threads attempting to populate the abbrev hash table.

Signed-off-by: Aaron Merey <amerey@redhat.com>
2 months agoaarch64: Recognize SHT_AARCH64_ATTRIBUTES
Mark Wielaard [Tue, 24 Feb 2026 21:19:48 +0000 (22:19 +0100)] 
aarch64: Recognize SHT_AARCH64_ATTRIBUTES

Recognize SHT_AARCH64_ATTRIBUTES. This is enough to stop elflint
complaining about unknown section types. But doesn't implement parsing
the attributes.

* backends/aarch64_symbol.c (aarch64_section_type_name):
  New function.
* backends/aarch64_init.c (aarch64_init): Hook
        section_type_name.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 months agodwarf_begin_elf.c: Fix lock resource leak
Aaron Merey [Tue, 24 Feb 2026 21:08:07 +0000 (16:08 -0500)] 
dwarf_begin_elf.c: Fix lock resource leak

dwarf_begin_elf might free memory for a struct Dwarf after its rwlock and
mutex fields have been initialized without calling the corresponding
destroy functions to release the lock resources.

Fix this by moving lock inits to the end of the valid_p function, after
the struct Dwarf being intialized has passed all error checking.

Signed-off-by: Aaron Merey <amerey@redhat.com>
2 months agodoc: Add gelf_xlatetof.3 and gelf_xlatetom.3
Aaron Merey [Thu, 1 Jan 2026 02:50:29 +0000 (21:50 -0500)] 
doc: Add gelf_xlatetof.3 and gelf_xlatetom.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
2 months agodoc: Add gelf_getchdr.3
Aaron Merey [Thu, 1 Jan 2026 02:50:28 +0000 (21:50 -0500)] 
doc: Add gelf_getchdr.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
2 months agodoc: Add gelf_update_phdr.3
Aaron Merey [Thu, 1 Jan 2026 02:50:27 +0000 (21:50 -0500)] 
doc: Add gelf_update_phdr.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
2 months agodoc: Add gelf_getphdr.3
Aaron Merey [Thu, 1 Jan 2026 02:50:26 +0000 (21:50 -0500)] 
doc: Add gelf_getphdr.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
2 months agodoc: Add gelf_fsize.3
Aaron Merey [Thu, 1 Jan 2026 02:50:25 +0000 (21:50 -0500)] 
doc: Add gelf_fsize.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
2 months agoreadelf: Fix NULL pointer dereference in process_symtab with -D flag
Samuel Dainard [Tue, 17 Feb 2026 22:07:06 +0000 (23:07 +0100)] 
readelf: Fix NULL pointer dereference in process_symtab with -D flag

When using eu-readelf with the -D (use_dynamic_segment) flag on malformed
ELF files, process_symtab can receive a NULL symstr_data pointer if
elf_getdata_rawchunk fails or the dynamic segment is malformed.

The function then dereferences symstr_data->d_buf without checking,
causing a segmentation fault.

Add NULL check before accessing symstr_data fields.

Fixes regression introduced in 0.194 where process_symtab was refactored
to handle dynamic segment symbol tables.

Signed-off-by: Samuel Dainard <sdainard@amazon.com>
2 months agoCONTRIBUTING: Add Policy on the Use of LLM-generated Content
Aaron Merey [Tue, 17 Feb 2026 19:47:41 +0000 (14:47 -0500)] 
CONTRIBUTING: Add Policy on the Use of LLM-generated Content

Such contributions are not being accepted at this time.  See
CONTRIBUTING for more information.

Signed-off-by: Aaron Merey <amerey@redhat.com>
2 months agodebuginfod: add filename to archive_exception log
Michael Trapp [Tue, 17 Feb 2026 13:46:49 +0000 (14:46 +0100)] 
debuginfod: add filename to archive_exception log

The current archive_exception doesn't report the filename of a broken archive,
but this information is needed to identify the affected archive.

Fix this by adding a new archive_exception to get the following log message:

  libarchive error: _FILENAME_ cannot extract file: Truncated tar archive ...

Signed-off-by: Michael Trapp <michael.trapp@sap.com>
2 months agotests: Skip tests on non-ELF bitcode object files
Mark Wielaard [Tue, 10 Feb 2026 17:25:42 +0000 (18:25 +0100)] 
tests: Skip tests on non-ELF bitcode object files

clang with -flto produces object files that contain bitcode. This
breaks various (self) testcases that expect those .o files are ELF
files. eu-readelf, eu-nm, eu-elfline and eu-elfcompress won't work on
such files.

Add a helper function is_obj_bitcode in test-subr.sh that tests can
use to possibly skip a check on an .o file.

       * tests/test-subr.sh (is_obj_bitcode): New function.
       (testrun_on_self): Use is_obj_bitcode to possibly skip a file.
       (testrun_on_self_obj): Likewise.
       (testrun_on_self_compressed): Likewise.
       (testrun_on_self_quiet): Likewise.
       * tests/run-elfclassify-self.sh: Check if the object files are
       actually ELF files.
       * tests/run-nm-self.sh: Use is_obj_bitcode to possibly skip file.
       * tests/run-reverse-sections-self.sh: Likewise.
       * tests/run-strip-reloc-self.sh: Likewise.
       * tests/run-strip-strmerge.sh: Likewise.
       * tests/strip-reloc-subr.sh: Likewise.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 months agoreadelf: Don't warn for CUs with the same base addresses
Mark Wielaard [Tue, 10 Feb 2026 17:01:30 +0000 (18:01 +0100)] 
readelf: Don't warn for CUs with the same base addresses

It is valid for for two CUs to share the same base address attributes,
so don't warn for that (which also would sets the exit status to
non-zero).

* src/readelf.c (compare_listptr): Remove listptr_base check.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 months agoreadelf: Handle CUs that share an addr_base or str_offsets_base
Mark Wielaard [Thu, 5 Feb 2026 18:58:05 +0000 (19:58 +0100)] 
readelf: Handle CUs that share an addr_base or str_offsets_base

readelf assumed each .debug_addr and .debug_str_offsets was associated
with precisely one CU DIE. But CU DIEs can have the same
DW_AT_addr_base or DW_AT_str_offsets_base. Change the code to find the
first CU associated with the offset.

 * src/readelf.c (print_debug_addr_section): Skip CUs that
         have an addr_base already handled.
         (print_debug_str_offsets_section): Likewise for
         str_offsets_base.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 months agoelflint: Recognize .relro_padding section
Mark Wielaard [Mon, 9 Feb 2026 22:19:17 +0000 (23:19 +0100)] 
elflint: Recognize .relro_padding section

lld might generate a .relro_padding section, it should be WRITE|ALLOC
to be part of PT_GNU_TLS.

 * src/elflint.c (special_sections): Add .relro_padding.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 months agoelflint, readelf, support SHT_LLVM_LTO and SHT_LLVM_ADDRSIG
Mark Wielaard [Mon, 9 Feb 2026 22:18:40 +0000 (23:18 +0100)] 
elflint, readelf, support SHT_LLVM_LTO and SHT_LLVM_ADDRSIG

An SHT_LLVM_LTO section contains LLVM bitcode. An SHT_LLVM_ADDRSIG
section contains ULEB128 integers referring to the symbol table
indexes of address-significant symbols. This patch just recognizes the
SHT constants but doesn't handle the section contents.

 * libebl/eblsectiontypename.c (ebl_section_type_name):
 Recognize SHT_LLVM_ADDRSIG and SHT_LLVM_LTO.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 months agoelflint: Accept R_X86_64_DTPOFF64 in ET_REL files
Mark Wielaard [Mon, 9 Feb 2026 22:17:19 +0000 (23:17 +0100)] 
elflint: Accept R_X86_64_DTPOFF64 in ET_REL files

Normally R_X86_64_DTPOFF32, which takes a 32bit TLS offset, is used,
but R_X86_64_DTPOFF64, which takes a 64bit TLS offset may also be used
in ET_REL files.

 * backends/x86_64_reloc.def (DTPOFF64): Add REL.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 months agosrc/elfclassify.c: Fix memory leak in check_ar_members
Aaron Merey [Tue, 3 Feb 2026 21:31:00 +0000 (16:31 -0500)] 
src/elfclassify.c: Fix memory leak in check_ar_members

If current_path needs to be reallocated, full_path is assigned a newly
malloced buffer and then full_path is assigned to current_path.  This
leaks the previous value of full_path.

Free full_path before reassigning it.

Signed-off-by: Aaron Merey <amerey@redhat.com>
2 months agoconfigure: Add -Wdeprecated-non-prototype and -Wfree-labels if available
Mark Wielaard [Sat, 7 Feb 2026 17:25:09 +0000 (18:25 +0100)] 
configure: Add -Wdeprecated-non-prototype and -Wfree-labels if available

Calling a function with one or more arguments declared with an empty
parameter list is an error in C23. In C23 labels applied to
non-statements are allowed, but not in earlier standards (they are as
GNU extension in GCC). Add -Wdeprecated-non-prototype and
-Wfree-labels (available since GCC 15) to catch this.

            * configure.ac: Add HAVE_DEPRECATED_NON_PROTOTYPE_WARNING
    and HAVE_FREE_LABELS_WARNING check.
            * config/eu.am: Set FREE_LABELS_WARNING and
    FREE_LABELS_WARNING.
            (AM_CFLAGS): Add DEPRECATED_NON_PROTOTYPE_WARNING and
    FREE_LABELS_WARNING.

Signed-off-by: Mark Wielaard <mark@klomp.org>
Reviewed-by: Sam James <sam@gentoo.org>
2 months agoconfigure: Add -Wmissing-parameter-name if available
Mark Wielaard [Sat, 7 Feb 2026 00:48:26 +0000 (01:48 +0100)] 
configure: Add -Wmissing-parameter-name if available

Before C23 omitting parameter names in function definitions isn't
supported. Add -Wmissing-parameter-name (available since GCC 15) to
catch this.

* configure.ac: Add HAVE_MISSING_PARAMETER_NAME_WARNING check.
* config/eu.am: Set MISSING_PARAMETER_NAME_WARNING based on
HAVE_MISSING_PARAMETER_NAME_WARNING.
(AM_CFLAGS): Add MISSING_PARAMETER_NAME_WARNING.

Signed-off-by: Mark Wielaard <mark@klomp.org>
Reviewed-by: Sam James <sam@gentoo.org>
2 months agostacktrace: fix a C23-ism in sigint_handler
Mark Wielaard [Wed, 4 Feb 2026 14:09:06 +0000 (15:09 +0100)] 
stacktrace: fix a C23-ism in sigint_handler

clang 21 doesn't like ommitting a parameter name when not in C23 mode.

stacktrace.c:1138:44: error: omitting the parameter name in a function definition is a C23 extension [-Werror,-Wc23-extensions]
 1138 | static void sigint_handler (int /* signo */)
      |                                            ^
1 error generated.

* src/stacktrace.c (sigint_handler): Use attribute unused.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 months agoPR33854: fix regression in dwflst_perf_sample_getframes
Serhei Makarov [Thu, 29 Jan 2026 17:27:50 +0000 (12:27 -0500)] 
PR33854: fix regression in dwflst_perf_sample_getframes

In commit 3ce0d5ed, I missed the fact that
dwflst_perf_sample_getframes needs to handle the case of an unattached
Dwfl, when dwfl->process->ebl is not yet available to translate the
registers. Thus, it can't be a straightforward wrapper of
dwfl_sample_getframes, but should instead handle the attaching logic
identically to that function.

Also fix a leakage of sample_arg in dwflst_sample_getframes that was
happening on attach failure.

* libdwfl_stacktrace (dwflst_sample_getframes): Fix a leak of
  sample_arg on attach failure.
* libdwfl_stacktrace (dwflst_perf_sample_getframes): Implement
  attaching the Dwfl identically to dwflst_sample_getframes.
  Avoid leaking sample_arg on attach failure.

Signed-off-by: Serhei Makarov <serhei@serhei.io>
2 months agoMake __libdwfl_debuginfod_find_* functions thread safe
Aaron Merey [Fri, 19 Dec 2025 22:39:36 +0000 (17:39 -0500)] 
Make __libdwfl_debuginfod_find_* functions thread safe

Individual debuginfod_client objects and their underlying CURLM handles
should not be used concurrently during calls to
__libdwfl_debuginfod_find_debuginfo and
__libdwfl_debuginfod_find_executable.

Add a mutex field to struct Dwfl to serialize calls to
__libdwfl_debuginfod_find_*.

Signed-off-by: Aaron Merey <amerey@redhat.com>
3 months agogelf_getmove.c: Handle ELFCLASS32 and ELFCLASS64 separately
Aaron Merey [Wed, 7 Jan 2026 23:43:49 +0000 (18:43 -0500)] 
gelf_getmove.c: Handle ELFCLASS32 and ELFCLASS64 separately

Currently gelf_getmove does not distinguish between ELFCLASS32 and
ELFCLASS64 binaries.  This is assumes that Elf32_Move and Elf64_Move
structs are the same size.

This assumption is false since the m_info and m_poffset fields have
type uint32_t for Elf32_Move but uint64_t for Elf64_Move.

Fix this by handling ELFCLASS32 and ELFCLASS64 cases separately when
copying Elfxx_Move fields to dst.

Signed-off-by: Aaron Merey <amerey@redhat.com>
3 months agoforge: Add a forgejo workflow to run various tests
Mark Wielaard [Sat, 20 Dec 2025 02:19:36 +0000 (03:19 +0100)] 
forge: Add a forgejo workflow to run various tests

This adds a check-debian.yaml file which will run various tests under
Debian and Fedora for new merge requests.

       * CONTRIBUTING: Explain how to contribute through the forge.
       * .forgejo/workflows/check-debian.yaml: New Debian based workflow.
       * .forgejo/workflows/check-fedora.yaml: New Fedora based workflow.

Signed-off-by: Mark Wielaard <mark@klomp.org>
4 months agotests: Disable valgrind for run-large-elf-file and run-compress-test
Mark Wielaard [Thu, 18 Dec 2025 15:35:06 +0000 (16:35 +0100)] 
tests: Disable valgrind for run-large-elf-file and run-compress-test

Both run-compress-test and run-large-elf-file create really big
files. Processing these under valgrind take a very long time. To
encourage more testing under valgrind memcheck or helgrind disable
valgrind for these two test so people don't have to wait 10 minutes
for make check results.

* tests/run-compress-test.sh: Unset VALGRIND_CMD.
* tests/run-large-elf-file.sh: Likewise.

Signed-off-by: Mark Wielaard <mark@klomp.org>
4 months agoreadelf: gcc_except_table: add newline in output
Martin LiÅ¡ka [Wed, 17 Dec 2025 14:39:05 +0000 (15:39 +0100)] 
readelf: gcc_except_table: add newline in output

Fixes:
```
 TType table: [   3] 0x23a4
 [   2] 0x23a8
 [   1] 0x23ac
```

to:
```
 TType table:
 [   3] 0x23a4
 [   2] 0x23a8
 [   1] 0x23ac
```

ChangeLog:

* src/readelf.c (print_debug_exception_table): Add newline after TType table header.

Signed-off-by: Martin Liska <martin.liska@hey.com>
4 months agolibelf: Add gelf_fsize main check
Mark Wielaard [Mon, 8 Dec 2025 10:44:45 +0000 (11:44 +0100)] 
libelf: Add gelf_fsize main check

This test itself isn't super interesting, it just checks that all
Elf_Types are handled by gelf_fsize and that the 32 vs 64 variant
sizes make sense. The interesting part is that it uses the internal
interface (__libelf_type_sizes) to do it. So you don't have to
contruct a whole Elf handle.

It mimics the support for "main checks" in libdw. It adds a way to
compile an individual source file with an optional main function that
can directly access the internal/static functions.

To add new main check tests you have to add an #ifdef MAIN_CHECK with
a main function that calls the test functions to the source file. And
add two make file rules after .SECONDEXPANSION. One starting with
<source_basename>_checks$(EXEEXT) and one starting with
nodist_<source_basename>_check_SOURCES.

* libelf/gelf_fsize.c: Add MAIN_CHECK part.
* libelf/Makefile.am: Add gelf_fsize main check rules.

Signed-off-by: Mark Wielaard <mark@klomp.org>
4 months agolibdw: Make sure to get .eh_frame_hdr with .eh_frame in getcfi_shdr
Mark Wielaard [Fri, 5 Dec 2025 15:27:04 +0000 (16:27 +0100)] 
libdw: Make sure to get .eh_frame_hdr with .eh_frame in getcfi_shdr

If we find a .eh_frame section we want to make sure to also get the
search table section .eh_frame_hdr. Otherwise lookups will be very
slow. Only create a Dwarf_CFI without a search table as a last resort.

* libdw/dwarf_getcfi_elf.c (getcfi_shdr): Keep iterating
        through the shdrs till both .eh_frame and .eh_frame_hdr are
        found. Check both aren't SHT_NOBITS.

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

Suggested-by: Shimin Guo <shimin.guo@skydio.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
4 months agotests: improve reliability of run-sysroot.sh
Arnout Engelen [Fri, 5 Dec 2025 14:52:41 +0000 (15:52 +0100)] 
tests: improve reliability of run-sysroot.sh

Previously, the 'second' test would test the `RESOLVE_IN_ROOT` feature
when the current libc supports it, even when the currently running
kernel did not yet support it.

Signed-off-by: Arnout Engelen <arnout@bzzt.net>
4 months agoreadelf: improve output format for .gcc_except_table
Martin LiÅ¡ka [Tue, 9 Dec 2025 08:21:01 +0000 (09:21 +0100)] 
readelf: improve output format for .gcc_except_table

Before the change:
```
 Call site table: [   0] Call site start:   0x10
        Call site length:  12
        Landing pad:       0x2a
        Action:            3
 [   1] Call site start:   0x1c
        Call site length:  123
        Landing pad:       0
        Action:            0

 Action table: [   0] ar_filter:   1
        ar_disp:     0
 [   1] ar_filter:   2
        ar_disp:    -3    -> [   0]
```

After:
```
 Call site table:
 [   0] Call site start:   0x10
        Call site length:  12
        Landing pad:       0x2a
        Action:            3
 [   1] Call site start:   0x1c
        Call site length:  123
        Landing pad:       0
        Action:            0

 Action table:
 [   0] ar_filter:   1
        ar_disp:     0
 [   1] ar_filter:   2
        ar_disp:    -3    -> [   0]
```

ChangeLog:

* src/readelf.c (print_debug_exception_table): Add newlines.

Signed-off-by: Martin Liska <martin.liska@hey.com>
4 months agoPR33635: Introduce debuginfod --home-redirect and --home-html
Martin Cermak [Fri, 5 Dec 2025 13:33:57 +0000 (14:33 +0100)] 
PR33635: Introduce debuginfod --home-redirect and --home-html

NEWS: New entry
debuginfod/debuginfod.cxx: Feature implementation
doc/debuginfod.8: Doc text
tests/Makefile.am: New testcase
tests/run-debuginfod-homesite.sh: New testcase

Signed-off-by: Martin Cermak <mcermak@redhat.com>
4 months agolibdw: Translate DW_LANG_Algol68 to DW_LNAME_Algol68 with lversion 1978
Mark Wielaard [Fri, 5 Dec 2025 11:56:22 +0000 (12:56 +0100)] 
libdw: Translate DW_LANG_Algol68 to DW_LNAME_Algol68 with lversion 1978

1978 is the year of the publication of the Revised Report that defines
the revised language. And this is the version set by gcc a68. So when
we see DW_LANG_Algol68 we translate it to DW_LNAME_Algol68 with
lversion set to 1978 to match gcc a68.

* libdw/dwarf_srclang.c (srclang_to_language): Set lversion to
        1978 for DW_LANG_Algol68.

Signed-off-by: Mark Wielaard <mark@klomp.org>
4 months agolibdw: Add Erlang, Elixir and Gleam language constants
Mark Wielaard [Tue, 2 Dec 2025 14:41:23 +0000 (15:41 +0100)] 
libdw: Add Erlang, Elixir and Gleam language constants

The DWARF standard recently added language constants for Erlang,
Elixir and Gleam. https://dwarfstd.org/languages.html
https://dwarfstd.org/languages-v6.html

* libdw/dwarf.h: Add DW_LANG_Erlang, DW_LNAME_Erlang,
DW_LANG_Elixir, DW_LNAME_Elixir, DW_LANG_Gleam and
DW_LNAME_Gleam.
* libdw/dwarf_default_lower_bound.c
(dwarf_default_lower_bound): Add DW_LANG_Gleam, DW_LANG_Erlang
and DW_LANG_Elixir.
(dwarf_language_lower_bound): Add DW_LNAME_Gleam, DW_LNAME_Erlang
and DW_LNAME_Elixir.
* libdw/dwarf_srclang.c (srclang_to_language): Handle
DW_LANG_Erlang, DW_LANG_Elixir and DW_LANG_Gleam.
(language_to_srclang): Handle DW_LNAME_Erlang, DW_LNAME_Elixir
and Add DW_LNAME_Gleam.

Signed-off-by: Mark Wielaard <mark@klomp.org>
4 months agopo: Update Polish translation
Piotr DrÄ…g [Mon, 1 Dec 2025 03:10:39 +0000 (22:10 -0500)] 
po: Update Polish translation

Signed-off-by: Aaron Merey <amerey@redhat.com>
5 months agoFix const-correctness issues
Andreas Schwab [Mon, 24 Nov 2025 12:46:16 +0000 (13:46 +0100)] 
Fix const-correctness issues

These were uncovered by the C23 const-preserving library macros.

5 months agopo: Update POTFILES.in
Piotr DrÄ…g [Wed, 26 Nov 2025 01:10:35 +0000 (20:10 -0500)] 
po: Update POTFILES.in

Signed-off-by: Aaron Merey <amerey@redhat.com>
5 months agodoc: add man page for gelf update symbol versioning entry functions
Aaron Merey [Mon, 10 Nov 2025 04:40:04 +0000 (23:40 -0500)] 
doc: add man page for gelf update symbol versioning entry functions

Add man pages for gelf_update_versym, gelf_update_verdef,
gelf_update_verdaux, gelf_update_verneed and gelf_update_vernaux.

Signed-off-by: Aaron Merey <amerey@redhat.com>
5 months agodoc: add man pages for gelf get symbol versioning entry functions
Aaron Merey [Mon, 10 Nov 2025 04:40:03 +0000 (23:40 -0500)] 
doc: add man pages for gelf get symbol versioning entry functions

Add man pages for gelf_getversym, gelf_getverdef, gelf_getverdaux
gelf_getverneed and gelf_getvernaux.

Signed-off-by: Aaron Merey <amerey@redhat.com>
5 months agodoc: Add gelf_update_rel.3 and gelf_update_rela.3
Aaron Merey [Mon, 10 Nov 2025 04:40:02 +0000 (23:40 -0500)] 
doc: Add gelf_update_rel.3 and gelf_update_rela.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
5 months agolibcpu/i386_parse.y: drop unused `cnt` variable
Sergei Trofimovich [Fri, 14 Nov 2025 09:44:55 +0000 (09:44 +0000)] 
libcpu/i386_parse.y: drop unused `cnt` variable

Without the change the build fails on `gcc-16` as:

    i386_parse.y: In function 'instrtable_out':
    i386_parse.y:1245:10: error: variable 'cnt' set but not used [-Werror=unused-but-set-variable=]
     1245 |   size_t cnt = 0;
          |          ^~~

Signed-off-by: Sergei Trofimovich <slyich@gmail.com>
5 months agodoc: Add gelf_newehdr.3
Aaron Merey [Mon, 3 Nov 2025 23:00:34 +0000 (18:00 -0500)] 
doc: Add gelf_newehdr.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
5 months agodoc: Add gelf_update_ehdr.3
Aaron Merey [Mon, 3 Nov 2025 22:59:23 +0000 (17:59 -0500)] 
doc: Add gelf_update_ehdr.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
5 months agodebuginfod: Mark internal debuginfod-client.c functions static
Mark Wielaard [Thu, 30 Oct 2025 10:43:44 +0000 (11:43 +0100)] 
debuginfod: Mark internal debuginfod-client.c functions static

The init_server_urls, init_handle and perform_queries functions are
only used internally by other debuginfod-client.c and shouldn't be
exported. Make sure they aren't by marking them static.

* debuginfod/debuginfod-client.c (init_server_urls): Mark static.
(init_handle): Likewise.
(perform_queries): Likewise.

Reported-by: Matthias Klose <doko@ubuntu.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
5 months agodoc: Add gelf_update_shdr.3
Aaron Merey [Tue, 28 Oct 2025 23:56:29 +0000 (19:56 -0400)] 
doc: Add gelf_update_shdr.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
5 months agodoc: Add gelf_getrel.3 and gelf_getrela.3
Aaron Merey [Tue, 28 Oct 2025 22:29:04 +0000 (18:29 -0400)] 
doc: Add gelf_getrel.3 and gelf_getrela.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
5 months agodoc: Add gelf_newphdr.3
Aaron Merey [Tue, 28 Oct 2025 22:26:31 +0000 (18:26 -0400)] 
doc: Add gelf_newphdr.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
5 months agodoc: Add gelf_offscn.3
Aaron Merey [Tue, 28 Oct 2025 22:16:49 +0000 (18:16 -0400)] 
doc: Add gelf_offscn.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
5 months agodoc: Add gelf_getshdr.3
Aaron Merey [Tue, 28 Oct 2025 14:14:38 +0000 (10:14 -0400)] 
doc: Add gelf_getshdr.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
6 months agoreadelf: Allocate job_data one-by-one as needed
Aaron Merey [Tue, 28 Oct 2025 02:00:12 +0000 (22:00 -0400)] 
readelf: Allocate job_data one-by-one as needed

Currently, job_data is stored in an array whose size is equal to the
number of debug sections (.debug_*, .eh_frame, .gdb_index, etc.).

This size may be too small if a binary contains multiple debug sections
with the same name.  For example an ET_REL binary compiled with -ggdb3
can contain multiple .debug_macro sections.

Fix this by allocating job_data on the fly when preparing to read a
debug section.  This supports an arbitrary number of debug sections
while also avoiding unnecessary memory allocation.

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

Signed-off-by: Aaron Merey <amerey@redhat.com>
6 months agolink_map.c: Declare name_no_sysroot only if openat2 RESOLVE_IN_ROOT is supported
Aaron Merey [Tue, 28 Oct 2025 01:49:31 +0000 (21:49 -0400)] 
link_map.c: Declare name_no_sysroot only if openat2 RESOLVE_IN_ROOT is supported

Rename variable n to name_no_sysroot.  Declare name_no_sysroot only if
openat2 RESOLVE_IN_ROOT is supported to avoid an unused variable warning.

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

Signed-off-by: Aaron Merey <amerey@redhat.com>
6 months agoPrepare for 0.194 elfutils-0.194
Aaron Merey [Sat, 25 Oct 2025 00:27:02 +0000 (20:27 -0400)] 
Prepare for 0.194

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

Signed-off-by: Aaron Merey <amerey@redhat.com>
6 months agotests/run-ar.sh: disable PIC/PIE/PLT for ar-extract-ar binaries
Aaron Merey [Fri, 24 Oct 2025 22:41:30 +0000 (18:41 -0400)] 
tests/run-ar.sh: disable PIC/PIE/PLT for ar-extract-ar binaries

Architecutres such as Debian i386 may enable PIE by default, resulting
in test binaries that include extra symbols such as
'__x86.get_pc_thunk.ax'.

These extra symbols are added to test archive symbol indices.  This
changes ar-extract-ar output which causes test failures.

Include '-fno-pic -fno-pie -fno-plt' when compiling test binaries to
ensure that no extra symbols are added and no symbols are reordered.

Signed-off-by: Aaron Merey <amerey@redhat.com>
6 months agobackends: Guard x86_sample_* function calls behind HAVE_X86_INITREG_SAMPLE
Aaron Merey [Fri, 24 Oct 2025 16:17:57 +0000 (12:17 -0400)] 
backends: Guard x86_sample_* function calls behind HAVE_X86_INITREG_SAMPLE

Avoid "implicit declaration" compile errors on non-x86_64/i386 arches
by calling x86_sample_* functions only when x86_initreg_sample.c is
included in the build.

Signed-off-by: Aaron Merey <amerey@redhat.com>
6 months agolibdwfl_stacktrace + libebl: dwflst_sample_getframes non-perf api
Serhei Makarov [Fri, 24 Oct 2025 14:26:03 +0000 (10:26 -0400)] 
libdwfl_stacktrace + libebl: dwflst_sample_getframes non-perf api

This patch adds a generic dwflst_sample_getframes() API that does not
depend on perf_events concepts, in particular the
linux-kernel-specific enum defining the perf_regs_mask register order.
This involves reworking the register-handling backend to use
regs_mapping arrays rather than perf_regs_mask, and provide a way to
translate perf_regs_mask to regs_mapping.

A regs_mapping array, for each item in a provided regs[] array,
specifies its position in the full register file expected by the DWARF
functionality.

* libdwfl_stacktrace/Makefile.am: Rename dwflst_sample_frame.c from
  dwflst_perf_frame.c.
* libdwfl_stacktrace/libdwfl_stacktrace.h (dwflst_sample_getframes):
  New function providing unwinding functionality with a regs_mapping
  array rather than a linux-kernel-dependent perf_regs_mask.
* libdw/libdw.map (ELFUTILS_0.194_EXPERIMENTAL): Add dwflst_sample_getframes.
* libdwfl_stacktrace/dwflst_sample_frame.c: Renamed from
  dwflst_perf_frame.c. Remove linux/perf_event.h dependency.
  (struct sample_info): Rename from perf_sample_info, include
  regs_mapping field, replace abi with elfclass field.
  (sample_next_thread): Renamed struct sample_info.
  (sample_getthread): Renamed struct sample_info.
  (copy_word): Use elfclass instead of perf abi field.
  (elf_memory_read): Renamed struct sample_info, use elfclass.
  (sample_memory_read): Renamed struct sample_info, use elfclass.
  (sample_set_initial_registers): Renamed struct sample_info,
  pass regs_mapping to ebl_set_initial_registers_sample.
  (dwflst_sample_getframes): New function.
  (dwflst_perf_sample_getframes): Reimplement in terms of
  dwflst_sample_getframes and ebl_sample_perf_regs_mapping.
* libebl/ebl-hooks.h (set_initial_registers_sample): Now
  takes regs_mapping instead of regs_mask.
  (sample_base_addr): Removed.
  (sample_pc): Removed.
  (sample_sp_pc): New function combining the removed functions for
  efficiency.
  (sample_perf_regs_mapping): New function translating
  perf_regs_mask to regs_mapping array.
* libebl/eblinitreg_sample.c (ebl_sample_base_addr): Removed.
  (ebl_sample_pc): Removed.
  (ebl_sample_sp_pc): New function.
  (ebl_set_initial_registers_sample): Take regs_mapping, provide
  a default implementation for contiguous dwarf_regs array.
  (ebl_sample_perf_regs_mapping): New function.
* libebl/eblclosebackend.c (ebl_closebackend):
  Free cached_regs_mapping.
* libebl/libebl.h (ebl_set_initial_registers_sample): Now takes
  regs_mapping instead of regs_mask.
  (ebl_sample_base_addr): Removed.
  (ebl_sample_pc): Removed.
  (ebl_sample_sp_pc): New function.
  (ebl_sample_perf_regs_mapping): New function.
* libebl/libeblP.h (struct ebl): Add caching fields to remove the
  need to repeat a sample_perf_regs_mapping() computation for
  every frame when the perf_regs_mask is consistent.
* backends/Makefile.am: Remove no-longer-needed linux-perf-regs.c.
* backends/i386_init.c (i386_init): Renamed sample_* functions,
  added cached_regs_mapping and related fields/functions.
* backends/i386_initreg_sample.c (i386_sample_base_addr): Removed.
  (i386_sample_pc): Removed.
  (i386_sample_sp_pc): New function combining the removed functions.
  (i386_set_initial_registers_sample): Removed.
  (i386_sample_perf_regs_mapping): New function translating
  perf_regs_mask to regs_mapping array.
* backends/linux-perf-regs.c: Removed as perf_sample_find_reg is no
  longer needed.
* backends/x86_64_init.c (x86_64_init): Renamed sample_* functions,
  added cached_regs_mapping and related fields/functions.
* backends/x86_64_initreg_sample.c (x86_64_sample_base_addr): Removed.
  (x86_64_sample_pc): Removed.
  (x86_64_sample_sp_pc): New function combining the removed functions.
  (x86_64_set_initial_registers_sample): Removed.
  (x86_64_sample_perf_regs_mapping): New function translating
  perf_regs_mask to regs_mapping array.
* backends/x86_initreg_sample.c (x86_set_initial_registers_sample):
  Removed.
  (x86_sample_sp_pc): New function.
  (x86_sample_perf_regs_mapping): New function translating
  perf_regs_mask to regs_mapping array.

Signed-off-by: Serhei Makarov <serhei@serhei.io>
6 months agoelf_getarhdr.c: Return correct header for archive within an archive
Aaron Merey [Fri, 24 Oct 2025 02:25:25 +0000 (22:25 -0400)] 
elf_getarhdr.c: Return correct header for archive within an archive

If elf_getarhdr is called on a descriptor that refers to an archive
which is itself a member of another archive, it may return the Elf_Arhdr
of the current member (i.e., the member selected by elf_next or elf_rand)
of the inner archive instead of Elf_Arhdr of the inner archive itself.

This also causes a memory leak: elf_end only attempts to free
Elf_Arhdr fields ar_name and ar_rawname for descriptors that are not
ELF_K_AR.

To fix this, replace the state.elf[32|64] field elf_ar_hdr with new
struct Elf field elf_ar_hdr.  This field stores the Elf_Arhdr for all
descriptors of archive members, including those with kind ELF_K_AR.

Also rename the state.ar field elf_ar_hdr to cur_ar_hdr to clarify that
this is the header of an archive's current member.

Signed-off-by: Aaron Merey <amerey@redhat.com>
6 months agoreadelf: use PRIu16 instead of PRId16 for uint16_t
Andreas Schwab [Wed, 22 Oct 2025 10:17:53 +0000 (12:17 +0200)] 
readelf: use PRIu16 instead of PRId16 for uint16_t

The Elfxx_Half type is unsigned, thus it should be printed as an unsigned
type.  This fixes the formatting of such a value if it is bigger than
32767, which would be printed as a negative number with the PRId16 format,
due to a recent change in glibc that properly converts the value to the
narrow type before printing.

Fixes this testsuite failure:

@@ -14,7 +14,7 @@
   Flags:
   Size of this header:               64 (bytes)
   Size of program header entries:    56 (bytes)
-  Number of program headers entries: -1 (66000 in [0].sh_info)
+  Number of program headers entries: 65535 (66000 in [0].sh_info)
   Size of section header entries:    64 (bytes)
   Number of section headers entries: 1
   Section header string table index: 0
FAIL run-getphdrnum.sh (exit status: 1)

6 months agoelflint: Do not raise an error when note type is unrecognized
Aaron Merey [Thu, 9 Oct 2025 21:08:30 +0000 (17:08 -0400)] 
elflint: Do not raise an error when note type is unrecognized

check_note_data compares the type of a given ELF note to a list of known
types.  If the type is not recognized then an "unknown note" error is
raised.

Unknown note types do not necessarily indicate a gABI/psABI compliance
issue so an error should not be raised for this reason alone.
Additionally some common note types are missing from the list of known
types (NT_FILE for example).

Fix this by removing the "unknown note" error from check_note_data.

This patch preserves existing type-specific format checks and adds a
check for the presence of the null terminator in the note name, if
applicable.  If one of these checks fails, a "malformed note" or
"missing null terminator" error is raised.

Since there are currently no type-specific checks for any ET_CORE
notes, these checks are only performed when the given binary does not
have e_type ET_CORE.

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

Signed-off-by: Aaron Merey <amerey@redhat.com>
6 months agolibdwfl_stacktrace: fix non-Linux build dep on PERF_SAMPLE_REGS_ABI
Serhei Makarov [Mon, 8 Sep 2025 16:10:54 +0000 (12:10 -0400)] 
libdwfl_stacktrace: fix non-Linux build dep on PERF_SAMPLE_REGS_ABI

Reported on a GNU Hurd build of elfutils. This is a quick fix pending
my more complex patch to reduce dependency on linux perf concepts for
the libdwfl_stacktrace code.

* libdwfl_stacktrace/dwflst_perf_frame.c (perf_sample_regs_abi):
  Define this Linux enum on non-Linux platforms.

6 months agolibelf: elf[32|64]_offscn shouldn't return a result for empty sections
Mark Wielaard [Tue, 14 Oct 2025 16:21:54 +0000 (18:21 +0200)] 
libelf: elf[32|64]_offscn shouldn't return a result for empty sections

offscn sets the result before checking the section isn't empty. It
assumes the result will be reset for the next section that matches the
given offset. But this might not be the case, for example if this was
the last section. It will then return that section (and set elf_errno)
instead of returning NULL to indicate no non-empty section matched.

* libelf/elf32_offscn.c (offscn): Move assignment to result
after empty size check.

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 months agoconfigure.ac: Add option --with-libarchive
Aaron Merey [Thu, 9 Oct 2025 00:31:20 +0000 (20:31 -0400)] 
configure.ac: Add option --with-libarchive

libarchive is required to build debuginfod server and optional for
eu-srcfiles (it enables the --zip option). If neither debuginfod server
nor eu-srcfiles --zip are needed, libarchive can be excluded from the
build.

Currently there is no way to exclude libarchive from the build if
PKG_CHECK_MODULES finds it at configure time.  While debuginfod server
can be disabled with --disable-debuginfod, eu-srcfiles is
unconditionally built with libarchive if it is found.

Add configure option --with-libarchive so that this behavior can be
overridden.

--without-libarchive and --enable-debuginfod cannot be used together.

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

Signed-off-by: Aaron Merey <amerey@redhat.com>
6 months agogelf_getnote.c: Replace assert with eu_static_assert
Aaron Merey [Tue, 7 Oct 2025 16:34:17 +0000 (12:34 -0400)] 
gelf_getnote.c: Replace assert with eu_static_assert

Two runtime asserts in gelf_getnote() compare sizeof GElf_Nhdr with
Elf32_Ndhr and Elf64_Nhdr.  This can be done at compile time using
eu_static_assert.

Signed-off-by: Aaron Merey <amerey@redhat.com>
6 months agoreadelf.c: Avoid repeating calls to gettext _() in hotpath
Aaron Merey [Mon, 22 Sep 2025 01:30:17 +0000 (21:30 -0400)] 
readelf.c: Avoid repeating calls to gettext _() in hotpath

Calls to the gettext _() macro in hotpaths results in unnecessary lookups
of the same translation strings during runtime.

Avoid this performance cost by calling _() for hotpath strings just once
and storing the results.  Runtime speedup of up to 17% has been observed
with this patch applied.

Signed-off-by: Aaron Merey <amerey@redhat.com>
7 months agoelfutils.spec.in: Add gelf man pages to %{_mandir}
Aaron Merey [Wed, 17 Sep 2025 03:09:52 +0000 (23:09 -0400)] 
elfutils.spec.in: Add gelf man pages to %{_mandir}

Signed-off-by: Aaron Merey <amerey@redhat.com>
7 months agodoc: Add gelf_getehdr.3
Aaron Merey [Sun, 14 Sep 2025 23:21:02 +0000 (19:21 -0400)] 
doc: Add gelf_getehdr.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
7 months agodoc: Add gelf_getclass.3
Aaron Merey [Sun, 14 Sep 2025 23:21:01 +0000 (19:21 -0400)] 
doc: Add gelf_getclass.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
7 months agodoc: Add elf_memory.3
Aaron Merey [Sun, 14 Sep 2025 23:21:00 +0000 (19:21 -0400)] 
doc: Add elf_memory.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
7 months agodoc: Add elf_flag*.3
Aaron Merey [Sun, 14 Sep 2025 23:20:59 +0000 (19:20 -0400)] 
doc: Add elf_flag*.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
7 months agolibelf: check ehdr isn't NULL before calling default_ehdr
Mark Wielaard [Mon, 15 Sep 2025 21:58:08 +0000 (23:58 +0200)] 
libelf: check ehdr isn't NULL before calling default_ehdr

default_ehdr assumes the passed ehdr pointer is not NULL and can be
directly dereferenced. But getehdr can return NULL. So explicitly
check.

* libelf/elf32_updatenull.c (updatenull_wrlock): Check ehdr is
        not NULL.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 months agoreadelf.c: Close dwfl if dwfl_report_offline fails
Aaron Merey [Mon, 8 Sep 2025 02:17:29 +0000 (22:17 -0400)] 
readelf.c: Close dwfl if dwfl_report_offline fails

Within create_dwfl, if dwfl_begin is successful but dwfl_report_offline
fails, the dwfl * pointer being reported is reset to NULL without calling
dwfl_end, causing a memory leak.

Update create_dwfl to call dwfl_end in this case, preventing the leak.

Signed-off-by: Aaron Merey <amerey@redhat.com>
7 months agoelf_begin.c: Use relative offset in archive size check
Aaron Merey [Mon, 8 Sep 2025 02:17:28 +0000 (22:17 -0400)] 
elf_begin.c: Use relative offset in archive size check

Before creating an elf descriptor for an archive member, dup_elf
verifies that the size of an archive is large enough to contain the
member.  This check uses the member's offset relative to the map_address
of the top-level archive containing the member.

This check can incorrectly fail when an archive contains another
archive as a member.  For members of the inner archive, their offset
relative to the outer archive might be significantly larger than
the max_size of the inner archive.  This appears as if the offset and
max_size values are inconsistent and the creation of the member's elf
descriptor is stopped unnecessarily.

Fix this by accounting for the inner archive's non-zero start_offset
when judging whether the member can fit within it.

Also perform this size check before creating a copy of the member's
Elf_Arhdr to prevent leaking the header's ar_name and ar_rawname if
the size check fails.

Signed-off-by: Aaron Merey <amerey@redhat.com>
7 months agolibelf: Check ELF parent size can contain ar member
Mark Wielaard [Sat, 6 Sep 2025 10:39:15 +0000 (12:39 +0200)] 
libelf: Check ELF parent size can contain ar member

Don't trust the ar header offset and size. When creating an Elf
descriptor for an ar member check the offset isn't past the end of the
containing Elf and don't use/set the member maximum_size larger than
the remaining size of the parent.

* libelf/elf_begin.c (dup_elf): Only call read_file if the
        offset isn't past the end and with a maximum_size not too large.

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 months agolibdw_open_elf: Avoid invalid free
Aaron Merey [Fri, 5 Sep 2025 19:27:52 +0000 (15:27 -0400)] 
libdw_open_elf: Avoid invalid free

If libdw_open_elf detects an invalid ELF file, it may attempt to
temporarily treat it as an ELF archive in order to check if there's
a valid ELF file following a header.

When doing this, the elf descriptor for the invalid file is given
the dummy state.ar.elf_ar_hdr.ar_name "libdwfl is faking you out".

Afterwards libdw_open_elf will call elf_end on the elf descriptor
for the invalid ELF file.  elf_end will attempt to free the address
of the "libdwfl is faking you out" literal, causing an invalid free.

Fix this by setting the ar_name to NULL before libdw_open_elf calls
elf_end on the descriptor of the invalid ELF file.

Signed-off-by: Aaron Merey <amerey@redhat.com>
7 months agodoc: Add elf_next.3
Aaron Merey [Tue, 5 Aug 2025 03:24:43 +0000 (23:24 -0400)] 
doc: Add elf_next.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
7 months agodoc: Add elf_rawdata.3
Aaron Merey [Tue, 5 Aug 2025 03:24:42 +0000 (23:24 -0400)] 
doc: Add elf_rawdata.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
7 months agodoc: Add elf_rand.3
Aaron Merey [Tue, 5 Aug 2025 03:24:41 +0000 (23:24 -0400)] 
doc: Add elf_rand.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
7 months agodoc: Add elf_newscn.3
Aaron Merey [Fri, 5 Sep 2025 15:28:15 +0000 (11:28 -0400)] 
doc: Add elf_newscn.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
7 months agodoc: Add elf_newdata.3
Aaron Merey [Fri, 5 Sep 2025 15:18:11 +0000 (11:18 -0400)] 
doc: Add elf_newdata.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
7 months agodoc: Add elf_gnu_hash.3
Aaron Merey [Fri, 5 Sep 2025 15:16:57 +0000 (11:16 -0400)] 
doc: Add elf_gnu_hash.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
7 months agodoc: Add elf_getshdrstrndx.3 and elf_getshstrndx.3
Aaron Merey [Fri, 5 Sep 2025 14:21:20 +0000 (10:21 -0400)] 
doc: Add elf_getshdrstrndx.3 and elf_getshstrndx.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
7 months agodoc: Add elf_getshdrnum.3 and elf_getshnum.3
Aaron Merey [Fri, 5 Sep 2025 14:18:42 +0000 (10:18 -0400)] 
doc: Add elf_getshdrnum.3 and elf_getshnum.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
7 months agodoc: Add elf_getphdrnum.3
Aaron Merey [Tue, 5 Aug 2025 03:24:35 +0000 (23:24 -0400)] 
doc: Add elf_getphdrnum.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
7 months agodoc: Add elf_getident.3
Aaron Merey [Tue, 5 Aug 2025 03:24:34 +0000 (23:24 -0400)] 
doc: Add elf_getident.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
7 months agodoc: Add elf_getdata_rawchunk.3
Aaron Merey [Tue, 5 Aug 2025 03:24:33 +0000 (23:24 -0400)] 
doc: Add elf_getdata_rawchunk.3

Signed-off-by: Aaron Merey <amerey@redhat.com>
7 months agoelf_getdata_rawchunk.c: Fix dummy chunk insertion race condition
Aaron Merey [Mon, 28 Jul 2025 20:32:28 +0000 (16:32 -0400)] 
elf_getdata_rawchunk.c: Fix dummy chunk insertion race condition

When elf_getdata_rawchunk aquires a new chunk for the first time, it
inserts a stack-allocated dummy chunk into a search_tree with a rdlock
held.  When the real chunk is prepared to replace the dummy chunk, the
rdlock is released and a wrlock is then held while replacing the
dummy with the real chunk.

Before the wrlock is held, other threads could incorrectly acquire the
dummy chunk as if it were a real chunk.

Fix this by holding a wrlock throughout elf_getdata_rawchunk.

Signed-off-by: Aaron Merey <amerey@redhat.com>
7 months ago__libdw_dieabbrev: Replace rwlock with __atomic builtins
Aaron Merey [Tue, 2 Sep 2025 00:31:28 +0000 (20:31 -0400)] 
__libdw_dieabbrev: Replace rwlock with __atomic builtins

__libdw_dieabbrev uses the abbrev_lock rwlock to synchronize access to the
Dwarf_Die abbrev field as well as its lazy loading.  Calls to rwlock_wrlock
and unlock incur significant performance overhead even in single-threaded
cases.

This patch implements thread safety in __libdw_dieabbrev with GCC __atomic
builtins instead of an rwlock, improving performance.  abbrev_lock has been
changed to a mutex and now synchronizes access to the Dwarf_CU field
last_abbrev_offset in __libdw_findabbrev.

libdw/
* dwarf_begin_elf.c (valid_p): Change type of abbrev_lock from
rwlock to mutex.
* dwarf_end.c (cu_free): Ditto.
* dwarf_tag.c (__libdw_findabbrev): Protect
cu->last_abbrev_offset with mutex.
* libdwP.h (struct Dwarf_CU): Change type of abbrev_lock from
rwlock to mutex.
(__libdw_dieabbrev): Use __atomic builtins instead of rwlock.
* libdw_findcu.c (__libdw_intern_next_unit): Change type of
abbrev_lock from rwlock to mutex.

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