elfutils:users/halamour/try-pr30991

Last commit made on 2024-02-02
Get this branch:
git clone -b users/halamour/try-pr30991 https://git.launchpad.net/elfutils

Branch merges

Branch information

Name:
users/halamour/try-pr30991
Repository:
lp:elfutils

Recent commits

bd18c04... by Housam Alamour <email address hidden>

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 <email address hidden>

7554d41... by Frank Ch. Eigler

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 <email address hidden>

c1058da... by Aaron Merey <email address hidden>

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 <email address hidden>

ae580d4... by Sergei Trofimovich

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 <email address hidden>

a2194f6... by Khem Raj

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 <email address hidden>
Signed-off-by: Mark Wielaard <email address hidden>

744e3ea... by Mark J. Wielaard

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 <email address hidden>

03c1719... by Aleksei Vetrov <email address hidden>

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 <email address hidden>

2f38fa5... by Aaron Merey <email address hidden>

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 <email address hidden>

e54af3a... by Aleksei Vetrov <email address hidden>

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 <email address hidden>

0ab5a3e... by Aleksei Vetrov <email address hidden>

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 <email address hidden>