[PATCH] PR 30991: srcfiles tarball feature

2024-02-02 Thread Housam Alamour
* 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 
---
 NEWS   |   8 +
 configure.ac   |   5 +-
 debuginfod/debuginfod.cxx  |   2 -
 doc/srcfiles.1 |  33 +++-
 src/Makefile.am|   9 +-
 src/srcfiles.cxx   | 305 +
 tests/debuginfod-subr.sh   |  14 +-
 tests/run-srcfiles-self.sh |  74 -
 8 files changed, 400 insertions(+), 50 deletions(-)

diff --git a/NEWS b/NEWS
index 0420d3b8..3391d6a1 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,8 @@
+Version 0.191 (after 0.189)
+
+srcfiles: Can now fetch the source files of a DWARF/ELF file and
+  place them into a zip.
+
 Version 0.190 "Woke!"
 
 CONTRIBUTING: Switch from real name policy to known identity policy.
@@ -9,6 +14,9 @@ libelf: Add RELR support.
 
 libdw: Recognize .debug_[ct]u_index sections
 
+srcfiles: added srcfiles tool that lists all the source files of a given 
+  DWARF/ELF file.
+
 readelf: Support readelf -Ds, --use-dynamic --symbol.
  Support .gdb_index version 9
 
diff --git a/configure.ac b/configure.ac
index af5b6bf7..ddb79b83 100644
--- a/configure.ac
+++ b/configure.ac
@@ -841,7 +841,7 @@ AM_CONDITIONAL([LIBDEBUGINFOD],[test 
"x$enable_libdebuginfod" = "xyes" || test "
 AM_CONDITIONAL([DUMMY_LIBDEBUGINFOD],[test "x$enable_libdebuginfod" = 
"xdummy"])
 AC_CHECK_HEADERS([execinfo.h])
 
-# Look for libmicrohttpd, libarchive, sqlite for debuginfo server
+# Look for libmicrohttpd, libarchive, sqlite for debuginfo server and srcfiles 
tool
 # minimum versions as per rhel7.
 AC_ARG_ENABLE([debuginfod],AS_HELP_STRING([--enable-debuginfod], [Build 
debuginfod server]))
 AS_IF([test "x$enable_debuginfod" != "xno"], [
@@ -853,11 +853,12 @@ AS_IF([test "x$enable_debuginfod" != "xno"], [
   AC_MSG_ERROR([need libdebuginfod (or dummy), use --disable-debuginfod to 
disable.])
 fi
 enable_debuginfod=yes # presume success
+AC_DEFINE([HAVE_LIBARCHIVE], [1], [Define to 1 if libarchive is 
available]) # presume success
 PKG_PROG_PKG_CONFIG
 PKG_CHECK_MODULES([libmicrohttpd],[libmicrohttpd >= 
0.9.33],[],[enable_debuginfod=no])
 PKG_CHECK_MODULES([oldlibmicrohttpd],[libmicrohttpd < 
0.9.51],[old_libmicrohttpd=yes],[old_libmicrohttpd=no])
 PKG_CHECK_MODULES([sqlite3],[sqlite3 >= 3.7.17],[],[enable_debuginfod=no])
-PKG_CHECK_MODULES([libarchive],[libarchive >= 
3.1.2],[],[enable_debuginfod=no])
+PKG_CHECK_MODULES([libarchive],[libarchive >= 
3.1.2],[],[enable_debuginfod=no], AC_DEFINE([HAVE_LIBARCHIVE], [0], [Define to 
0 if libarchive is not available]))
 if test "x$enable_debuginfod" = "xno"; then
   AC_MSG_ERROR([dependencies not found, use --disable-debuginfod to 
disable.])
 fi
diff --git a/debuginfod/debuginfod.cxx b/debuginfod/debuginfod.cxx
index 524be948..6b21f46f 100644
--- a/debuginfod/debuginfod.cxx
+++ b/debuginfod/debuginfod.cxx
@@ -2996,8 +2996,6 @@ dwarf_extract_source_paths (Elf *elf, set& 
debug_sourcefiles)
 
   if (comp_dir[0] == '\0' && cuname[0] != '/')
 {
-  // This is a common symptom for dwz-compressed debug files,
-  // where the altdebug file cannot be resolved.
   if (verbose > 3)
 obatched(clog) << "skipping cu=" << cuname << " due to empty 
comp_dir" << endl;
   continue;
diff --git a/doc/srcfiles.1 b/doc/srcfiles.1
index 6149c21b..c6338315 100644
--- a/doc/srcfiles.1
+++ b/doc/srcfiles.1
@@ -21,15 +21,18 @@
 eu-srcfiles \- Lists the source files of a DWARF/ELF file.
 
 .SH "SYNOPSIS"
-eu-srcfiles [\fB\-0\fR|\fB\-\-null\fR] [\fB\-c\fR|\fB\-\-cu\-only\fR] 
[\fB\-v\fR|\fB\-\-verbose\fR] INPUT
+eu-srcfiles [\fB\-0\fR|\fB\-\-null\fR] [\fB\-c\fR|\fB\-\-cu\-only\fR] 
[\fB\-v\fR|\fB\-\-verbose\fR] [\fB\-z\fR|\fB\-\-zip\fR] INPUT
 
 .SH "DE

[Bug libelf/31225] Crash when using elf_memory() on a compressed section; fixed with s/ELF_C_READ/ELF_C_READ_MMAP/

2024-02-02 Thread bruening at google dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=31225

--- Comment #4 from Derek Bruening  ---
>  So I added one that checks various issues (and that fails before your 
> suggested change). Please take a look:
>
> https://inbox.sourceware.org/elfutils-devel/20240201143858.930159-1-m...@klomp.org/

LGTM!  Thank you for adding the test case.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

[Bug libelf/31225] Crash when using elf_memory() on a compressed section; fixed with s/ELF_C_READ/ELF_C_READ_MMAP/

2024-02-02 Thread mark at klomp dot org
https://sourceware.org/bugzilla/show_bug.cgi?id=31225

Mark Wielaard  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|ASSIGNED|RESOLVED

--- Comment #5 from Mark Wielaard  ---
commit cc44ac6740797a23cd0af0cb22bd828d569224b8
Author: Mark Wielaard 
Date:   Thu Feb 1 14:56:18 2024 +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 
Signed-off-by: Mark Wielaard 

-- 
You are receiving this mail because:
You are on the CC list for the bug.