]> git.ipfire.org Git - thirdparty/elfutils.git/log
thirdparty/elfutils.git
4 months agolibdw: Add dwarf_language and dwarf_language_lower_bound functions.
Mark Wielaard [Thu, 30 Jan 2025 17:53:25 +0000 (18:53 +0100)] 
libdw: Add dwarf_language and dwarf_language_lower_bound functions.

dwarf_language returns a DW_LNAME constant for a CU Die. If the CU Die
has a DW_AT_language_name attribute dwarf_language will return it and
the DW_AT_language_version attribute value. Otherwise dwarf_language
will lookup the (old style) DW_AT_language attribute and translate the
DW_LANG constant into a DW_LNAME constant and version using a new
static function srclang_to_language.

The dwarf_language_lower_bound function works just like the
dwarf_default_lower_bound function, but takes a DW_LNAME constant
instead of a DW_LANG constant.

Adds a new test to make sure dwarf_language_lower_bound handles all
known DW_LNAME constants.

    * NEWS: Add new functions.
    * libdw/libdw.map (ELFUTILS_0.193): New section with new functions.
    * libdw/libdw.h (dwarf_srclang): Add comment explaining this
    returns DW_LANG constants.
    (dwarf_language): New function.
    (dwarf_default_lower_bound): Add comment explaining this works on
    DW_LANG constants.
    (dwarf_language_lower_bound): New function.
    * libdw/libdwP.h: INTDECL dwarf_language and
    dwarf_language_lower_bound.
    * libdw/dwarf_srclang.c (srclang_to_language): New function.
    (dwarf_language): Likewise.
    * libdw/dwarf_default_lower_bound.c (dwarf_language_lower_bound):
    New function.
    * libdw/dwarf_getfuncs.c (dwarf_getfuncs):  Use dwarf_language and
    dwarf_language_lower_bound.
    * libdw/dwarf_aggregate_size.c (array_size): Likewise.
    * tests/dwarf_language_lower_bound.c: New test.
    * tests/Makefile.am (check_PROGRAMS): Add dwarf_language_lower_bound.
    (TESTS): Likewise.
    (dwarf_language_lower_bound_LDADD): New variable.

Signed-off-by: Mark Wielaard <mark@klomp.org>
4 months agodwarf.h: Add DWARF v6 langauge attributes and DW_LNAME constants
Mark Wielaard [Wed, 29 Jan 2025 14:35:06 +0000 (15:35 +0100)] 
dwarf.h: Add DWARF v6 langauge attributes and DW_LNAME constants

https://dwarfstd.org/languages-v6.html defines the DWARF v6 language
attributes, DW_AT_language_name, DW_AT_language_version and DW_LNAME
constants as usable by pre-DWARF v6 producers and consumers.

Also add new DW_LANG_V and DW_LANG_Algol68 (DWARFv5) language constants.

    * config/known-dwarf.awk: Handle DW_LNAME.
    * libdw/dwarf.h: Add DW_AT_language_name and DW_AT_language_version
    plus all currently defined DW_LNAME constants. Add DW_LANG_V and
    DW_LANG_Algol68.
    * libdw/dwarf_default_lower_bound.c: Add DW_LANG_V and
    DW_LANG_Algol68.

Signed-off-by: Mark Wielaard <mark@klomp.org>
4 months agoPR31862: debuginfod: client to cache x-debuginfod-* headers
Frank Ch. Eigler [Wed, 5 Mar 2025 20:23:49 +0000 (15:23 -0500)] 
PR31862: debuginfod: client to cache x-debuginfod-* headers

This feature allows the extra http headers from debuginfod to be saved
into the client cache, and also thus replayed to clients.  This way
they can perform IMA verification again, if they like, or a federating
caching intermediate debuginfod server can replay the headers it
received previously from upstream to future downstream.  The headers
are placed adjacent to the payload files .cache/debuginfod/BUILDID/PAYLOAD
as .cache/debuginfod/BUILDID/hdr-PAYLOAD.  They are aged the same
atime-based way.

Testing via an extension of a previous small test, and hand-running both
client & server code under valgrind.  No memcheck errors reported.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
5 months agolibelf: Rewrite elf_scnshndx, extended index table handling
Mark Wielaard [Tue, 18 Feb 2025 22:24:48 +0000 (23:24 +0100)] 
libelf: Rewrite elf_scnshndx, extended index table handling

elf_scnshndx is a elfutils extension to libelf that given a SHT_SYMTAB
section returns the index to the corresponding SHT_SYMTAB_SHNDX
section, if it exists. This is needed when there are more than 64K
sections and there are symbols that have to refer to a section with an
index larger than 64K, because the Elf Sym st_shndx field is only
16 bits.

This was implemented by adding an shndx_index field to the Elf_Scn
struct which is updated when reading the section headers. This takes
up space in every section and is hard to proof correct. In the case of
using ELF_C_READ_MMAP the shndx_index field was only updated when the
shdrs needed to be converted from file to memory order.

And the two places were this function was used in readelf.c and
elf-print-reloc-syms.c the wrong section was used to lookup the
extended index table. There were also no tests for this functionality.

Replace the elf_scnshndx implementation with a simpler lookup over all
sections. This sounds inefficient, but in practice the
SHT_SYMTAB_SHNDX section is the next section after the SHT_SYMTAB
section. elf_scnshndx only needs to be called when there are more than
SHN_LORESERVE (0xff00) sections. And normally a user would just lookup
the SHT_SYMTAB and SHT_SYMTAB_SHNDX sections at the same time (which
is what readelf does when showing the symbol table, as does nm,
objcopy and libdwfl).

Add a testfile manyfuncs.c that when compiled contains 64K symbols and
sections. Make sure to use -fasynchronous-unwind-tables so there is at
least one relocatable section that uses all function symbols (e.g. on
arm32 where there is no .eh_frame by default). This can then be used
to verify the readelf --relocs support. Add another test,
test-manyfuncs that explicitly goes through the symbol table and
associated extended index table and verify each function symbol
matches the section name.

There are For riscv there are local, notype, symbols at the start of each
executable section which relocations refer to instead of the section
symbol. Since all these local symbols are called ".L0" this isn't very
useful, so print the section name instead. For powerpc ELFv1 all
function symbols go through the .opd section. Allow this in the new
test-manyfuncs test.

* libelf/elf32_getshdr.c (load_shdr_wrlock): Remove handling
        of shndx_index.
* libelf/elf_begin.c (file_read_elf): Likewise.
* libelf/elf_scnshndx.c (elf_scnshndx): Rewritten.
* libelf/libelf.h (elf_scnshndx): Added full documentation.
* libelf/libelfP.h (struct Elf_Scn): Remove shndx_index field.
(__elf_scnshndx_internal): Removed.
* src/readelf.c (handle_relocs_rel): Use symscn in call to
elf_scnshndx. Print section name for local start section label.
(handle_relocs_rela): Likewise.
* tests/Makefile.am (check_PROGRAMS): Add test-manyfuncs.
(manyfuncs.o): New target.
(check-local): New target, depends on manyfuncs.o.
(TESTS): Add run-readelf-r-manyfuncs.sh and
run-test-manyfuncs.sh.
(EXTRA_DIST): Add run-readelf-r-manyfuncs.sh,
run-test-manyfuncs.sh and manyfuncs.c.
(test_manyfuncs_LDADD): New variable.
(EXTRA_test_manyfuncs_DEPENDENCIES): New variable.
(CLEANFILES): Add manyfuncs.o.
* tests/elf-print-reloc-syms.c (print_reloc_symnames):
Use symscn in call to elf_scnshndx.
* tests/manyfuncs.c: New test file to generate 64K symbols and
        sections.
* tests/run-readelf-r-manyfuncs.sh: New test wrapper.
* tests/run-test-manyfuncs.sh: Likewise.
* tests/test-manyfuncs.c: New test.

Signed-off-by: Mark Wielaard <mark@klomp.org>
5 months agoreadelf: Use section_name instead of elf_strptr in print_debug_frame_section
Mark Wielaard [Thu, 27 Feb 2025 20:22:49 +0000 (21:22 +0100)] 
readelf: Use section_name instead of elf_strptr in print_debug_frame_section

All other print_debug_* functions use section_name (ebl, shdr) to get
the current section name. Be consistent and use the same method in
print_debug_frame_section to make static analyzers happy who might
think elf_strptr can return NULL in this case.

      * src/readelf.c (print_debug_frame_section): Use section_name
      instead of elf_strptr to get the section name.

Signed-off-by: Mark Wielaard <mark@klomp.org>
5 months agoreadelf: check elf_getarhdr returns NULL in dump_archive_index
Anton Moryakov [Thu, 13 Feb 2025 15:57:42 +0000 (18:57 +0300)] 
readelf: check elf_getarhdr returns NULL in dump_archive_index

Report of the static analyzer:
DEREF_OF_NULL.RET Pointer, returned from function 'elf_getarhdr' at
readelf.c:13551, may be NULL and is dereferenced at readelf.c:13553.

    * src/readelf.c (dump_archive_index): Check elf_getarhdr doesn't
    return NULL.

Triggers found by static analyzer Svace.

Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
5 months agoaarch64: define struct user_pac_mask if needed
Markus Mayer [Fri, 21 Feb 2025 19:19:34 +0000 (11:19 -0800)] 
aarch64: define struct user_pac_mask if needed

On Aarch64, Linux is using Pointer Authentication Code (PAC) for pointer
authentication.[1] The struct "user_pac_mask" has been part of the Linux
kernel since version 5.0 as part of this feature. However, older kernels
do not define it.

Therefore, we want to check if the definition is present in the kernel
headers and provide one if it isn't. This ensures two things:

* elfutils will continue to compile against kernel headers from 4.x
* binaries built against older kernel headers will still be fully
  functional if used on a newer system

For reference, the build error that is being avoided looks like this:

[...]
  CC       aarch64_initreg.o
aarch64_initreg.c: In function 'aarch64_set_initial_registers_tid':
aarch64_initreg.c:61:24: error: storage size of 'pac_mask' isn't known
   struct user_pac_mask pac_mask;
                        ^~~~~~~~
aarch64_initreg.c:61:24: warning: unused variable 'pac_mask' [-Wunused-variable]
make[4]: *** [Makefile:831: aarch64_initreg.o] Error 1
make[3]: *** [Makefile:547: all-recursive] Error 1
make[2]: *** [Makefile:463: all] Error 2

[1] https://docs.kernel.org/arch/arm64/pointer-authentication.html

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

Fixes: 64e3b451ad2c ("aarch64: extend dwfl_thread_state_registers to handle PAC")
Signed-off-by: Markus Mayer <mmayer@broadcom.com>
5 months agoRevert "debuginfod-client: correct invalid free() in failed ima path"
Frank Ch. Eigler [Thu, 20 Feb 2025 19:18:24 +0000 (14:18 -0500)] 
Revert "debuginfod-client: correct invalid free() in failed ima path"

This reverts commit a71bac67f4705b84368b71f5ece54deedaa1abf1.
Commit 1be0787d6654ed71bf659e8bfd already fixes this problem.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
5 months agodebuginfod-client: correct invalid free() in failed ima path
Frank Ch. Eigler [Wed, 19 Feb 2025 03:09:12 +0000 (22:09 -0500)] 
debuginfod-client: correct invalid free() in failed ima path

debuginfod-find with a failed signature configuration was found on f41
glibc (2.40) to sometimes leave invalid addresses in a sscanf("%ms", &ptr)
pointer in case of error, leading to an invalid free() during cleanup.
We now clear that ptr manually, making valgrind happy.  Unclear why this
hasn't shown up in testsuite testing.

==1098106== Invalid free() / delete / delete[] / realloc()
==1098106==    at 0x4844B83: free (vg_replace_malloc.c:989)
==1098106==    by 0x49647A2: ??? (in /usr/lib64/libdebuginfod-0.192.so)
==1098106==    by 0x401528: main (debuginfod-find.c:209)
==1098106==  Address 0xc8 is not stack'd, malloc'd or (recently) free'd

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
5 months agolibelf: Handle elf_strptr on section without any data
Mark Wielaard [Wed, 12 Feb 2025 23:02:32 +0000 (00:02 +0100)] 
libelf: Handle elf_strptr on section without any data

In the unlikely situation that elf_strptr was called on a section with
sh_size already set, but that doesn't have any data yet we could crash
trying to verify the string to return.

This could happen for example when a new section was created with
elf_newscn, but no data having been added yet.

* libelf/elf_strptr.c (elf_strptr): Check strscn->rawdata_base
is not NULL.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
5 months agostrip: Verify symbol table is a real symbol table
Mark Wielaard [Thu, 13 Feb 2025 13:59:34 +0000 (14:59 +0100)] 
strip: Verify symbol table is a real symbol table

We didn't check the symbol table referenced from the relocation table
was a real symbol table. This could cause a crash if that section
happened to be an SHT_NOBITS section without any data. Fix this by
adding an explicit check.

       * src/strip.c (INTERNAL_ERROR_MSG): New macro that takes a
       message string to display.
       (INTERNAL_ERROR): Use INTERNAL_ERROR_MSG with elf_errmsg (-1).
       (remove_debug_relocations): Check the sh_link referenced
       section is real and isn't a SHT_NOBITS section.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
5 months agoreadelf: Skip trying to uncompress sections without a name
Mark Wielaard [Sat, 8 Feb 2025 23:07:39 +0000 (00:07 +0100)] 
readelf: Skip trying to uncompress sections without a name

When combining eu-readelf -z with -x or -p to dump the data or strings
in an (corrupted ELF) unnamed numbered section eu-readelf could crash
trying to check whether the section name starts with .zdebug. Fix this
by skipping sections without a name.

   * src/readelf.c (dump_data_section): Don't try to gnu decompress a
   section without a name.
   (print_string_section): Likewise.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
5 months agoreadelf: Handle NULL phdr in handle_dynamic_symtab
Mark Wielaard [Sat, 8 Feb 2025 23:07:13 +0000 (00:07 +0100)] 
readelf: Handle NULL phdr in handle_dynamic_symtab

A corrupt ELF file can have broken program headers, in which case
gelf_getphdr returns NULL. This could crash handle_dynamic_symtab
while searching for the PT_DYNAMIC phdr. Fix this by checking whether
gelf_phdr returns NULL.

  * src/readelf.c (handle_dynamic_symtab): Check whether
          gelf_getphdr returns NULL.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
5 months agolibelf, readelf: Use validate_str also to check dynamic symstr data
Mark Wielaard [Sat, 8 Feb 2025 20:44:56 +0000 (21:44 +0100)] 
libelf, readelf: Use validate_str also to check dynamic symstr data

When dynsym/str was read through eu-readelf --dynamic by readelf
process_symtab the string data was not validated, possibly printing
unallocated memory past the end of the symstr data. Fix this by
turning the elf_strptr validate_str function into a generic
lib/system.h helper function and use it in readelf to validate the
strings before use.

* libelf/elf_strptr.c (validate_str): Remove to...
* lib/system.h (validate_str): ... here. Make inline, simplify
check and document.
* src/readelf.c (process_symtab): Use validate_str on symstr_data.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
5 months agolibdw: Simplify __libdw_getabbrev and fix dwarf_offabbrev issue
Mark Wielaard [Sat, 8 Feb 2025 19:00:12 +0000 (20:00 +0100)] 
libdw: Simplify __libdw_getabbrev and fix dwarf_offabbrev issue

__libdw_getabbrev could crash on reading a bad abbrev by trying to
deallocate memory it didn't allocate itself. This could happen because
dwarf_offabbrev would supply its own memory when calling
__libdw_getabbrev. No other caller did this.

Simplify the __libdw_getabbrev common code by not taking external
memory to put the abbrev result in (this would also not work correctly
if the abbrev was already cached). And make dwarf_offabbrev explicitly
copy the result (if there was no error or end of abbrev).

     * libdw/dwarf_getabbrev.c (__libdw_getabbrev): Don't take
     Dwarf_Abbrev result argument. Always just allocate abb when
     abbrev not found in cache.
     (dwarf_getabbrev): Don't pass NULL as last argument to
     __libdw_getabbrev.
    * libdw/dwarf_tag.c (__libdw_findabbrev): Likewise.
    * libdw/dwarf_offabbrev.c (dwarf_offabbrev): Likewise. And copy
    abbrev into abbrevp on success.
    * libdw/libdw.h (dwarf_offabbrev): Document return values.
    * libdw/libdwP.h (__libdw_getabbrev): Don't take Dwarf_Abbrev
    result argument.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
5 months agoelflint: process_file both prefix and suffix are NULL or both are non-NULL
Mark Wielaard [Tue, 11 Feb 2025 13:46:44 +0000 (14:46 +0100)] 
elflint: process_file both prefix and suffix are NULL or both are non-NULL

Add an assert of this property to help static analyzers (or humans)
reading this code.

* src/elflint.c (process_file): Add assert.

Signed-off-by: Mark Wielaard <mark@klomp.org>
5 months agotests/Makefile.am: Add --track-fds=yes to valgrind_cmd
Aaron Merey [Fri, 31 Jan 2025 01:16:34 +0000 (20:16 -0500)] 
tests/Makefile.am: Add --track-fds=yes to valgrind_cmd

`valgrind --track-fds=yes` will report errors for file descriptor leaks
and attempts at closing invalid file descriptors.

Signed-off-by: Aaron Merey <amerey@redhat.com>
5 months agotests: Avoid leaking file descriptors
Aaron Merey [Fri, 31 Jan 2025 01:21:03 +0000 (20:21 -0500)] 
tests: Avoid leaking file descriptors

Add calls to close for all test programs that leak file descriptors
in order to prevent test failures when run under valgrind
--track-fds=yes.

Signed-off-by: Aaron Merey <amerey@redhat.com>
5 months agotests/backtrace-subr.sh: Avoid valgrind track-fds in check_native_core
Aaron Merey [Fri, 31 Jan 2025 01:17:28 +0000 (20:17 -0500)] 
tests/backtrace-subr.sh: Avoid valgrind track-fds in check_native_core

valgrind --track-fds=yes might incorrectly report an error due to the use
of inherited file descriptors in check_native_core.

Prevent this false positive by temporarily removing "--track-fds=yes" from
$VALGRIND_CMD for the duration of the testrun in check_native_core.

Signed-off-by: Aaron Merey <amerey@redhat.com>
5 months agolibdwfl/offline.c: Avoid closing invalid fd
Aaron Merey [Fri, 31 Jan 2025 01:16:11 +0000 (20:16 -0500)] 
libdwfl/offline.c: Avoid closing invalid fd

process_archive may be called with an fd argument of -1, which
libelf interprets as "no file opened".  However when closing
the fd process_archive does not check whether the fd is valid
and may attempt to close an fd of -1.

Signed-off-by: Aaron Merey <amerey@redhat.com>
5 months agoobjdump: Handle elf_getarhdr returning NULL in handle_ar
Anton Moryakov [Tue, 4 Feb 2025 21:50:23 +0000 (00:50 +0300)] 
objdump: Handle elf_getarhdr returning NULL in handle_ar

Report of the static analyzer:
Pointer, returned from function 'elf_getarhdr' at objdump.c:314,
may be NULL and is dereferenced at objdump.c:317. (CWE-476, CWE-690)

Corrections explained:
When processing archive elements, the code could dereference a NULL
pointer if 'elf_getarhdr' returns NULL. This patch adds a check to
ensure 'arhdr' is not NULL before using it. The fix ensures that the
function safely handles cases where 'elf_getarhdr' fails, avoiding
potential crashes.

Triggers found by static analyzer Svace.

Signed-off-by: Anton Moryakov <ant.v.moryakov@gmail.com>
5 months agostacktrace: Add missing locale.h
Alfred Wingate [Wed, 29 Jan 2025 08:06:22 +0000 (10:06 +0200)] 
stacktrace: Add missing locale.h

The missing header is only obvious on musl and on glibc when you don't
have optimizations enabled.

Normally the header would transitively come from config.h -> ./lib/eu-config.h
-> glibc libintl.h. with __OPTIMIZE__.

https://sourceware.org/git/?p=glibc.git;a=blob;f=intl/libintl.h;hb=HEAD#l103

Signed-off-by: Alfred Wingate <parona@protonmail.com>
6 months agoDeclare HAVE_ERROR_H only if error symbol is available
Alfred Wingate [Wed, 29 Jan 2025 07:32:49 +0000 (09:32 +0200)] 
Declare HAVE_ERROR_H only if error symbol is available

Musl doesn't provide error.h. But there exists a standalone implementation
that installs /usr/include/error.h but requires explicit linkage. This
leads linkage errors later on due to the assumption that error
symbols are provided by the libc.

Bug: https://bugs.gentoo.org/948878
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=32548
Signed-off-by: Alfred Wingate <parona@protonmail.com>
6 months agoAdd eu_search_tree_init
Aaron Merey [Sun, 19 Jan 2025 01:23:50 +0000 (20:23 -0500)] 
Add eu_search_tree_init

* libdw/dwarf_begin_elf.c (dwarf_begin_elf): Initialize
eu_search_trees.

Signed-off-by: Aaron Merey <amerey@redhat.com>
6 months agosrc/readelf.c: Close skel_fd
Aaron Merey [Sat, 25 Jan 2025 01:21:57 +0000 (20:21 -0500)] 
src/readelf.c: Close skel_fd

skel_fd is passed to create_dwfl, which calls dup() on skel_fd.
create_dwfl handles closing the duped fd but not the original.

Ensure the original skel_fd is closed after it's passed to create_dwfl.

Signed-off-by: Aaron Merey <amerey@redhat.com>
6 months agodebuginfod-client.c: Avoid freeing uninitialized value
Aaron Merey [Sat, 25 Jan 2025 00:43:19 +0000 (19:43 -0500)] 
debuginfod-client.c: Avoid freeing uninitialized value

debuginfod_validate_imasig might call free on an uninitialized sig_buf
due to a goto that can occur before sig_buf is set to NULL.

Fix this by setting sig_buf to NULL before the goto.

Signed-off-by: Aaron Merey <amerey@redhat.com>
6 months agoReplace usage of ar with stored library manifest files
Michael Pratt [Mon, 13 Jan 2025 23:56:38 +0000 (23:56 +0000)] 
Replace usage of ar with stored library manifest files

The ar program is called to assemble a list of objects
within each archive to assist in building combined libraries,
however make already has this information
when processing the subdirectory for that respective library.
The list can be saved in a "manifest" file
instead of being generated whenever it is needed
for use with other subdirectories.

Even though the difference in time is insignificant,
a simple "echo" and "cat" is as much as 10 times faster
than a call to "ar t" for printing the archive members.

Since elfutils builds ar,
this also removes the awkward circular dependency
where an installation of ar is required
to build the libraries for ar.

Additionally, not every version of ar is equally portable,
as native versions of ar on macOS and other BSD-like distributions
may print out a special archive member like "__.SYMDEF"
which is not a compiled object but rather just metadata
from ranlib, leading to a build failure.

Avoid these limitations by removing usage of ar
and adding build and clean rules
for the usage of archive manifest files.

    * .gitignore: exclude ".manifest" file extension.
    * backends/Makefile.am: add manifest file build and clean rules.
    * debuginfod/Makefile.am: Likewise.
    * lib/Makefile.am: Likewise.
    * libasm/Makefile.am: Likewise.
    * libcpu/Makefile.am: Likewise.
    * libdw/Makefile.am: Likewise,
      and set object lists to manifest contents.
    * libdwelf/Makefile.am: Likewise.
    * libdwfl/Makefile.am: Likewise.
    * libebl/Makefile.am: Likewise.
    * libelf/Makefile.am: Likewise,
      and set object lists to manifest contents.
    * src/Makefile.am: Likewise.

Signed-off-by: Michael Pratt <mcpratt@pm.me>
6 months agolibdwfl/argp-std.c: Set offline_next_address for a.out default
Aaron Merey [Tue, 21 Jan 2025 00:20:12 +0000 (19:20 -0500)] 
libdwfl/argp-std.c: Set offline_next_address for a.out default

If none of -e, -p or -k is given as a command line option, libdwfl
parse_opt will use '-e a.out' as the default.

When handling -e, parse_opt will set dwfl->offline_next_address
to 0.  However when handling the default '-e a.out',
dwfl->offline_next_address is not set to 0.  This can result in
eu-addr2line failing to correctly output the line information for a
given address.

Fix this by setting dwfl->offline_next_address to 0 when setting up
the default '-e a.out' dwfl.

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

Signed-off-by: Aaron Merey <amerey@redhat.com>
6 months agoUpdate minimum C compiler supported to C11 plus stdatomic.h
Mark Wielaard [Mon, 18 Nov 2024 23:45:39 +0000 (00:45 +0100)] 
Update minimum C compiler supported to C11 plus stdatomic.h

We were using a somewhat odd mix of gnu99 with a fallback atomics.h so
we could build with gcc 4.7. Lets requires a compiler that can do at
least C11 and has a stdatomic.h. So we can build against any C
standard >= C11 (including C17 and C23). That means GCC 4.9+.
GCC 4.9 was released in 2014.

The lowest compiler version we check in the buildbots is currently
GCC 8.3.0 (Debian old old stable, released in 2018).

Also update the minimum autoconf version to 2.69. We would really like
2.70+ so we don't need the gnulib gnu11.m4. But 2.69 still seems in
use on various stable systems. autoconf 2.70 was released end of 2020,
autoconf 2.69 in 2012.

      * configure.ac (AC_PACKAGE_URL): Removed workaround for
      autoconf < 2.64.
      (AC_PREREQ): Update from 2.63 to 2.69.
      (AC_PROG_CC): Test for ac_cv_prog_cc_c11.
      (AC_CACHE_CHECK for stdatomic.h
      * config/eu.am (AM_CFLAGS): Remove -std=gnu99.
      * lib/Makefile.am (noinst_HEADERS): Remove atomics.h and
      stdatomic-fbsd.h.
      * lib/atomics.h: Removed.
      * lib/stdatomic-fbsd.h: Removed.
      * lib/dynamicsizehash_concurrent.h: Include stdatomic.h.
      * libdw/libdw_alloc.c: Likewise.
      * m4/.gitignore: Add !/std-gnu11.m4.
      * m4/std-gnu11.m4: New file from gnulib to provide AC_PROG_CC
      from autoconf 2.70.

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 months agolibcpu: Remove false positive null ptr deref warning for GCC -O3
Philippe Benard [Thu, 9 Jan 2025 13:59:00 +0000 (14:59 +0100)] 
libcpu: Remove false positive null ptr deref warning for GCC -O3

i386_lex_CFLAGS is a make variable to tweak the i386_lex.c.o
specific compile flags. The are already some -W defined there, I'd
like to add one to avoid seeing false warning during build with -O3
compile flag.

GCC 14.2 (as well as 13.x) produce a false positive warning for the
i386 lexer, a bug is filled already against GCC for that, CLANG is
immune.

* libcpu/Makefile.am
i386_lex_CFLAGS += $(subst -O3,-Wno-null-dereference,$(findstring -O3,$(CFLAGS)))

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

Signed-off-by: Philippe Benard <phi.debian@gmail.com>
6 months agoconfig: Put the -D option as first argument to INSTALL_DATA
Mark Wielaard [Wed, 8 Jan 2025 11:37:35 +0000 (12:37 +0100)] 
config: Put the -D option as first argument to INSTALL_DATA

INSTALL_DATA uses the install program to install files. The GNU
coreutils implementation of install takes options anywhere. Other
implementations of install might take options only before the source
and destination arguments.

* config/Makefile.am (all-local): Move -D option before
file and directory arguments.

Signed-off-by: Mark Wielaard <mark@klomp.org>
6 months agoConsolidate list of custom phony targets
Michael Pratt [Sun, 24 Nov 2024 19:03:58 +0000 (19:03 +0000)] 
Consolidate list of custom phony targets

Having a target defined as phony within a condition
while another target is always defined as phony
causes an automake warning:

  Makefile.am:67: warning: .PHONY was already defined in condition TRUE, which includes condition GCOV ...
  config/eu.am:141: ... '.PHONY' previously defined here
  Makefile.am:21:   'config/eu.am' included from here
  tests/Makefile.am:895: warning: .PHONY was already defined in condition TRUE, which includes condition GCOV ...
  config/eu.am:141: ... '.PHONY' previously defined here
  tests/Makefile.am:19:   'config/eu.am' included from here

Instead, list all the custom targets that are phony
in the common definitions in the eu.am file.

Since it is all related to coverage at this moment,
the list can be grouped as it is instead of moved or split.

    * Makefile.am: remove .PHONY list in conditional
    * config/eu.am: add coverage target to .PHONY list
    * tests/Makefile.am: remove .PHONY list in conditional

Signed-off-by: Michael Pratt <mcpratt@pm.me>
6 months agoConsolidate custom clean targets for coverage files
Michael Pratt [Sun, 24 Nov 2024 19:03:47 +0000 (19:03 +0000)] 
Consolidate custom clean targets for coverage files

As reported by Mark:

Since b2f225d6b ("Consolidate and add files to clean target variables")
autoreconf (automake) produces these warnings:

debuginfod/Makefile.am:130: warning: CLEANFILES multiply defined in condition TRUE ...
config/eu.am:138: ... 'CLEANFILES' previously defined here
debuginfod/Makefile.am:32:   'config/eu.am' included from here
libasm/Makefile.am:91: warning: CLEANFILES multiply defined in condition TRUE ...
config/eu.am:138: ... 'CLEANFILES' previously defined here
libasm/Makefile.am:30:   'config/eu.am' included from here
libcpu/Makefile.am:105: warning: CLEANFILES multiply defined in condition TRUE ...
config/eu.am:138: ... 'CLEANFILES' previously defined here
libcpu/Makefile.am:30:   'config/eu.am' included from here
libdw/Makefile.am:156: warning: CLEANFILES multiply defined in condition TRUE ...
config/eu.am:138: ... 'CLEANFILES' previously defined here
libdw/Makefile.am:30:   'config/eu.am' included from here
libelf/Makefile.am:142: warning: CLEANFILES multiply defined in condition TRUE ...
config/eu.am:138: ... 'CLEANFILES' previously defined here
libelf/Makefile.am:30:   'config/eu.am' included from here
src/Makefile.am:47: warning: CLEANFILES multiply defined in condition TRUE ...
config/eu.am:138: ... 'CLEANFILES' previously defined here
src/Makefile.am:19:   'config/eu.am' included from here
tests/Makefile.am:891: warning: CLEANFILES multiply defined in condition TRUE ...
config/eu.am:138: ... 'CLEANFILES' previously defined here
tests/Makefile.am:19:   'config/eu.am' included from here

This is because config/eu.am defines a default "CLEANFILES".

However, the list is only for the removal of coverage files.
Since there is an exising custom clean rule for coverage in Makefile.am
because there is a directory involved as well as files,
further simplification of these rule definitions can resolve this.

Define cleaning targets for coverage files
in a single place and as a common definition
for all generated Makefiles using a custom rule.
This allows for avoiding the use of "CLEANFILES"
variables for anything related to removing coverage files,
and removing the usage of this variable where there is a conflict,
as it is no longer needed to be defined there.

    * Makefile.am: remove variables and custom clean target.
    * config/eu.am: remove clean variables, add variables
      and custom clean target based on removed definitions.

Fixes: b2f225d6b ("Consolidate and add files to clean target variables")
Reported-by: Mark Wielaard <mark@klomp.org>
Signed-off-by: Michael Pratt <mcpratt@pm.me>
6 months agoMakefile.am: include common eu.am definitions
Michael Pratt [Sun, 24 Nov 2024 19:03:28 +0000 (19:03 +0000)] 
Makefile.am: include common eu.am definitions

Some definitions in Makefile.am can be moved
to the common definitions in config/eu.am,
but for them to apply to the top-level Makefile after moving,
eu.am must be added as an include statement.

Except for "CLEANFILES", handled in the next commit,
there are no definitions in eu.am that are defined in Makefile.am,
so there are no other conflicts or overrides between the two.

Signed-off-by: Michael Pratt <mcpratt@pm.me>
7 months agobackends: check_special_symbol _GLOBAL_OFFSET_TABLE_ points inside .got
Mark Wielaard [Mon, 30 Dec 2024 00:17:02 +0000 (01:17 +0100)] 
backends: check_special_symbol _GLOBAL_OFFSET_TABLE_ points inside .got

If desthdr is ".got.plt" search for the actual ".got" section and make
sure the _GLOBAL_OFFSET_TABLE_ points to it.

     * backends/riscv_symbol.c (riscv_check_special_symbol): Check
     sname is ".got.plt", find ".got" scn to check sym st_value.

Signed-off-by: Mark Wielaard <mark@klomp.org>
7 months agodebuginfod.cxx: Fix unused parameter warning
Aaron Merey [Tue, 10 Dec 2024 15:58:49 +0000 (10:58 -0500)] 
debuginfod.cxx: Fix unused parameter warning

Add __attribute__ ((unused)) to prevent unused param warnings in
is_seekable_archive and extract_from_seekable_archive when USE_LZMA is
false.

Signed-off-by: Aaron Merey <amerey@redhat.com>
7 months agodebuginfod: in --cors mode, add CORS response headers and OPTIONS method
Henning Meyer [Sat, 7 Dec 2024 20:01:54 +0000 (15:01 -0500)] 
debuginfod: in --cors mode, add CORS response headers and OPTIONS method

CORS is the Cross-Origin-Resource-Sharing mechanism explained at
https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS 1. by default
JavaScript code from Website A cannot request arbitrary resources from
website B, these are called cross-origin-requests 2. The browser
performs what is called a preflight check, this the OPTIONS method 3.
the response allows website B fine-grained control over what the web
browser should allow 4. Setting "Access-Control-Allow-Origin: *" tells
the web browser to allow all access, e.g. the same behavior you get with
curl or debuginfod-find The website mentions that the corresponding spec
has been changed, such that preflight requests are no longer necessary,
but in the browsers I use today (Firefox 132 and Chromium 131) they are
still necessary.

I have confirmed that I can use debuginfod with this patch from my web
application at https://core-explorer.github.io/cdx-type/

FChE simplified the code and added a few quick "curl -i | grep" tests
to confirm the new headers are there.

   * debuginfod/debuginfod.cxx (handle_options): New function.
   (handler_cb): Call it for OPTIONS.  Add ACAO header for all
   successful requests.
   (parse_opt): Parse --cors.
   * tests/run-debuginfod-federation-metrics.sh,
   tests/run-debuginfod-find-metadata.sh: Lightly test.
   * doc/debuginfod.8: Document --cors option, default off.

Signed-off-by: Henning Meyer <hmeyer.eu@gmail.com>
Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
7 months agolibdw: Update DW_LANG codes
Mark Wielaard [Fri, 22 Nov 2024 17:17:29 +0000 (18:17 +0100)] 
libdw: Update DW_LANG codes

Pick up the language codes published after DWARF5 was published.
The are listed at https://dwarfstd.org/languages.html

Also adjust C language dectection in dwarf_getfuncs and update the
dwarf_default_lower_bound function to return the default lower bounds
for the new langauge codes.

There is one small change in dwarf_default_lower_bound. We now return
zero instead of an error when called for DW_LANG_Mips_Assembler. Since
there is now an "official" DW_LANG_Assembly which is explicitly
defined as having a default lower bound of zero. It seems better to do
the same for the vendor code too.

    * libdw/dwarf.h: Add new DW_LANG codes.
    * libdw/dwarf_default_lower_bound.c (dwarf_default_lower_bound):
    Handle new language codes and remove a special case for
    DW_LANG_Mips_Assembler.
    * libdw/dwarf_getfuncs.c (dwarf_getfuncs): Check against
    DW_LANG_C17 and DW_LANG_C23.
    * tests/dwarf_default_lower_bound.c: Also check for
    DW_LANG_Mips_Assembler.

Signed-off-by: Mark Wielaard <mark@klomp.org>
8 months agosrcfiles.cxx: Prevent fd and entry leak
Aaron Merey [Mon, 18 Nov 2024 23:35:38 +0000 (18:35 -0500)] 
srcfiles.cxx: Prevent fd and entry leak

Make sure to free fd and the archive entry if an error is encountered
while adding source files to the archive.

Signed-off-by: Aaron Merey <amerey@redhat.com>
8 months agolibdw: Don't use ATOMIC_VAR_INIT
Mark Wielaard [Mon, 18 Nov 2024 18:50:17 +0000 (19:50 +0100)] 
libdw: Don't use ATOMIC_VAR_INIT

ATOMIC_VAR_INIT was introduced in C11, but not deemed necessary to
implement atomics. So deprecated in C17 and removed in C23. Normal
initialization syntax should be sufficient.

* libdw/libdw_alloc.c (next_id): Initialize to zero without
        using ATOMIC_VAR_INIT.

Signed-off-by: Mark Wielaard <mark@klomp.org>
8 months agoConsolidate and add files to clean target variables users/amerey/try-clean
Michael Pratt [Wed, 23 Oct 2024 06:33:18 +0000 (06:33 +0000)] 
Consolidate and add files to clean target variables

To increase the consistency of how automatic clean targets run,
define the variables together without +=, default to MOSTLYCLEANFILES
when there is no need for different levels or
add more clean levels to match other subdirectories,
add more files that are built, remove duplication, and cleanup.

Do the same for EXTRA_DIST where it is equally messy.

    * backends/Makefile.am: add more objects to clean, improve spacing.
    * debuginfod/Makefile.am: Likewise, and remove duplicates.
    * lib/Makefile.am: improve spacing.
    * libasm/Makefile.am: add more objects to clean, split similar to debuginfod.
    * libcpu/Makefile.am: use normal =, add more objects to clean.
    * libdw/Makefile.am: add more objects to clean, split similar to debuginfod.
    * libdwelf/Makefile.am: add more objects to clean, use lowest clean level.
    * libdwfl/Makefile.am: Likewise.
    * libebl/Makefile.am: add more objects to clean.
    * libelf/Makefile.am: add more objects to clean, split similar to debuginfod.
    * src/Makefile.am: consolidate including EXTRA_DIST, split clean levels,
      define with normal =, define with variables.
    * tests/Makefile.am: Likewise, but not including EXTRA_DIST.

Signed-off-by: Michael Pratt <mcpratt@pm.me>
8 months agolibelf: Only fetch shdr once in elf_compress[_gnu]
Mark Wielaard [Tue, 5 Nov 2024 22:31:14 +0000 (23:31 +0100)] 
libelf: Only fetch shdr once in elf_compress[_gnu]

Some compilers assume the second call to elf[32|64]_getshdr can fail
and produce error: potential null pointer dereference. Just store the
result of the first call and reuse (when not NULL).

       * libelf/elf_compress.c (elf_compress): Store getshdr result in
       a shdr union var.
       * libelf/elf_compress_gnu.c (): Likewise

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
8 months agostrip: Ignore --reloc-debug-sections-only for non-ET_REL files.
Aaron Merey [Tue, 5 Nov 2024 22:41:26 +0000 (17:41 -0500)] 
strip: Ignore --reloc-debug-sections-only for non-ET_REL files.

strip --reloc-debug-sections-only is expected to be a no-op for
non-ET_REL files.  This was not enforced in the code.  Sections
were copied over to a new output file and normally its contents
would be identical to the input file.

However the output file is not identical to a non-ET_REL input
file if the linker organized sections such that the indices of
SHF_ALLOC sections are not in a contigous group.

In this case strip will modify sections in order to keep all SHF_ALLOC
sections in a contiguous group.

Fix this by ignoring --reloc-debug-sections-only for non-ET_REL files.

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

Signed-off-by: Aaron Merey <amerey@redhat.com>
9 months agotests/.gitignore: Add newzdata
Aaron Merey [Tue, 29 Oct 2024 18:20:58 +0000 (14:20 -0400)] 
tests/.gitignore: Add newzdata

Signed-off-by: Aaron Merey <amerey@redhat.com>
9 months agoconfigure.ac: Fix ENABLE_IMA_VERIFICATION conditional
Aaron Merey [Tue, 29 Oct 2024 18:16:57 +0000 (14:16 -0400)] 
configure.ac: Fix ENABLE_IMA_VERIFICATION conditional

Fix test statement for ENABLE_IMA_VERIFICATION always evalutating to
false due to a missing 'x'.

Signed-off-by: Aaron Merey <amerey@redhat.com>
9 months agoconfig: fix globing error for zsh
RocketDev [Sat, 26 Oct 2024 14:18:09 +0000 (22:18 +0800)] 
config: fix globing error for zsh

Zsh treat unmatched glob as error while bash treat that as the original
string. Substitute globing with find to solve.

    * config/profile.sh.in: Fix globing error for zsh

Signed-off-by: RocketDev <marocketbd@gmail.com>
9 months agoconfig: Enable Debuginfod RPM sig checking and eu-stacktrace in spec
Mark Wielaard [Thu, 24 Oct 2024 09:34:11 +0000 (11:34 +0200)] 
config: Enable Debuginfod RPM sig checking and eu-stacktrace in spec

For testing that the eu-stacktrace and debuginfod ima verification
code builds correctly explicitly add --enable-stacktrace and
--enable-debuginfod-ima-verification to configure.

 * config/elfutils.spec.in (enable_stacktrace): New global,
         depends on arch.
 (BuildRequires): Add sysprof-capture-devel.
 (configure): Add --enable-stacktrace and
 --enable-debuginfod-ima-verification.
 (files): Add eu-stacktrace.

Signed-off-by: Mark Wielaard <mark@klomp.org>
9 months agostacktrace: Init elf_fd in sysprof_init_dwfl
Mark Wielaard [Thu, 24 Oct 2024 09:06:08 +0000 (11:06 +0200)] 
stacktrace: Init elf_fd in sysprof_init_dwfl

When building with LTO gcc believes elf_fd can be used uninitialized:

In function â€˜sysprof_init_dwfl’,
    inlined from â€˜sysprof_unwind_cb’ at stacktrace.c:1235:16:
stacktrace.c:1087:7: error: â€˜elf_fd’ may be used uninitialized [-Werror=maybe-uninitialized]
 1087 |       close (elf_fd);
      |       ^

This code won't be reached because if find_procfile doesn't initialize
elf_fd, it will return an error. But help the compiler by initializing
elf_fd to -1.

* src/stacktrace.c (sysprof_init_dwfl): Init elf_fd to -1.

Signed-off-by: Mark Wielaard <mark@klomp.org>
9 months agoconfigure: better error message for [lib]debuginfod missing dependencies
Mark Wielaard [Tue, 22 Oct 2024 16:19:09 +0000 (18:19 +0200)] 
configure: better error message for [lib]debuginfod missing dependencies

When dependencies for libdebuginfod, debuginfod or ima verification are
missing and these features are explicitly enabled the user might not
immediately know which of the dependicies are missing. Move the checks
around a little so checks for dependencies are done immediately before
the enable error message. And add the possible reason to the error to
make things more clear.

     * configure.ac: Move libcurl and json-c tests before libdebuginfod
     check, move libmicrohttpd, sqlite3 and libarchive tests before
     debuginfod check and move librpm, libcrypto and imaevm.h tests
     before ima verification check.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
9 months agolibelf: Add libeu objects to libelf.a static archive
Mark Wielaard [Tue, 22 Oct 2024 13:03:42 +0000 (15:03 +0200)] 
libelf: Add libeu objects to libelf.a static archive

libelf might use some symbols from libeu.a, specifically the eu-search
wrappers. But we don't ship libeu.a separately. So include the libeu
objects in the libelf.a archive to facilitate static linking.

* libelf/Makefile.am (libeu_objects): New variable.
(libelf_a_LIBADD): New, add libeu_objects.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
9 months agotests: run-debuginfod-seekable.sh depends on LZMA and DEBUGINFOD
Mark Wielaard [Tue, 22 Oct 2024 11:48:22 +0000 (13:48 +0200)] 
tests: run-debuginfod-seekable.sh depends on LZMA and DEBUGINFOD

The run-debuginfod-seekable.sh test would run (and fail) if lzma
support was enabled, but debuginfod wasn't build. Only run it when
both are available.

     * tests/Makefile.am (TESTS): Add run-debuginfod-seekable.sh if
     DEBUGINFOD and LZMA.

Signed-off-by: Mark Wielaard <mark@klomp.org>
9 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>
9 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>
9 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>
9 months agolibelf: Treat elf_memory image as writable
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>
9 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>
9 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>
9 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>
9 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>
9 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>
9 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>
9 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>
9 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>
9 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>
9 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>
9 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>
9 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>
9 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>
9 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>
9 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>
9 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>
9 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>
9 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>
9 months agolibcpu: Include config.h before standard headers in lexer source
Michael Pratt [Thu, 10 Oct 2024 10:27:02 +0000 (10:27 +0000)] 
libcpu: Include config.h before standard headers in lexer source

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Found by RASU JSC with SVACE.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Replace tsearch, tfind, etc with eu_t* equivalents.

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

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

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

Signed-off-by: Heather S. McIntyre <hsm2@rice.edu>
Signed-off-by: Aaron Merey <amerey@redhat.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>