]> git.ipfire.org Git - thirdparty/elfutils.git/log
thirdparty/elfutils.git
16 months agoPR 30991: srcfiles tarball feature
Housam Alamour [Tue, 6 Feb 2024 00:18:05 +0000 (19:18 -0500)] 
PR 30991: srcfiles tarball feature

* srcfiles.cxx: Introduce new --zip option that places all the
    source files associated with a specified dwarf/elf file
    into a zip file and sends it to stdout. Files may be
    fetched from debuginfod (if applicable) or locally as
    a backup.
    Added -b option to disable the backup of checking
    for files locally in -z mode.

* run-srcfiles-self.sh: Added test-case for the new zip
    feature that archives the source files of the srcfiles
    tool and checks archive integrity. An additional test
    ensures that if debuginfod is enabled, the files are
    fetched and archived properly while maintaing integrity.

* debuginfod-subr.sh: On very slow/remote storage, it can
    take O(minute) to finish indexing the entire elfutils
    build tree, so a wait_ready4 shell function is one
    way to let a longer debuginfod wait operation work.

* srcfiles.1, NEWS: Added documentation for the new zip feature.

* configure.ac: Simplify check for libarchive for srcfiles.cxx
    by integrating it into the same check for debuginfod.

* Makefile.am: build with local copy of debuginfod-client.

Example:
% ./src/srcfiles -z -e /bin/ls > output.zip

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

Signed-off-by: Housam Alamour <halamour@redhat.com>
16 months agolibelf: Treat elf_memory as if using ELF_C_READ_MMAP
Mark Wielaard [Thu, 1 Feb 2024 13:56:18 +0000 (14:56 +0100)] 
libelf: Treat elf_memory as if using ELF_C_READ_MMAP

An Elf handle created through elf_memory was treated as if opened with
ELF_C_READ. Which means libelf believed it had read the memory itself
and could simply write to it if it wanted (because it wasn't mmaped
directly on top of a file). This causes issues when that memory was
actually read-only. Work around this by pretending the memory was
actually read with ELF_C_READ_MMAP (so directly readable, but not
writable).

Add extra tests to elfgetzdata to check using elf_memory with
read-only memory works as expected.

  * libelf/elf_memory.c (elf_memory): Call
  __libelf_read_mmaped_file with ELF_C_READ_MMAP.
  * tests/elfgetzdata.c (main): Add new "mem" option.
  * tests/run-elfgetzdata.sh: Also run all tests with new
  "mem" option.

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

Reported-by: Derek Bruening <bruening@google.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
17 months agolibdwfl: Add some extra space to buffer to read kernel image header
Mark Wielaard [Sun, 21 Jan 2024 19:54:39 +0000 (20:54 +0100)] 
libdwfl: Add some extra space to buffer to read kernel image header

GCC 14 notices we play some tricks with the array into which we try
to read the kernel image header.

image-header.c: In function ‘__libdw_image_header’:
image-header.c:77:18: error: array subscript -496 is outside array bounds of ‘char[96]’ [-Werror=array-bounds=]
   77 |           header = header_buffer - H_START;
      |                  ^
image-header.c:67:12: note: at offset -496 into object ‘header_buffer’ of size 96
   67 |       char header_buffer[H_READ_SIZE];
      |            ^~~~~~~~~~~~~

GCC is correct. The new header pointer is before the actually buffer we
want to read from. Later in the code we "correct" the address again by
adding the "offset" off the elements we want to read. Such pointer
arithmetic is technically invalid. Make it valid by making the buffer
a little bigger, so all pointer arithmetic stays inside the header_buffer.
This does waste 496 bytes on the stack at the front of the buffer that
is never used.

* libdwfl/image-header.c (__libdw_image_header): Add H_START
to header_buffer size and return

Signed-off-by: Mark Wielaard <mark@klomp.org>
17 months agoPR31248: debuginfod_find_*: lseek to the front on returned fds
Frank Ch. Eigler [Tue, 16 Jan 2024 02:21:24 +0000 (21:21 -0500)] 
PR31248: debuginfod_find_*: lseek to the front on returned fds

Previous code could return a fd that had its file-offset left at the
place where libcurl last used it, namely at the end of the freshly
downloaded file.  Not good if a client just wants to read it right
away!  We now ensure (and document) that the fd is pointed to the
beginning of the file.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
18 months agolibdw: Use INTUSE with dwarf_get_units
Aaron Merey [Wed, 6 Dec 2023 22:23:48 +0000 (17:23 -0500)] 
libdw: Use INTUSE with dwarf_get_units

Add INTDECL for dwarf_get_units and call dwarf_get_units with INTUSE.

Signed-off-by: Aaron Merey <amerey@redhat.com>
18 months agotests: fix build against upcoming `gcc-14` (`-Werror=calloc-transposed-args`)
Sergei Trofimovich [Thu, 21 Dec 2023 09:23:30 +0000 (09:23 +0000)] 
tests: fix build against upcoming `gcc-14` (`-Werror=calloc-transposed-args`)

`gcc-14` added a new `-Wcalloc-transposed-args` warning recently. It
detected minor infelicity in `calloc()` API usage in `elfutils`:

    elfstrmerge.c: In function 'main':
    elfstrmerge.c:450:32: error:
      'calloc' sizes specified with 'sizeof' in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
      450 |   newscnbufs = calloc (sizeof (void *), newshnums);
          |                                ^~~~
    elfstrmerge.c:450:32: note: earlier argument should specify number of elements, later size of each element

Signed-off-by: Sergei Trofimovich <slyich@gmail.com>
18 months agoAdd helper function for basename
Khem Raj [Sun, 10 Dec 2023 20:20:33 +0000 (12:20 -0800)] 
Add helper function for basename

musl does not provide GNU version of basename and lately have removed
the definiton from string.h [1] which exposes this problem. It can be
made to work by providing a local implementation of basename which
implements the GNU basename behavior, this makes it work across C
libraries which have POSIX implementation only.

[1] https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7

    * lib/system.h (xbasename): New static inline functions.
    Poison basename.
    * libdw/dwarf_getsrc_file.c (dwarf_getsrc_file): Use xbasename.
    * libdwfl/core-file.c (dwfl_core_file_report): Likewise.
    * libdwfl/dwfl_module_getsrc_file.c (dwfl_module_getsrc_file):
    Likewise.
    * libdwfl/dwfl_segment_report_module.c (dwfl_segment_report_module):
    Likewise.
    * libdwfl/find-debuginfo.c (find_debuginfo_in_path): Likewise.
    * libdwfl/link_map.c (report_r_debug): Likewise.
    * libdwfl/linux-kernel-modules.c (try_kernel_name): Likewise.
    * src/addr2line.c (print_dwarf_function): Likewise.
    (print_src): Likewise.
    * src/ar.c (do_oper_insert): Likewise.
    And cast away const in entry.key assignment.
    * src/nm.c (show_symbols): Use xbasename.
    * src/stack.c (module_callback): Likewise.
    * src/strip.c (handle_elf): Likewise.
    * tests/show-die-info.c: Include system.h.
    (dwarf_tag_string): Use xbasename.
    * tests/varlocs.c: Likewise.
    * debuginfod/debuginfod.cxx: Move include system.h to the end.
    (register_file_name): Rename basename to filename.

Signed-off-by: Khem Raj <raj.khem@gmail.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
18 months agotests: Don't redirect output to /dev/null in run-native-test.sh
Mark Wielaard [Tue, 12 Dec 2023 09:43:49 +0000 (10:43 +0100)] 
tests: Don't redirect output to /dev/null in run-native-test.sh

By redirecting all output to /dev/null in run-native-test.sh the
run-native-test.sh.log file will be empty on failures. This makes
it hard to figure out what went wrong.

* tests/run-native-test.sh: Remove /dev/null redirects.

Signed-off-by: Mark Wielaard <mark@klomp.org>
19 months agolibelf: check decompressed ZSTD size
Aleksei Vetrov [Thu, 23 Nov 2023 15:31:47 +0000 (15:31 +0000)] 
libelf: check decompressed ZSTD size

Decompression functions like __libelf_decompress_zlib check that
decompressed data has the same size as it was declared in the header
(size_out argument). The same check is now added to
__libelf_decompress_zstd to make sure that the whole allocated buffer is
initialized.

    * libelf/elf_compress.c (__libelf_decompress_zstd): Use return value
      of ZSTD_decompress to check that decompressed data size is the
      same as size_out of the buffer that was allocated.

Signed-off-by: Aleksei Vetrov <vvvvvv@google.com>
19 months agolibdwfl: Correctly handle corefile non-contiguous segments
Aaron Merey [Tue, 21 Nov 2023 13:56:44 +0000 (08:56 -0500)] 
libdwfl: Correctly handle corefile non-contiguous segments

It is possible for segments of different shared libaries to be interleaved
in memory such that the segments of one library are located in between
non-contiguous segments of another library.

For example, this can be seen with firefox on RHEL 7.9 where multiple
shared libraries could be mapped in between ld-2.17.so segments:

      [...]
      7f0972082000-7f09720a4000 00000000 139264      /usr/lib64/ld-2.17.so
      7f09720a4000-7f09720a5000 00000000 4096        /memfd:mozilla-ipc (deleted)
      7f09720a5000-7f09720a7000 00000000 8192        /memfd:mozilla-ipc (deleted)
      7f09720a7000-7f09720a9000 00000000 8192        /memfd:mozilla-ipc (deleted)
      7f0972134000-7f0972136000 00000000 8192        /usr/lib64/firefox/libmozwayland.so
      7f0972136000-7f0972137000 00002000 4096        /usr/lib64/firefox/libmozwayland.so
      7f0972137000-7f0972138000 00003000 4096        /usr/lib64/firefox/libmozwayland.so
      7f0972138000-7f0972139000 00003000 4096        /usr/lib64/firefox/libmozwayland.so
      7f097213a000-7f0972147000 00000000 53248       /usr/lib64/firefox/libmozsqlite3.so
      7f0972147000-7f097221e000 0000d000 880640      /usr/lib64/firefox/libmozsqlite3.so
      7f097221e000-7f0972248000 000e4000 172032      /usr/lib64/firefox/libmozsqlite3.so
      7f0972248000-7f0972249000 0010e000 4096        /usr/lib64/firefox/libmozsqlite3.so
      7f0972249000-7f097224c000 0010e000 12288       /usr/lib64/firefox/libmozsqlite3.so
      7f097224c000-7f0972250000 00111000 16384       /usr/lib64/firefox/libmozsqlite3.so
      7f0972250000-7f0972253000 00000000 12288       /usr/lib64/firefox/liblgpllibs.so
      [...]
      7f09722a3000-7f09722a4000 00021000 4096        /usr/lib64/ld-2.17.so
      7f09722a4000-7f09722a5000 00022000 4096        /usr/lib64/ld-2.17.so

dwfl_segment_report_module did not account for the possibility of
interleaving non-contiguous segments, resulting in premature closure
of modules as well as failing to report modules.

Fix this by removing segment skipping in dwfl_segment_report_module.
When dwfl_segment_report_module reported a module, it would return
the index of the segment immediately following the end address of the
current module.  Since there's a chance that other modules might fall
within this address range, dwfl_segment_report_module instead returns
the index of the next segment.

This patch also fixes premature module closure that can occur in
dwfl_segment_report_module when interleaving non-contiguous segments
are found.  Previously modules with start and end addresses that overlap
with the current segment would have their build-ids compared with the
current segment's build-id.  If there was a mismatch, that module would
be closed.  Avoid closing modules in this case when mismatching build-ids
correspond to distinct modules.

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

Signed-off-by: Aaron Merey <amerey@redhat.com>
19 months agotests: Add test for duplicate entries in archive
Aleksei Vetrov [Mon, 20 Nov 2023 17:44:48 +0000 (17:44 +0000)] 
tests: Add test for duplicate entries in archive

Test dwfl-report-offline-memory against an archive that contains
non-relocatable ELFs with the same name and contents.

    * tests/test-ar-duplicates.a.bz2: New test file.
    * tests/run-dwfl-report-offline-memory.sh: Test new
      test-ar-duplicates.a.bz2.
    * tests/Makefile.am (EXTRA_DIST): Add test-ar-duplicates.a.bz2.

Signed-off-by: Aleksei Vetrov <vvvvvv@google.com>
19 months agolibdwfl: handle duplicate ELFs when reporting archives
Aleksei Vetrov [Mon, 20 Nov 2023 17:44:47 +0000 (17:44 +0000)] 
libdwfl: handle duplicate ELFs when reporting archives

When archive is processed in process_archive (libdwfl/offline.c), it
creates an Elf object for each archive member. Then in
process_archive_member it calls process_file to create a Dwfl_Module
through __libdwfl_report_elf.

The ownership of the Elf object is expected to be:

* either transfered to the Dwfl_Module, if __libdwfl_report_elf returns
  not NULL;

* or handled at the end of process_archive_member by calling elf_end.

Moreover, Elf object is expected to be alive, if __libdwfl_report_elf
returns not NULL, because at the end of process_archive_member it
advances to the next member through the elf_next call.

The problem happens when __libdwfl_report_elf encounters Elf with the
same name and content as it seen before. In that case dwfl_report_module
will reuse existing Dwfl_Module object. This leads to a codepath that
calls elf_end on the Elf object, while returning not NULL, breaking the
elf_next call to the next member.

The fix is to destroy m->main.elf instead and put the new Elf object in
the already existing Dwfl_Module.

    * libdwfl/dwfl_report_elf.c (__libdwfl_report_elf): Replace Elf in
      the Dwfl_Module in case of duplicate modules to prolong its
      lifetime for subsequent processing.

Signed-off-by: Aleksei Vetrov <vvvvvv@google.com>
19 months agoreadelf: Don't print average number of tests when no tests are done
Mark Wielaard [Wed, 15 Nov 2023 16:33:42 +0000 (17:33 +0100)] 
readelf: Don't print average number of tests when no tests are done

If the symbol hash table only contains lenght zero chains, no lookup
tests need to be done and eu-readelf -I would print out bogus numbers
for the number of tests that were successful/unsuccessful.

e.g. for an "empty" program like
  int main() {}
eu-readelf -I would print:

Histogram for bucket list length in section [ 5] '.gnu.hash' (total of 1 bucket):
 Addr: 0x00000000004003c0  Offset: 0x0003c0  Link to section: [ 6] '.dynsym'
 Symbol Bias: 1
 Bitmask Size: 8 bytes  0% bits set  2nd hash shift: 0
 Length  Number  % of total  Coverage
      0       1      100.0%
 Average number of tests:   successful lookup: -nan
  unsuccessful lookup: 0.000000

Only print out the Average number of tests when there were actual
tests to do.

Signed-off-by: Mark Wielaard <mark@klomp.org>
19 months agotests: Restructure run-debuginfod-response-headers.sh
Mark Wielaard [Sun, 19 Nov 2023 13:14:11 +0000 (14:14 +0100)] 
tests: Restructure run-debuginfod-response-headers.sh

run-debuginfod-response-headers.sh does occassionally fail because
it might scan an rpm more than once. Try to fix this by making sure
all files that debuginfod is supposed to scan are ready before the
server starts. And to explicitly wait till the first scan is ready
and done before testing 'scanned_files_total{source=".rpm archive"}'
instead of sending an kill -USR1.

Signed-off-by: Mark Wielaard <mark@klomp.org>
19 months agolibdw: check offset dwarf_formstring in all cases
Aleksei Vetrov [Thu, 16 Nov 2023 21:29:22 +0000 (21:29 +0000)] 
libdw: check offset dwarf_formstring in all cases

This check was initially added to test if offset overflows the safe
prefix where any string will be null-terminated. However the check
was placed in a wrong place and didn't cover all `attrp->form` cases.

    * libdw/dwarf_formstring.c (dwarf_formstring): Move offset check
      right before returning the result.

Signed-off-by: Aleksei Vetrov <vvvvvv@google.com>
19 months agodoc/debuginfod.8: clarify source file handling
Frank Ch. Eigler [Tue, 14 Nov 2023 19:09:40 +0000 (14:09 -0500)] 
doc/debuginfod.8: clarify source file handling

Added text about the archive common-prefix heuristic, mentioned
the new eu-srcfiles tool, and gave some extra debian advice.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
19 months agoMinor: include <stdint.h> for uintptr_t
Paul Pluzhnikov [Tue, 14 Nov 2023 22:20:38 +0000 (22:20 +0000)] 
Minor: include <stdint.h> for uintptr_t

We have a clang-tidy complaining that uintptr_t is not provided by any
directly included header (it's only provided by a transitively included one).

* libelf/elf_begin.c: Include <stdint.h>

Signed-off-by: Paul Pluzhnikov <ppluzhnikov@google.com>
19 months agolibelf: Fix elf_begin.c build on 32bit arches.
Mark Wielaard [Tue, 14 Nov 2023 20:34:50 +0000 (21:34 +0100)] 
libelf: Fix elf_begin.c build on 32bit arches.

On 32bit architectures gcc produces an error:

elf_begin.c: In function ‘file_read_elf’:
elf_begin.c:495:30: error: cast to pointer from integer of different
size [-Werror=int-to-pointer-cast]
      elf->state.elf64.shdr = (Elf64_Shdr *) (ehdr + e_shoff);
                              ^

This is because we are adding an uintptr to an Elf64_Off which
promotes the result to a 64bit value. Fix this by casting the
e_shoff to an ptrdiff_t. This is fine since the mmap of the file
would have failed if it didn't fit in the 32bit address space
and we check that e_shoff fits inside the image.

* libelf/elf_begin.c (file_read_elf): Cast e_shoff to ptrdiff_t
before adding to ehdr.

Suggested-by: Paul Pluzhnikov <ppluzhnikov@google.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
19 months agoFix computations with (potentially) NULL pointer
Paul Pluzhnikov [Mon, 13 Nov 2023 22:40:46 +0000 (22:40 +0000)] 
Fix computations with (potentially) NULL pointer

When map_address is NULL, computing map_address+offset is technically
undefined behavior, and triggers Clang/LLVM warning when using
-fsanitize=pointer-overflow.

Fix this by using uintptr_t to perform computations.

Signed-off-by: Shahriar "Nafi" Rouf <nafi@google.com>
Signed-off-by: Paul Pluzhnikov <ppluzhnikov@google.com>
19 months agolibelf: Fix possible memory leak in elf_getdata_rawchunk
Mark Wielaard [Wed, 8 Nov 2023 12:50:01 +0000 (13:50 +0100)] 
libelf: Fix possible memory leak in elf_getdata_rawchunk

If the rawchunk is not properly aligned we'll create a new buffer
that is correctly aligned and put the data in that new buffer with
memcpy or the conversion function. In such cases the rawchunk leaks
because the new buffer is put into the Elf_Data_Chunk.

* libelf/elf_getdata_rawchunk.c (elf_getdata_rawchunk):
Call free on the rawchunk if new buffer was allocated.

Signed-off-by: Mark Wielaard <mark@klomp.org>
19 months agorpmbuild: fix Makefile rules
Mark Wielaard [Mon, 13 Nov 2023 23:47:58 +0000 (00:47 +0100)] 
rpmbuild: fix Makefile rules

* Makefile.am (rpmbuild): Use mkdir -p. Use $(shell pwd).

19 months agobackends: Fix arm_machine_flag_name version string.
Mark Wielaard [Mon, 13 Nov 2023 21:38:10 +0000 (22:38 +0100)] 
backends: Fix arm_machine_flag_name version string.

arm_machine_flag_name checks the version byte and if not zero returns
a version string. There are only 5 versions defined. So check the
version byte is not larger.

* backends/arm_machineflagname.c (arm_machine_flag_name):
Check version <= 0, otherwise return NULL.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
19 months agoelfutils.spec: Add eu-srcfiles and add new make rpmbuild target
Mark Wielaard [Fri, 3 Nov 2023 21:25:15 +0000 (22:25 +0100)] 
elfutils.spec: Add eu-srcfiles and add new make rpmbuild target

The elfutils.spec was missing the new eu-srcfiles program. Add a new
rpmbuild target to test a whole rpm build to catch such issues early.

 * config/elfutils.spec.in: Add eu-srcfiles to files.
 * Makefile.am (rpmbuild): New target.

Signed-off-by: Mark Wielaard <mark@klomp.org>
19 months agoPrepare for 0.190 elfutils-0.190
Mark Wielaard [Fri, 3 Nov 2023 17:02:44 +0000 (18:02 +0100)] 
Prepare for 0.190

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
19 months agoThe default branch is now 'main'
Mark Wielaard [Fri, 3 Nov 2023 14:05:57 +0000 (15:05 +0100)] 
The default branch is now 'main'

Updated the HEAD symbolic reference.
Updated gitsigure checkref.
Updated hooks/post-receive irkerhook
Updated buildbot elfutils_[snapshots_]scheduler and elfutils_gitpoller

If you still have a checkout that refers to master and you do a git
pull you might get:

  Your configuration specifies to merge with the ref
  'refs/heads/master' from the remote, but no such ref was
  fetched.

Make sure to rename your branch to main and set the new upstream:

$ git branch -m master main
$ git branch --unset-upstream
$ git branch -u origin/main

Signed-off-by: Mark Wielaard <mark@klomp.org>
19 months agolibelf/elf_newscn.c: fix build failure against gcc-14 (-Walloc-size)
Sergei Trofimovich [Thu, 2 Nov 2023 19:58:46 +0000 (19:58 +0000)] 
libelf/elf_newscn.c: fix build failure against gcc-14 (-Walloc-size)

`gcc-14` adde a new -Walloc-size warning that makes sure that size of an
individual element matches size of a pointed type:

    https://gcc.gnu.org/PR71219

`elfutils` triggers is on `calloc()` call where member size is sued as
`1`.

    elf_newscn.c: In function `elf_newscn`:
    elf_newscn.c:97:12: error: allocation of insufficient size «1» for type «Elf_ScnList» with size «16» [-Werror=alloc-size]
       97 |       newp = calloc (sizeof (Elf_ScnList)
          |            ^

The change swaps arguments to pass larger value as a member size.

Signed-off-by: Sergei Trofimovich <slyich@gmail.com>
19 months agotests: Optionally dump all units in dwarf-getmacros
Omar Sandoval [Wed, 27 Sep 2023 18:21:01 +0000 (11:21 -0700)] 
tests: Optionally dump all units in dwarf-getmacros

If instead of a CU offset an empty string is given as the second
argument, dump all units.

Signed-off-by: Omar Sandoval <osandov@fb.com>
19 months agotests: Handle DW_MACRO_{define,undef}_{strx,sup} in dwarf-getmacros
Omar Sandoval [Wed, 27 Sep 2023 18:21:00 +0000 (11:21 -0700)] 
tests: Handle DW_MACRO_{define,undef}_{strx,sup} in dwarf-getmacros

Signed-off-by: Omar Sandoval <osandov@fb.com>
19 months agoreadelf: Support .gdb_index version 9
Aaron Merey [Tue, 31 Oct 2023 20:00:27 +0000 (16:00 -0400)] 
readelf: Support .gdb_index version 9

Version 9 adds a "shortcut table" to the index.  The shortcut table contains
the name and language of the main function, if it exists.

A testcase added in this patch uses an executable written with Fortran.
This is because gdb does not currently populate the shortcut table of
C/C++ programs (see sourceware PR30996).

Signed-off-by: Aaron Merey <amerey@redhat.com>
19 months agolibdw, libdwfl: Save original path of ELF file
Omar Sandoval [Wed, 27 Sep 2023 18:20:58 +0000 (11:20 -0700)] 
libdw, libdwfl: Save original path of ELF file

libdw and libdwfl currently save the path of the directory containing
the ELF file to use when searching for alt and dwo files.  To search for
dwp files, we need the file name too.  Add an elfpath field to Dwarf,
and set the debugdir field from it.  Also update libdwfl to set elfpath
and debugdir.

Signed-off-by: Omar Sandoval <osandov@fb.com>
19 months agodebuginfod-client.c: Don't print empty line in header_callback
Aaron Merey [Wed, 1 Nov 2023 21:40:12 +0000 (17:40 -0400)] 
debuginfod-client.c: Don't print empty line in header_callback

libcurl passes an empty line to header_callback indicating the end
of the response's HTTP headers.

Currently this empty line is printed to the debuginfod_client's
verbose_fd with a "header" prefix:

    $ echo $DEBUGINFOD_URLS
    https://debuginfod.fedoraproject.org/
    $ debuginfod-find -vv debuginfo e2bbf033b548021c37866429f12a99bd33bd6e8d
    [...]
    header x-fedora-requestid: ZULLx0PPA8nmj8c8Hw-RtAACgAE
    header server: Apache
    header
    [...]

Prevent this unnecessary line of output by only printing non-empty
lines in header_callback.

Signed-off-by: Aaron Merey <amerey@redhat.com>
19 months agodwfl_offline_section_address: replace asserts with early return
Aaron Merey [Wed, 1 Nov 2023 20:15:16 +0000 (16:15 -0400)] 
dwfl_offline_section_address: replace asserts with early return

dwfl_offline_section_address asserts that the current module is ET_REL.

A possibly corrupt .gnu_debuglink can cause an abort by calling
dwfl_offline_section_address on an ET_DYN module.

Prevent this abort and similar ones by replacing
dwfl_offline_section_address initial asserts with an early return.

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

Signed-off-by: Aaron Merey <amerey@redhat.com>
20 months agolibdw: Recognize .debug_[ct]u_index sections in dwarf_elf_begin
Omar Sandoval [Wed, 27 Sep 2023 18:20:56 +0000 (11:20 -0700)] 
libdw: Recognize .debug_[ct]u_index sections in dwarf_elf_begin

DWARF package (.dwp) files have a .debug_cu_index section and,
optionally, a .debug_tu_index section.  Add them to the list of DWARF
sections.

Unfortunately, it's not that simple: the other debug sections in a dwp
file have names ending with .dwo, which confuses the checks introduced
by commit 5b21e70216b8 ("libdw: dwarf_elf_begin should use either plain,
dwo or lto DWARF sections.").  So, we also have to special case
.debug_cu_index and .debug_tu_index in scn_dwarf_type and check_section
to treat them as TYPE_DWO sections.

Signed-off-by: Omar Sandoval <osandov@fb.com>
20 months agolibdw: ignore really large discriminator
Mark Wielaard [Thu, 26 Oct 2023 14:49:08 +0000 (16:49 +0200)] 
libdw: ignore really large discriminator

llvm can create really large discriminator values. We used to flag those
as invalid when the value wouldn't fit in 24 bits. Just truncate the value.

* libdw/dwarf_getsrclines.c (add_new_line): Define SETX.
Use SETX to set discriminator.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
20 months agoCONTRIBUTING: Update ChangeLog policy, mention patchwork and try bots
Mark Wielaard [Thu, 19 Oct 2023 15:43:01 +0000 (17:43 +0200)] 
CONTRIBUTING: Update ChangeLog policy, mention patchwork and try bots

Signed-off-by: Mark Wielaard <mark@klomp.org>
20 months agoPR 30000: debuginfod-find should have a source-list verb
Housam Alamour [Thu, 7 Sep 2023 18:29:19 +0000 (14:29 -0400)] 
PR 30000: debuginfod-find should have a source-list verb

* seclines.cxx: Introduce new tool  that compiles a list of source
files associated with a specified dwarf/elf file. This
compilation relies on searching the dwarf debug information,
which can be automatically retrieved via debuginfod using
libdwfl functions when required. The target file can
encompass various types, such as an executable, a coredump,
a running process, or the currently executing kernel. The
source file names are rendered as unique entries and then
displayed on the standard output.

*  run-srcfiles-self.sh: New test-case for tool.

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

Signed-off-by: Housam Alamour <halamour@redhat.com>
20 months agoCONTRIBUTING: Switch from real name policy to know identity policy
Mark Wielaard [Thu, 19 Oct 2023 15:47:28 +0000 (17:47 +0200)] 
CONTRIBUTING: Switch from real name policy to know identity policy

Signed-off-by: Mark Wielaard <mark@klomp.org>
20 months agolibelf: Make elf32_getchdr and elf64_getchdr thread-safe
Heather McIntyre [Tue, 10 Oct 2023 11:20:59 +0000 (13:20 +0200)] 
libelf: Make elf32_getchdr and elf64_getchdr thread-safe

* libelf/elf32_getchdr.c: Move getchdr function to
elf32_getchdr.h.
* libelf/elf32_getchdr.h: New file.
Add macro to create getchdr_wrlock.
* libelf/elf32_updatenull.c: Change call from getchdr to
getchdr_wrlock.
* libelf/elf_getdata.c: Add elf_getdata_wrlock.
* libelf/libelfP.h: Add internal function declarations.
* libelf/Makefile.am (noinst_HEADERS): Add elf32_getchdr.h.

Signed-off-by: Heather S. McIntyre <hsm2@rice.edu>
Signed-off-by: Mark Wielaard <mark@klomp.org>
20 months agolibelf: Fix elf_end deadlock
Heather McIntyre [Tue, 10 Oct 2023 11:16:03 +0000 (13:16 +0200)] 
libelf: Fix elf_end deadlock

* libelf/elf_end.c (elf_end): Add rwlock_unlock before
early return.

Signed-off-by: Heather S. McIntyre <hsm2@rice.edu>
Signed-off-by: Mark Wielaard <mark@klomp.org>
20 months agolibelf: Make elf_version thread-safe
Heather McIntyre [Tue, 10 Oct 2023 10:39:53 +0000 (12:39 +0200)] 
libelf: Make elf_version thread-safe

* elf_version.c (version_once): Define once.
(initialize_version): New static function.
(elf_version): Use initialize_version version_once.

Signed-off-by: Heather S. McIntyre <hsm2@rice.edu>
Signed-off-by: Mark Wielaard <mark@klomp.org>
20 months agolib: Add new once_define and once macros to eu-config.h
Heather McIntyre [Mon, 9 Oct 2023 21:09:28 +0000 (23:09 +0200)] 
lib: Add new once_define and once macros to eu-config.h

* lib/eu-config.h New macros.
[USE_LOCKS] (ONCE_CALL): (once_define, once)

Signed-off-by: Heather S. McIntyre <hsm2@rice.edu>
Signed-off-by: Mark Wielaard <mark@klomp.org>
20 months agolibelf: Sync elf.h from glibc
Ying Huang [Fri, 13 Oct 2023 09:01:09 +0000 (17:01 +0800)] 
libelf: Sync elf.h from glibc

MIPS add new ELF file header flags, new relocations and new section
type SHT_MIPS_ABIFLAGS.

20 months agoPR30962: debuginfod: full paths for X-DEBUGINFOD-FILE/ARCHIVE response headers
Frank Ch. Eigler [Tue, 10 Oct 2023 20:21:00 +0000 (16:21 -0400)] 
PR30962: debuginfod: full paths for X-DEBUGINFOD-FILE/ARCHIVE response headers

Previous code was inconsistent in offering basename versus full
pathname for these headers.  The documentation was not explicit on
this issue.  We now simplify by always passing full names back, and
document this in the debuginfod.8 man page, along with pointers to
how to use proxy front-end servers to strip them if needed.

Signed-Off-By: Frank Ch. Eigler <fche@redhat.com>
20 months agolibdw: Skip zero entries in aranges
Mark Wielaard [Fri, 6 Oct 2023 11:56:55 +0000 (13:56 +0200)] 
libdw: Skip zero entries in aranges

An address/length entry of two zeros is supposed to mark the end of a
table. But in some cases a producer might leave zero entries in the
table (for example when using gcc -ffunction-sections -gc-sections).

Since we know the lenght of the table we can just skip such entries
and continue to the end.

    * libdw/dwarf_getaranges.c (dwarf_getaranges): Calculate endp.
    When seeing two zero values, check we are at endp.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
20 months agostrip: Clean up a bit more after errors
Mark Wielaard [Fri, 6 Oct 2023 14:25:56 +0000 (16:25 +0200)] 
strip: Clean up a bit more after errors

In some cases (late) errors would exit early without cleanup.  Set
result to 1 (failure) in those cases and fallthrough.  That way we
cleanup and might provide more hints to the user about what was wrong
with the file.

     * src/strip.c (handle_elf): Set result to 1 and fallthrough
     instead of return 1.

Signed-off-by: Mark Wielaard <mark@klomp.org>
20 months agolibdw: Handle split DWARF in dwarf_macro_getsrcfiles
Omar Sandoval [Wed, 27 Sep 2023 18:20:55 +0000 (11:20 -0700)] 
libdw: Handle split DWARF in dwarf_macro_getsrcfiles

Macro information references file names from the line number information
table, which is tricky in split DWARF for a couple of reasons.

First, the line number information for a macro unit comes from the
.debug_line.dwo section in the split file, not the .debug_line section
in the skeleton file.  This was not specified in the GNU DebugFission
design document [1] or the DWARF 5 standard, but it is how GCC and Clang
behave in practice and was clarified in DWARF standard issue
200602.1 [2] for the upcoming DWARF 6 standard.

dwarf_macro_getsrcfiles uses the line number information from whichever
Dwarf handle it was passed.  This is error-prone, since the most natural
thing to do is to pass the skeleton Dwarf handle.  Fix this by storing
the appropriate Dwarf handle in Dwarf_Macro_Op_Table and using that one.

Second, for .debug_macinfo.dwo in GNU DebugFission (generated by gcc
-gdwarf-4 -gstrict-dwarf -gsplit-dwarf), the offset into .debug_line.dwo
is implicitly 0.  Again, this isn't in any specification, but it's how
GCC behaves in practice (Clang never generates macro information for
DWARF 4 split DWARF).  Make get_macinfo_table default to 0 for split
DWARF when it can't find DW_AT_stmt_list.

1: https://gcc.gnu.org/wiki/DebugFission
2: https://dwarfstd.org/issues/200602.1.html

Signed-off-by: Omar Sandoval <osandov@fb.com>
20 months agolibdw: Fix dwarf_macro_getsrcfiles for DWARF 5
Omar Sandoval [Wed, 27 Sep 2023 18:20:54 +0000 (11:20 -0700)] 
libdw: Fix dwarf_macro_getsrcfiles for DWARF 5

Dwarf_Macro_Op_Table::is_64bit conflates the address size and the offset
size: for .debug_macinfo, it is initialized based on the compilation
unit's address size, but for .debug_macro, it is initialized based on
the macro unit's offset size.  is_64bit is used to determine the address
size to pass to __libdw_getsrclines.  For a 64-bit architecture using
DWARF 5 with 32-bit offsets (the common case), this fails because
read_srclines checks that the given address size matches the address
size from the line number program header.

Fix it by splitting is_64bit into separate address_size and offset_size
members.

Fixes: fb90bf3f84b5 ("Support .debug_macro")
Signed-off-by: Omar Sandoval <osandov@fb.com>
20 months agolibdw: Handle other string forms in dwarf_macro_param2
Omar Sandoval [Wed, 27 Sep 2023 18:20:53 +0000 (11:20 -0700)] 
libdw: Handle other string forms in dwarf_macro_param2

dwarf_getmacros handles the additional macro string forms added by DWARF
5, but dwarf_macro_param2 doesn't.  Update it with the list of all
string forms allowed in .debug_macro.  In particular, GCC and Clang
generate DW_MACRO_define_strx and DW_MACRO_undef_strx, which
dwarf_macro_param2 couldn't handle.

Fixes: cdf865b890c2 ("readelf, libdw: Handle DWARF5 .debug_macro.")
Signed-off-by: Omar Sandoval <osandov@fb.com>
20 months agolibdw: Handle DW_AT_ranges in split DWARF 5 skeleton in dwarf_ranges
Omar Sandoval [Wed, 27 Sep 2023 18:20:52 +0000 (11:20 -0700)] 
libdw: Handle DW_AT_ranges in split DWARF 5 skeleton in dwarf_ranges

When commit 879f3a4f99df ("libdw: Handle .debug_rnglists in
dwarf_ranges.") added support for split DWARF 5 in 2018, GCC put all
range lists for split DWARF in the .debug_rnglists section of the
skeleton file (similarly to GNU DebugFission, which puts all range lists
in .debug_ranges in the skeleton file).

In 2021, after a discussion on the dwarf-discuss mailing list [1], GCC
changed this to match Clang's behavior.  Now, ranges are in
.debug_rnglists.dwo in the split file, _except_ for one: the skeleton
unit DIE has a DW_AT_ranges attribute, and its ranges are in
.debug_rnglists in the skeleton file.  See GCC commit 4b33c5aaab9e
("dwarf2out: Fix up ranges for -gdwarf-5 -gsplit-dwarf [PR99490]") and
the Issue 210310.1 clarifying the DWARF standard [2].

Unfortunately, this confuses dwarf_ranges, which always uses
.debug_rnglists.dwo if it exists.  Fix it by special casing the unit
DIE: its range lists should be in .debug_rnglists if that exists, and
.debug_rnglists.dwo otherwise.

1: https://lists.dwarfstd.org/pipermail/dwarf-discuss/2021-March/002009.html
2: https://dwarfstd.org/issues/210310.1.html

Signed-off-by: Omar Sandoval <osandov@fb.com>
20 months agolibdw: Handle split DWARF in dwarf_entrypc
Omar Sandoval [Wed, 27 Sep 2023 18:20:51 +0000 (11:20 -0700)] 
libdw: Handle split DWARF in dwarf_entrypc

If a DIE has no DW_AT_entry_pc attribute, dwarf_entrypc looks for
DW_AT_low_pc in that DIE.  But for a split compilation unit DIE,
DW_AT_low_pc is in the corresponding skeleton DIE, so this fails.
dwarf_lowpc already handles this fallback, so use it instead.

Signed-off-by: Omar Sandoval <osandov@fb.com>
20 months agolibdw: Make try_split_file static
Omar Sandoval [Wed, 27 Sep 2023 18:20:50 +0000 (11:20 -0700)] 
libdw: Make try_split_file static

It's only used in libdw_find_split_unit.c.

Signed-off-by: Omar Sandoval <osandov@fb.com>
21 months agoPR30879: intermittent debuginfod crash with unhandled exception
Frank Ch. Eigler [Fri, 22 Sep 2023 19:30:51 +0000 (15:30 -0400)] 
PR30879: intermittent debuginfod crash with unhandled exception

Code inspection identified two places where sqlite_ps objects were
being created/used outside try/catch protection.  This patch wraps or
replaces them.

* configure.ac: Look for glibc backtrace headers.
* debuginfod.cxx (scan): New function wrapped by a try/catch loop.
  (sqlite_checkpoint_pb): Use non-exception-producing sqlite functions.
  (main, my_terminate_handler): New terminate() handler.

21 months agolibelf: tdelete dummy key if anything goes wrong setting up rawchunk
Mark Wielaard [Thu, 7 Sep 2023 14:14:43 +0000 (16:14 +0200)] 
libelf: tdelete dummy key if anything goes wrong setting up rawchunk

elf_getdata_rawchunk uses a binary search tree cache. If a rawchunk is
not yet in the cache we setup a new entry. But if anything went wrong
setting up the new rawchunk we would leave a NULL key in the
cache. This could blow up the next search. Fix this by removing the
(dummy) key from the cache on any failure.

* libelf/elf_getdata_rawchunk.c (elf_getdata_rawchunk): Don't
assign NULL to *found. Call tdelete if anything goes wrong.

Signed-off-by: Mark Wielaard <mark@klomp.org>
21 months agolibelf: fix typos in comment
COCOCO X [Sat, 9 Sep 2023 16:07:15 +0000 (00:07 +0800)] 
libelf: fix typos in comment

bug -> but

Signed-off-by: Yanglin Xun <xunyanglins@gmail.com>
21 months agotests: Fix system_elf_gelf_test build without system libelf.h
Mark Wielaard [Sun, 3 Sep 2023 16:25:56 +0000 (18:25 +0200)] 
tests: Fix system_elf_gelf_test build without system libelf.h

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

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

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

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

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

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

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

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

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

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

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

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

Adds new LoongArch relocations.

* elf.h: Update from glibc.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Policy drafted in April 2023.

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

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

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

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

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

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

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

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

Adds new RISC-V relocations.

* elf.h: Update from glibc.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

See also discussion here:

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

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

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

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

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

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

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

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

This patch implements the set_initial_registers_tid hook for LoongArch.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Add handling of _GLOBAL_OFFSET_TABLE_.

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

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

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

Add new relocation type handling.

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

Adds R_LARCH_*.

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

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

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

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

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

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

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

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

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

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

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

Signed-off-by: Jan Alexander Steffens (heftig) <heftig@archlinux.org>