Re: [PATCH v3] strip: keep .ctf section in stripped file

2023-03-03 Thread Mark Wielaard
Hi Guillermo,

On Thu, 2023-03-02 at 20:40 -0600, Guillermo E. Martinez wrote:
> On Tue, Feb 28, 2023 at 03:27:13PM +0100, Mark Wielaard wrote:
> > There are some exceptions to the general rule in eu-strip of dropping
> > not referenced, non-allocated, SHT_PROGBIT sections. SHT_NOTE sections
> > are never removed (even if they aren't allocated), as are non-
> > SHT_PROGBIT sections. ".gnu.warning." sections also aren't (even if
> > they are non-allocated SHT_PROGBIT sections). And ".comment" sections
> > aren't if not explicitly told to.
> > 
> > Guillermo's patch proposes to make ".ctf" another special case
> > (defaulting to keeping).
> > 
> > I am mainly wondering why binutils strip already seems to keep ".ctf"
> > sections (even without -g).
> > 
> 
> I'm not plenty sure, but I can tell that it was done so, because CTF was
> designed having in mind a lightweight debug format being shipped along with
> the other allocated ELF sections:
> 
>   "CTF and DWARF data can coexist in the same ELF file, she said, since 
> the
>   CTF data has its own dedicated section. The CTF data is naturally
>   smaller, but the format also includes compression to reduce the size
>   requirements further. The result is that this data, unlike DWARF
>   information, need not be stripped to get the executable file down to a
>   reasonable size."
> 
> https://lwn.net/Articles/795384/

Right. But I am wondering how that mechanism works with binutils strip.
Apparently we do something different in eu-strip which makes it
necessary to add a --keep-ctf option based on the section name. It
would be good if we figured out how/what we can do to keep the
different strip utilities in sync.

Cheers,

Mark


Re: [PATCH v3] strip: keep .ctf section in stripped file

2023-03-03 Thread Nick Clifton via Elfutils-devel

Hi Mark,


I am mainly wondering why binutils strip already seems to keep ".ctf"
sections (even without -g).



Right. But I am wondering how that mechanism works with binutils strip.
Apparently we do something different in eu-strip which makes it
necessary to add a --keep-ctf option based on the section name. It
would be good if we figured out how/what we can do to keep the
different strip utilities in sync.


I think that the function that does this is "is_strip_section_1" in
binutils/objcopy.c.  If an input section has the BSF_DEBUGGING flag
set (an internal flag to he BFD library, but basically it should be
set for all debug sections, including .ctf sections I think), then
the basic decision is to keep the section unless -g is used.

Cheers
  Nick



[COMMITTED] readelf: Fix use-after-free ebl pointer issue

2023-03-03 Thread Mark Wielaard
With -flto gcc 13 sees that we use the ebl pointer after closing and
freeing it.

In function ‘process_elf_file’,
inlined from ‘process_dwflmod’ at readelf.c:818:3:
readelf.c:1070:6: error: pointer ‘ebl_18’ used after ‘free’ 
[-Werror=use-after-free]
 1070 |   if (pure_ebl != ebl)
  |  ^
In function ‘ebl_closebackend’,
inlined from ‘process_elf_file’ at readelf.c:1068:3,
inlined from ‘process_dwflmod’ at readelf.c:818:3:
../libebl/eblclosebackend.c:47:7: note: call to ‘free’ here
   47 |   free (ebl);
  |   ^

Fix by only calling ebl_closebackend after using it in the comparison.

Signed-off-by: Mark Wielaard 
---
 src/ChangeLog | 5 +
 src/readelf.c | 5 +++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index 699d98ee..c26dafdd 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2023-03-03  Mark Wielaard  
+
+   * readelf (process_elf_file): ebl_closebackend only after
+   comparing ebl pointer.
+
 2023-02-12  Mark Wielaard  
 
* readelf.c (print_attributes): Add comment about check.
diff --git a/src/readelf.c b/src/readelf.c
index 0f13874f..6950204e 100644
--- a/src/readelf.c
+++ b/src/readelf.c
@@ -1065,13 +1065,14 @@ process_elf_file (Dwfl_Module *dwflmod, int fd)
   if (print_string_sections)
 print_strings (ebl);
 
-  ebl_closebackend (ebl);
-
   if (pure_ebl != ebl)
 {
+  ebl_closebackend (ebl);
   ebl_closebackend (pure_ebl);
   elf_end (pure_elf);
 }
+  else
+ebl_closebackend (ebl);
 }
 
 
-- 
2.39.2



[COMMITTED] libelf: Document and make ELFCOMPRESS_ZSTD usable with old system elf.h

2023-03-03 Thread Mark Wielaard
Make sure that even if the system elf.h doesn't have ELF_COMPRESS_ZSTD
defined it can still be used as constant. Also update libelf.h
documentation and add new feature to NEWS.

Signed-off-by: Mark Wielaard 
---
 ChangeLog|  4 
 NEWS |  8 +++-
 libelf/ChangeLog |  5 +
 libelf/libelf.h  | 13 +
 4 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 53a1d292..10c23002 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2023-03-03  Mark Wielaard  
+
+   * NEWS: Add ELFCOMPRESS_ZSTD support for libelf and elfcompress.
+
 2023-02-23  Mark Wielaard  
 
* NEWS: Add old version code names.
diff --git a/NEWS b/NEWS
index c01513d0..4985658f 100644
--- a/NEWS
+++ b/NEWS
@@ -1,11 +1,17 @@
-Version 0.189
+Version 0.189 "Don't deflate!"
 
 configure: eu-nm, eu-addr2line and eu-stack can provide demangled symbols
when linked with libstdc++. Use --disable-demangler to disable.
 
+libelf: elf_compress now supports ELFCOMPRESS_ZSTD when build against
+libzstd
+
 libdwfl: dwfl_module_return_value_location now returns 0 (no return type)
  for DIEs that point to a DW_TAG_unspecified_type.
 
+elfcompress: -t, --type= now support zstd if libelf has been build with
+ ELFCOMPRESS_ZSTD support.
+
 Version 0.188 "no section left behind"
 
 readelf: Add -D, --use-dynamic option.
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index bfd6b82d..8cc3c53c 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,8 @@
+2023-03-03  Mark Wielaard  
+
+   * libelf.h: Define ELFCOMPRESS_ZSTD if undefined.
+   (elf_compress): Document ELFCOMPRESS_ZSTD compression type.
+
 2023-02-20  Mark Wielaard  
 
* gnuhash_xlate.h (elf_cvt_gnuhash): memmove any left over bytes.
diff --git a/libelf/libelf.h b/libelf/libelf.h
index a139e733..2374a48a 100644
--- a/libelf/libelf.h
+++ b/libelf/libelf.h
@@ -64,6 +64,11 @@
  #define ELFCOMPRESS_HIPROC 0x7fff /* End of processor-specific.  */
 #endif
 
+#ifndef ELFCOMPRESS_ZSTD
+ /* So ZSTD compression can be used even with an old system elf.h.  */
+ #define ELFCOMPRESS_ZSTD   2  /* Zstandard algorithm.  */
+#endif
+
 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)
 # define __nonnull_attribute__(...) __attribute__ ((__nonnull__ (__VA_ARGS__)))
 # define __deprecated_attribute__ __attribute__ ((__deprecated__))
@@ -348,10 +353,10 @@ extern Elf64_Chdr *elf64_getchdr (Elf_Scn *__scn);
 
elf_compress takes a compression type that should be either zero to
decompress or an ELFCOMPRESS algorithm to use for compression.
-   Currently only ELFCOMPRESS_ZLIB is supported.  elf_compress_gnu
-   will compress in the traditional GNU compression format when
-   compress is one and decompress the section data when compress is
-   zero.
+   Currently ELFCOMPRESS_ZLIB and ELFCOMPRESS_ZSTD are supported.
+   elf_compress_gnu will compress in the traditional GNU compression
+   format when compress is one and decompress the section data when
+   compress is zero.
 
The FLAGS argument can be zero or ELF_CHF_FORCE.  If FLAGS contains
ELF_CHF_FORCE then it will always compress the section, even if
-- 
2.39.2



[COMMITTED] Prepare for 0.189

2023-03-03 Thread Mark Wielaard
Set version to 0.189
Update NEWS and elfutils.spec.in
Set copyright year in configure.ac and printversion.
Regenerate po/*.po files.

Signed-off-by: Mark Wielaard 
---
 NEWS|5 +
 config/elfutils.spec.in |   13 +
 configure.ac|4 +-
 lib/printversion.c  |2 +-
 po/de.po| 1485 +++---
 po/es.po| 1505 +++---
 po/ja.po| 1503 +++---
 po/pl.po| 1509 ---
 po/uk.po| 1508 +++---
 9 files changed, 3813 insertions(+), 3721 deletions(-)

diff --git a/NEWS b/NEWS
index 4985658f..16e37eca 100644
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,9 @@ Version 0.189 "Don't deflate!"
 configure: eu-nm, eu-addr2line and eu-stack can provide demangled symbols
when linked with libstdc++. Use --disable-demangler to disable.
 
+   A new option --enable-sanitize-memory has been added for msan
+   sanitizer support.
+
 libelf: elf_compress now supports ELFCOMPRESS_ZSTD when build against
 libzstd
 
@@ -12,6 +15,8 @@ libdwfl: dwfl_module_return_value_location now returns 0 (no 
return type)
 elfcompress: -t, --type= now support zstd if libelf has been build with
  ELFCOMPRESS_ZSTD support.
 
+backends: Add support for LoongArch and Synopsys ARCv2 processors.
+
 Version 0.188 "no section left behind"
 
 readelf: Add -D, --use-dynamic option.
diff --git a/config/elfutils.spec.in b/config/elfutils.spec.in
index c444d1f5..c82a40c5 100644
--- a/config/elfutils.spec.in
+++ b/config/elfutils.spec.in
@@ -341,6 +341,19 @@ exit 0
 %systemd_postun_with_restart debuginfod.service
 
 %changelog
+* Fri Mar  3 2023 Mark Wielaard  0.189-1
+- configure: eu-nm, eu-addr2line and eu-stack can provide demangled
+  symbols when linked with libstdc++. Use --disable-demangler to disable.
+  A new option --enable-sanitize-memory has been added for msan sanitizer
+  support.
+- libelf: elf_compress now supports ELFCOMPRESS_ZSTD when build
+  against libzstd
+- libdwfl: dwfl_module_return_value_location now returns 0 (no return
+  type) for DIEs that point to a DW_TAG_unspecified_type.
+- elfcompress: -t, --type= now support zstd if libelf has been build
+  with ELFCOMPRESS_ZSTD support.
+- backends: Add support for LoongArch and Synopsys ARCv2 processors.
+
 * Wed Nov  2 2022 Mark Wielaard  0.188-1
 - readelf: Add -D, --use-dynamic option.
 - debuginfod-client: Add $DEBUGINFOD_HEADERS_FILE setting to supply
diff --git a/configure.ac b/configure.ac
index 142a89f6..6e881fa0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -18,7 +18,7 @@ dnl  GNU General Public License for more details.
 dnl
 dnl  You should have received a copy of the GNU General Public License
 dnl  along with this program.  If not, see .
-AC_INIT([elfutils],[0.188],[https://sourceware.org/bugzilla],[elfutils],[http://elfutils.org/])
+AC_INIT([elfutils],[0.189],[https://sourceware.org/bugzilla],[elfutils],[http://elfutils.org/])
 
 dnl Workaround for older autoconf < 2.64
 m4_ifndef([AC_PACKAGE_URL],
@@ -45,7 +45,7 @@ fi
 AC_CONFIG_AUX_DIR([config])
 AC_CONFIG_FILES([config/Makefile])
 
-AC_COPYRIGHT([Copyright (C) 1996-2022 The elfutils developers.])
+AC_COPYRIGHT([Copyright (C) 1996-2023 The elfutils developers.])
 AC_PREREQ(2.63)dnl Minimum Autoconf version required.
 
 dnl We use GNU make extensions; automake 1.10 defaults to -Wportability.
diff --git a/lib/printversion.c b/lib/printversion.c
index 7d31fa83..be629b59 100644
--- a/lib/printversion.c
+++ b/lib/printversion.c
@@ -40,5 +40,5 @@ print_version (FILE *stream, struct argp_state *state)
 Copyright (C) %s The elfutils developers <%s>.\n\
 This is free software; see the source for copying conditions.  There is NO\n\
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
-"), "2022", PACKAGE_URL);
+"), "2023", PACKAGE_URL);
 }

[... .po ...]

-- 
2.39.2



[COMMITTED] Fix static build when zstd is enabled for libelf

2023-03-03 Thread Mark Wielaard
When doing a static build (as with --enable-gcov) the build fails
because the executables aren't linked with -lzstd. Also the
run-debuginfod-query-retry.sh test relies on libdebuginfod.so.1 which
isn't there.

Fix by adding $(zstd_LIBS) to the static libelf lines and using the
debuginfod-find executable itself in the testcase.

* src/Makefile.am (libelf): When BUILD_STATIC add $(zstd_LIBS)
* tests/Makefile.am (libelf): Likewise.
* tests/run-debuginfod-query-retry.sh: Use debuginfod-find instead
  of libdebuginfod.so.1

Signed-off-by: Mark Wielaard 
---
 src/Makefile.am | 2 +-
 tests/Makefile.am   | 2 +-
 tests/run-debuginfod-query-retry.sh | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 6cc019da..10d59a48 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -42,7 +42,7 @@ CLEANFILES += make-debug-archive
 if BUILD_STATIC
 libasm = ../libasm/libasm.a
 libdw = ../libdw/libdw.a -lz $(zip_LIBS) $(libelf) -ldl -lpthread
-libelf = ../libelf/libelf.a -lz
+libelf = ../libelf/libelf.a -lz $(zstd_LIBS)
 else
 libasm = ../libasm/libasm.so
 libdw = ../libdw/libdw.so
diff --git a/tests/Makefile.am b/tests/Makefile.am
index fd58bf84..7e32f117 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -664,7 +664,7 @@ installcheck-local:
 
 if BUILD_STATIC
 libdw = ../libdw/libdw.a -lz $(zip_LIBS) $(libelf) $(libebl) -ldl -lpthread
-libelf = ../libelf/libelf.a -lz
+libelf = ../libelf/libelf.a -lz $(zstd_LIBS)
 libasm = ../libasm/libasm.a
 else
 libdw = ../libdw/libdw.so
diff --git a/tests/run-debuginfod-query-retry.sh 
b/tests/run-debuginfod-query-retry.sh
index 2f551ffb..d2cdfd65 100755
--- a/tests/run-debuginfod-query-retry.sh
+++ b/tests/run-debuginfod-query-retry.sh
@@ -26,7 +26,7 @@ unset VALGRIND_CMD
 # set up tests for retrying failed queries.
 retry_attempts=`(testrun env DEBUGINFOD_URLS=http://255.255.255.255/JUNKJUNK 
DEBUGINFOD_RETRY_LIMIT=10 DEBUGINFOD_VERBOSE=1 
DEBUGINFOD_CACHE_PATH=${PWD}/.client_cache \
 ${abs_top_builddir}/debuginfod/debuginfod-find debuginfo \
-${abs_top_builddir}/debuginfod/libdebuginfod.so.1 || true) \
+${abs_top_builddir}/debuginfod/debuginfod-find || true) \
 2>&1 >/dev/null | grep -c 'Retry failed query'`
 if [ $retry_attempts -ne 10 ]; then
 echo "retry mechanism failed."
-- 
2.39.2



elfutils 0.189 released

2023-03-03 Thread Mark Wielaard
ELFUTILS 0.189 "Don't deflate!" - http://elfutils.org/

A new release of elfutils is available at:
ftp://sourceware.org/pub/elfutils/0.188/
or https://sourceware.org/elfutils/ftp/0.188/

Visit us on the Libera.Chat irc channel #elfutils

* NEWS *

configure: eu-nm, eu-addr2line and eu-stack can provide demangled
   symbols when linked with libstdc++. Use --disable-demangler
   to disable.

   A new option --enable-sanitize-memory has been added for
   msan sanitizer support.

libelf: elf_compress now supports ELFCOMPRESS_ZSTD when build against
libzstd

libdwfl: dwfl_module_return_value_location now returns 0 (no return
 type) for DIEs that point to a DW_TAG_unspecified_type.

elfcompress: -t, --type= now support zstd if libelf has been build
 with ELFCOMPRESS_ZSTD support.

backends: Add support for LoongArch and Synopsys ARCv2 processors.


* GIT SHORTLOG *

Aaron Merey (3):
  debuginfod_find_section: Always update rc with most recent error code
  debuginfod-client.c: Don't treat 0 as an error code.
  debuginfod-client.c: Download section even if cached executable
  didn't contain it.

Aleksei Vetrov (3):
  libdwfl: add check for elf_memory return value
  libdw: check memory access in get_(u|s)leb128
  libdw: check that DWARF strings are null-terminated

Andrew Paprocki (1):
  PR29926: debuginfod: Fix usage of deprecated CURLINFO_*

Frank Ch. Eigler (2):
  debuginfod.cxx: fix coverity-found use-after-release error
  debuginfod PR29975 & PR29976: decrease default concurrency

Gavin Li (1):
  libdwfl: Read no more than required in dwfl_segment_report_module

Hengqi Chen (1):
  Add support for LoongArch

Ilya Leoshkevich (11):
  readelf: Fix set but not used variable
  Initialize reglocs for VMCOREINFO
  addr2line: Do not test demangling in run-addr2line-i-test.sh
  libasm: Fix xdefault_pattern initialization
  readelf: Fix set but not used parameter
  configure: Use -fno-addrsig if possible
  configure: Add --disable-demangler
  tests: Ignore dwfl-report-offline-memory
  printversion: Fix unused variable
  backends: Support returning lvalue and rvalue references
  configure: Add --enable-sanitize-memory

Mark Wielaard (35):
  debuginfod: Mark extract_section function static
  readelf: Check phdr != NULL or shdr != NULL in handle_dynamic.
  libdw: Don't dereference and assign values we are skipping
  readelf: Check gelf_getdyn doesn't return NULL
  debuginfod: Initialize response_data early in debuginfod-client query
  libelf: Sync elf.h from glibc
  Do not use relative include paths in library files.
  debuginfod: Define CURL_AT_LEAST_VERSION if necessary
  lib: Remove -ffunction-sections for xmalloc
  libdwfl: Don't undef _
  debuginfod-client: Use CURLOPT_PROTOCOLS_STR for libcurl >= 7.85.0
  readelf: Check compression status of .debug section data
  backends: sparc uses NONE relocation type in ET_EXEC and ET_DYN files
  tests: run-debuginfod-query-retry.sh /bin/sh might not have a
  build-id
  addr2line: -C should not try to handle optional (ignored) argument
  libdw: Search for abstract origin in the correct CU
  tests: Check ELFUTILS_DISABLE_DEMANGLE in run-addr2line-C-test.sh
  debuginfod: Make sure there is only one typedef for debuginfod_client
  backends: Handle DW_TAG_unspecified_type in dwarf_peeled_die_type
  libdw, readelf, elflint: Add get_(u|s)leb128 guards
  libdw: Handle DW_OP_GNU_uninit in dwarf_getlocation
  libdw: Correct data end checkfor deref_type operand in
  dwarf_getlocation
  doc: Add .TP before -g in debuginfod.8
  configure: Error when demangler is enabled, but libstdc++ support
  isn't
  NEWS: Mention linking with libstdc++ or using --disable-demangler
  libasm: Fix use-after-free issue with circular single linked list
  cleanup
  configure: Check for and -Wuse-after-free=3 when available
  Update m4 files from autoconf-archive
  NEWS: Add old version code names
  libelf: memmove any extra bytes left by elf_cvt_gnuhash conversion
  libdw: Use elf_rawdata when checking .debug section
  libdw: Fix dwarf_getscopes memory leak on error
  readelf: Fix use-after-free ebl pointer issue
  libelf: Document and make ELFCOMPRESS_ZSTD usable with old system
  elf.h
  Prepare for 0.189

Martin Liska (4):
  readelf: print warning for -sW
  Missing newline for: elfcompress -t zlib-gnu a.out -force
  Refactor elf_compare
  support ZSTD compression algorithm

Sam James (1):
  Fix typos from codespell

Serhei Makarov (1):
  debuginfod-find.1: note on how to find a comp_dir

Shahab Vahedi (1):
  Add support for Synopsys ARCv2 processors

Yonggang Luo (4):
  libcpu: Use "#define FCT_mod$64r_m FCT_mod$r_m" in i386_data.h
  libdw: Change typeof -> __typeof in memory-access.h
  libcpu: Use __asm instead of asm to mark variables as used
  libcpu: Remove the need of NMNES by using enum



signature.asc
Description: This is a digitally signed message part