]> git.ipfire.org Git - thirdparty/elfutils.git/log
thirdparty/elfutils.git
8 months agoeu-stacktrace WIP: remove FLAGS from x86 regs (REQUIRES matching sysprof patch) users/serhei/eu-stacktrace.v0
Serhei Makarov [Fri, 11 Oct 2024 17:11:39 +0000 (13:11 -0400)] 
eu-stacktrace WIP: remove FLAGS from x86 regs (REQUIRES matching sysprof patch)

Found this cleanup necessary in the for-submission patchset;
must also change it in this branch since it requires a matching change
in sysprof.

10 months agoREADME.eu-stacktrace: fixup git clone command
Serhei Makarov [Thu, 29 Aug 2024 20:28:00 +0000 (16:28 -0400)] 
README.eu-stacktrace: fixup git clone command

10 months agoeu-stacktrace cleanup: simplify summary-printing code
Serhei Makarov [Thu, 29 Aug 2024 20:26:39 +0000 (16:26 -0400)] 
eu-stacktrace cleanup: simplify summary-printing code

10 months agoeu-stacktrace WIP: show # of dwfltab processes in summary
Serhei Makarov [Thu, 29 Aug 2024 20:26:19 +0000 (16:26 -0400)] 
eu-stacktrace WIP: show # of dwfltab processes in summary

10 months agoeu-stacktrace WIP: add dwfltab resizing
Serhei Makarov [Thu, 29 Aug 2024 14:46:50 +0000 (10:46 -0400)] 
eu-stacktrace WIP: add dwfltab resizing

10 months agoeu-stacktrace fixup: report dwfltab overflow cleanly
Serhei Makarov [Thu, 29 Aug 2024 14:45:46 +0000 (10:45 -0400)] 
eu-stacktrace fixup: report dwfltab overflow cleanly

10 months agoeu-stacktrace WIP: fix register order, 32-bit unwinding
Serhei Makarov [Tue, 27 Aug 2024 15:26:57 +0000 (11:26 -0400)] 
eu-stacktrace WIP: fix register order, 32-bit unwinding

The exciting 'scrambled eggs' transformations performed on the
x86 register files as it passes from hw to perf to DWARF are
quite something and require some magic numbers (sources carefully cited)
to be made to work correctly. The previous code worked deceptively
well but missed various cases.

h/t to qt perfparser for showing the precedent that this can be done,
even if our magic numbers are slightly different (due to omitting
segment registers).

10 months agoeu-stacktrace WIP: elf memory read, more pieces for 32-bit unwinding
Serhei Makarov [Mon, 26 Aug 2024 16:28:26 +0000 (12:28 -0400)] 
eu-stacktrace WIP: elf memory read, more pieces for 32-bit unwinding

The 32-bit unwinding needs some more testing.

10 months agoeu-stacktrace fixup: don't print startup banner on error
Serhei Makarov [Thu, 22 Aug 2024 22:09:29 +0000 (18:09 -0400)] 
eu-stacktrace fixup: don't print startup banner on error

10 months agoeu-stacktrace fixup: count samples where sysprof_init_dwfl failed
Serhei Makarov [Thu, 22 Aug 2024 22:08:49 +0000 (18:08 -0400)] 
eu-stacktrace fixup: count samples where sysprof_init_dwfl failed

10 months agoeu-stacktrace fixup: redundant declaration in sysprof_init_dwfl
Serhei Makarov [Thu, 22 Aug 2024 22:07:52 +0000 (18:07 -0400)] 
eu-stacktrace fixup: redundant declaration in sysprof_init_dwfl

10 months agoeu-stacktrace WIP: sketch how to handle PERF_SAMPLE_REGS_ABI_32
Serhei Makarov [Thu, 22 Aug 2024 20:24:44 +0000 (16:24 -0400)] 
eu-stacktrace WIP: sketch how to handle PERF_SAMPLE_REGS_ABI_32

Needs some additional debugging. But we accept the abi constant
from Sysprof (added in the recent patch 49115e50
in https://git.sr.ht/~serhei/sysprof-experiments)
and check it at the correct locations. Now we just need the
register layout table to get rid of the possible-incorrect magic
number code....

10 months agoeu-stacktrace WIP: rearrange the code into sections
Serhei Makarov [Wed, 21 Aug 2024 14:16:34 +0000 (10:16 -0400)] 
eu-stacktrace WIP: rearrange the code into sections

Put things in a more logical order as previous incremental
changes led to slightly arbitrary sequence of declarations.

10 months agoeu-stacktrace WIP: exclude show_memory_reads from --debug for now
Serhei Makarov [Thu, 15 Aug 2024 21:40:19 +0000 (17:40 -0400)] 
eu-stacktrace WIP: exclude show_memory_reads from --debug for now

"One line per frame" is a far more natural debugging mode
than "one line plus additional memory-read fluff".

10 months agoeu-stacktrace WIP: optional LIBDWFL_TRACKS_UNWOUND_SOURCE patch
Serhei Makarov [Thu, 15 Aug 2024 21:37:48 +0000 (17:37 -0400)] 
eu-stacktrace WIP: optional LIBDWFL_TRACKS_UNWOUND_SOURCE patch

patch -p1 <libdwfl-report-unwound-source.patch

This is an optional diagnostic patch that tracks the unwinding
mechanism used to produce each Dwfl_Frame.

Plus some #ifdef code in src/stacktrace.c that uses the
field to report per-frame or per-process which unwinding
mechanism was used.

Pending to figure out a better way to expand the libdwfl
data structures with additional tracking info.

10 months agoeu-stacktrace WIP: logging -- startup message, percent samples dropped
Serhei Makarov [Thu, 15 Aug 2024 21:31:29 +0000 (17:31 -0400)] 
eu-stacktrace WIP: logging -- startup message, percent samples dropped

10 months agoREADME.eu-stacktrace: fix sysprof-cli + manual eu-stacktrace invocation
Serhei Makarov [Thu, 15 Aug 2024 21:24:28 +0000 (17:24 -0400)] 
README.eu-stacktrace: fix sysprof-cli + manual eu-stacktrace invocation

12 months agoeu-stacktrace WIP: match sysprof's handling of SIGINT
Serhei Makarov [Mon, 24 Jun 2024 15:29:03 +0000 (11:29 -0400)] 
eu-stacktrace WIP: match sysprof's handling of SIGINT

Without the signal handler, eu-stacktrace gets terminated early
by a SIGINT inherited from a parent sysprof process, and isn't
able to finish processing all the data packets.

12 months agoREADME.eu-stacktrace: note sysprof-cli --use-stacktrace is WIP
Serhei Makarov [Mon, 10 Jun 2024 21:54:03 +0000 (17:54 -0400)] 
README.eu-stacktrace: note sysprof-cli --use-stacktrace is WIP

12 months agoeu-stacktrace WIP: further README fixes
Serhei Makarov [Mon, 10 Jun 2024 15:03:02 +0000 (11:03 -0400)] 
eu-stacktrace WIP: further README fixes

12 months agoeu-stacktrace WIP: fixes to build instructions in README
Serhei Makarov [Sat, 8 Jun 2024 18:45:35 +0000 (14:45 -0400)] 
eu-stacktrace WIP: fixes to build instructions in README

12 months agoeu-stacktrace WIP: maxframes only used with HAVE_SYSPROF_HEADERS
Serhei Makarov [Sat, 8 Jun 2024 18:41:21 +0000 (14:41 -0400)] 
eu-stacktrace WIP: maxframes only used with HAVE_SYSPROF_HEADERS

12 months agoeu-stacktrace WIP: update README
Serhei Makarov [Thu, 6 Jun 2024 16:34:39 +0000 (12:34 -0400)] 
eu-stacktrace WIP: update README

13 months agoeu-stacktrace WIP: default to mode 'naive'
Serhei Makarov [Thu, 30 May 2024 17:34:36 +0000 (13:34 -0400)] 
eu-stacktrace WIP: default to mode 'naive'

16 months agoeu-stacktrace WIP configury: sysprof-N/sysprof-capture-types.h
Serhei Makarov [Fri, 2 Feb 2024 20:46:36 +0000 (15:46 -0500)] 
eu-stacktrace WIP configury: sysprof-N/sysprof-capture-types.h

17 months agoeu-stacktrace WIP: optional debuginfo callbacks as in stack.c
Serhei Makarov [Fri, 26 Jan 2024 17:56:00 +0000 (12:56 -0500)] 
eu-stacktrace WIP: optional debuginfo callbacks as in stack.c

This is an #ifdef option since it's really of dubious utility.

17 months agoeu-stacktrace WIP: additional tweak to diagnostics
Serhei Makarov [Fri, 26 Jan 2024 17:50:40 +0000 (12:50 -0500)] 
eu-stacktrace WIP: additional tweak to diagnostics

17 months agoeu-stacktrace WIP: more module diagnostics
Serhei Makarov [Thu, 25 Jan 2024 20:03:32 +0000 (15:03 -0500)] 
eu-stacktrace WIP: more module diagnostics

These were helpful for debugging the latest issues, but are perhaps a
bit hacky. Placing them within an #ifdef for the time being.

17 months agoeu-stacktrace WIP fixes: accept a full sample of 18 registers
Serhei Makarov [Thu, 25 Jan 2024 19:58:09 +0000 (14:58 -0500)] 
eu-stacktrace WIP fixes: accept a full sample of 18 registers

This significantly improves our results.

17 months agoeu-stacktrace WIP: verbose,debug options to control diagnostics
Serhei Makarov [Mon, 22 Jan 2024 19:28:17 +0000 (14:28 -0500)] 
eu-stacktrace WIP: verbose,debug options to control diagnostics

17 months agoeu-stacktrace WIP: fix sysprof_init_dwfl
Serhei Makarov [Thu, 18 Jan 2024 22:00:30 +0000 (17:00 -0500)] 
eu-stacktrace WIP: fix sysprof_init_dwfl

Some of the data was not being reset properly on a new sample.

17 months agoeu-stacktrace WIP: print summary diagnostics at the end of the run
Serhei Makarov [Thu, 18 Jan 2024 21:58:42 +0000 (16:58 -0500)] 
eu-stacktrace WIP: print summary diagnostics at the end of the run

17 months agoeu-stacktrace WIP fixes: introduce a frame limit
Serhei Makarov [Thu, 18 Jan 2024 21:50:33 +0000 (16:50 -0500)] 
eu-stacktrace WIP fixes: introduce a frame limit

Rarely, the unwinder can loop indefinitely.
Guard against this, similarly to the code in stack.c.

17 months agoeu-stacktrace WIP fixes: dwfl_report_end
Serhei Makarov [Fri, 12 Jan 2024 17:54:54 +0000 (12:54 -0500)] 
eu-stacktrace WIP fixes: dwfl_report_end

There are several things to improve to get parity with eu-stack
in terms of CFI handling; this is the first fix.

18 months agoeu-stacktrace WIP: minor formatting fixup
Serhei Makarov [Mon, 11 Dec 2023 18:57:29 +0000 (13:57 -0500)] 
eu-stacktrace WIP: minor formatting fixup

18 months agoeu-stacktrace WIP: initial version of Dwfl caching, print comm
Serhei Makarov [Mon, 11 Dec 2023 18:56:23 +0000 (13:56 -0500)] 
eu-stacktrace WIP: initial version of Dwfl caching, print comm

19 months agoeu-stacktrace WIP: improve error msg when write offset < 0
Serhei Makarov [Fri, 1 Dec 2023 19:55:32 +0000 (14:55 -0500)] 
eu-stacktrace WIP: improve error msg when write offset < 0

19 months agoeu-stacktrace WIP: assemble and output the callchain frame
Serhei Makarov [Thu, 23 Nov 2023 20:23:14 +0000 (15:23 -0500)] 
eu-stacktrace WIP: assemble and output the callchain frame

19 months agoeu-stacktrace WIP: prefer uint8_t * to unsigned char *
Serhei Makarov [Thu, 23 Nov 2023 19:53:00 +0000 (14:53 -0500)] 
eu-stacktrace WIP: prefer uint8_t * to unsigned char *

Consistent with sysprof style (via sysprof-capture-types.h).

19 months agoeu-stacktrace WIP: introduce 'naive' unwinder mode, very initial code
Serhei Makarov [Thu, 16 Nov 2023 21:06:03 +0000 (16:06 -0500)] 
eu-stacktrace WIP: introduce 'naive' unwinder mode, very initial code

Still a number of pieces missing:
- recycle Dwfl structs sensibly
- create and output callchain frame
- compare to baseline sysprof unwinding, improve data quality

19 months agoeu-stacktrace WIP: update SysprofCaptureStackUser format
Serhei Makarov [Wed, 8 Nov 2023 15:35:23 +0000 (10:35 -0500)] 
eu-stacktrace WIP: update SysprofCaptureStackUser format

19 months agoeu-stacktrace WIP: add libdw to Makefile.am
Serhei Makarov [Wed, 8 Nov 2023 15:34:27 +0000 (10:34 -0500)] 
eu-stacktrace WIP: add libdw to Makefile.am

21 months agoeu-stacktrace WIP: add SysprofCaptureStackUser declarations
Serhei Makarov [Mon, 2 Oct 2023 18:40:52 +0000 (14:40 -0400)] 
eu-stacktrace WIP: add SysprofCaptureStackUser declarations

Adding these declarations as a fallback saves some fuss, since
eu-stacktrace can then be built with distro-provided sysprof-4
headers.

21 months agoeu-stacktrace WIP: fix header for sysprof packet parser
Serhei Makarov [Mon, 2 Oct 2023 18:39:50 +0000 (14:39 -0400)] 
eu-stacktrace WIP: fix header for sysprof packet parser

(the separate skip_frame and peek_frame functions are not being used)

21 months agoeu-stacktrace WIP: sysprof packet parser for passthrough
Serhei Makarov [Sun, 3 Sep 2023 20:49:29 +0000 (16:49 -0400)] 
eu-stacktrace WIP: sysprof packet parser for passthrough

Separate and byte-swap the packets as done by sysprof-capture-reader.

2 years agoREADME.eu-stacktrace: add link to discussion thread
Serhei Makarov [Mon, 8 May 2023 13:58:41 +0000 (09:58 -0400)] 
README.eu-stacktrace: add link to discussion thread

Also fixed a number of incorrectly named PERF_EVENT_* constants.

2 years agoREADME.eu-stacktrace: fix typo in prev commit
Serhei Makarov [Wed, 3 May 2023 18:37:50 +0000 (14:37 -0400)] 
README.eu-stacktrace: fix typo in prev commit

Updated example usage:
- mkfifo /tmp/test.fifo
- eu-stacktrace </tmp/test.fifo >test.syscap &
- sysprof-cli --use-fifo=/tmp/test.fifo test.syscap

2 years agoeu-stacktrace WIP: default stdin/stdout ("-") for --input/--output
Serhei Makarov [Wed, 3 May 2023 18:32:30 +0000 (14:32 -0400)] 
eu-stacktrace WIP: default stdin/stdout ("-") for --input/--output

Updated example usage:
- mkfifo /tmp/test.fifo
- eu-stacktrace </tmp/test.fifo >output=test.syscap &
- sysprof-cli --use-fifo=/tmp/test.fifo test.syscap

2 years agoREADME.eu-stacktrace: update for passthrough pipe demo
Serhei Makarov [Wed, 3 May 2023 12:14:00 +0000 (08:14 -0400)] 
README.eu-stacktrace: update for passthrough pipe demo

2 years agoeu-stacktrace WIP: simple passthrough for sysprof
Serhei Makarov [Tue, 2 May 2023 20:01:41 +0000 (16:01 -0400)] 
eu-stacktrace WIP: simple passthrough for sysprof

Works with the sysprof serhei/samples-via-fifo patchset [1].

Example usage:
- mkfifo /tmp/test.fifo
- eu-stacktrace --input=/tmp/test.fifo --output=test.syscap &
- sysprof-cli --use-fifo=/tmp/test.fifo test.syscap

[1]: https://git.sr.ht/~serhei/sysprof-experiments/log/serhei/samples-via-fifo

2 years agoeu-stacktrace WIP: include sysprof-capture-types.h
Serhei Makarov [Mon, 3 Apr 2023 19:49:07 +0000 (15:49 -0400)] 
eu-stacktrace WIP: include sysprof-capture-types.h

This header defines the Sysprof data format; we could make it optional
through configury, but for now the prototype does not support any other
data format.

2 years agoeu-stacktrace WIP: command line args
Serhei Makarov [Mon, 3 Apr 2023 15:10:44 +0000 (11:10 -0400)] 
eu-stacktrace WIP: command line args

eu-stacktrace is (will be) a utility to process a stream of stack
samples (such as those obtained from PERF_EVENT_SAMPLE) into a stream
of stack traces (such as those obtained from PERF_EVENT_CALLCHAIN),
freeing various profiling utilities from having to implement their own
backtracing logic.

2 years agoLoongArch: implemented a basic machine flag check
Alexey Sheplyakov [Mon, 20 Mar 2023 14:45:02 +0000 (18:45 +0400)] 
LoongArch: implemented a basic machine flag check

With this patch I can use eu-elflint to verify LoongArch ELF
binaries. Previously eu-elflint was complaining about invalid
machine flags:

$ ./src/elflint --gnu-ld ./src/elflint
invalid machine flags: 0x43
$ echo $?
1

    * backends/loongarch_symbol.c (loongarch_init): Hook
    machine_flag_check.
    * backends/loongarch_symbol.c (loongarch_machine_flag_check):
    New function.

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

Signed-off-by: Alexey Sheplyakov <asheplyakov@basealt.ru>
2 years agodebuginfod-client.c: Skip empty file creation for cancelled queries
Aaron Merey [Fri, 17 Mar 2023 15:20:50 +0000 (11:20 -0400)] 
debuginfod-client.c: Skip empty file creation for cancelled queries

Empty files in the client cache are used to indicate that contacted
servers could not find a requested resource.  Future queries for this
resource will not be attempted until the cache_miss_s duration has
passed.

Currently these empty files are also created when a query is cancelled
through the client's progressfn.  This can occur, for example, when a
user cancels a download with ctrl-c.

This prevents user-cancelled queries from being retried promptly without
having to modify cache_miss_s.  Fix this by skipping the creation of an
empty cache file when progressfn cancels a query.

Signed-off-by: Aaron Merey <amerey@redhat.com>
2 years agotests: skip '(null)' symname frames in backtrace tests
Mark Wielaard [Sat, 4 Mar 2023 20:55:56 +0000 (21:55 +0100)] 
tests: skip '(null)' symname frames in backtrace tests

Some setups might have some frames for unknown (null) functions
in the thread backtrace. Skip these frames instead of failing
immediately.

    * tests/backtrace.c (callback_verify): Check and skip nulls_seen.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoconfigure.ac contains Bashisms
Mark Wielaard [Sun, 5 Mar 2023 12:09:34 +0000 (13:09 +0100)] 
configure.ac contains Bashisms

Autoconf scripts are supposed to be written in POSIX-compatible shell
language. elfutils commits 0ffe2874e75d48cb88936e119e5284ff2bf664d9
and 3fa98a6f29b0f370e32549ead7eb897c839af980 introduced Bashisms to
configure.ac that cause errors when /bin/sh is not Bash.

Example error when /bin/sh is Dash:

./configure: 8748: test: xyes: unexpected operator

The cause of the error is the use of a non-existent == operator in
expressions passed to the 'test' built-in command. POSIX shell
specifies only an = operator for testing string equality.

  * configure.ac: Replace == by = in use_msan and enable_demangler
  comparisons.

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

Reported-by: Matt Whitlock <sourceware@mattwhitlock.name>
Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoFix static build when zstd is enabled for libelf
Mark Wielaard [Fri, 3 Mar 2023 16:10:30 +0000 (17:10 +0100)] 
Fix static build when zstd is enabled for libelf

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 <mark@klomp.org>
2 years agoPrepare for 0.189 elfutils-0.189
Mark Wielaard [Fri, 3 Mar 2023 15:13:52 +0000 (16:13 +0100)] 
Prepare for 0.189

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 <mark@klomp.org>
2 years agolibelf: Document and make ELFCOMPRESS_ZSTD usable with old system elf.h
Mark Wielaard [Fri, 3 Mar 2023 14:37:18 +0000 (15:37 +0100)] 
libelf: Document and make ELFCOMPRESS_ZSTD usable with old system elf.h

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 <mark@klomp.org>
2 years agoreadelf: Fix use-after-free ebl pointer issue
Mark Wielaard [Fri, 3 Mar 2023 13:13:49 +0000 (14:13 +0100)] 
readelf: Fix use-after-free ebl pointer issue

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 <mark@klomp.org>
2 years agolibdw: Fix dwarf_getscopes memory leak on error
Mark Wielaard [Wed, 22 Feb 2023 22:34:00 +0000 (23:34 +0100)] 
libdw: Fix dwarf_getscopes memory leak on error

When there is an error in dwarf_getscopes after the initial scopes
have been allocated, e.g. when looking for the inlined scopes, then
the scopes would leak. Fix this by explicitly free the scopes on error.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibcpu: Remove the need of NMNES by using enum
Yonggang Luo [Sat, 17 Dec 2022 16:52:02 +0000 (00:52 +0800)] 
libcpu: Remove the need of NMNES by using enum

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibdw: Use elf_rawdata when checking .debug section
Mark Wielaard [Mon, 20 Feb 2023 15:42:56 +0000 (16:42 +0100)] 
libdw: Use elf_rawdata when checking .debug section

.debug sections are raw bytes and don't need conversion even when host
and file have different endian order.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibelf: memmove any extra bytes left by elf_cvt_gnuhash conversion
Mark Wielaard [Mon, 20 Feb 2023 15:32:57 +0000 (16:32 +0100)] 
libelf: memmove any extra bytes left by elf_cvt_gnuhash conversion

Otherwise some undefined bytes might be left in the buffer. Now they
might still be not useful, but at least they are as defined in the
file.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoNEWS: Add old version code names
Mark Wielaard [Thu, 23 Feb 2023 09:42:15 +0000 (10:42 +0100)] 
NEWS: Add old version code names

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoUpdate m4 files from autoconf-archive
Mark Wielaard [Tue, 21 Feb 2023 21:27:59 +0000 (22:27 +0100)] 
Update m4 files from autoconf-archive

Update m4/ax_check_compile_flag.m4 and m4/ax_cxx_compile_stdcxx.m4
to autoconf-archive-2023.02.20.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoconfigure: Check for and -Wuse-after-free=3 when available
Mark Wielaard [Tue, 21 Feb 2023 12:12:38 +0000 (13:12 +0100)] 
configure: Check for and -Wuse-after-free=3 when available

gcc already includes -Wuse-after-free=2 in -Wall. -Wuse-after-free=3
also warns for indeterminate pointers in equality expressions.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibasm: Fix use-after-free issue with circular single linked list cleanup
Mark Wielaard [Fri, 17 Feb 2023 13:52:04 +0000 (14:52 +0100)] 
libasm: Fix use-after-free issue with circular single linked list cleanup

Pointed out by gcc 12 with -Wuse-after-free=3

In function ‘free_section’
asm_end.c:552:17: error: pointer ‘data’ used after ‘free’ [-Werror=use-after-free]
  552 |     while (oldp != scnp->content);
      |            ~~~~~^~~~~~~~~~~~~~~~
asm_end.c:550:9: note: call to ‘free’ here
  550 |         free (oldp);
      |         ^~~~~~~~~~~

Fix by freeing scnp->content last.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoNEWS: Mention linking with libstdc++ or using --disable-demangler
Mark Wielaard [Fri, 17 Feb 2023 20:17:10 +0000 (21:17 +0100)] 
NEWS: Mention linking with libstdc++ or using --disable-demangler

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibdw: check that DWARF strings are null-terminated
Aleksei Vetrov [Tue, 14 Feb 2023 20:30:02 +0000 (20:30 +0000)] 
libdw: check that DWARF strings are null-terminated

It is expected from libdw to return strings that are null-terminated to
avoid overflowing ELF data.

* Add calculation of a safe prefix inside string sections, where any
  string will be null-terminated.

* Check if offset overflows the safe prefix in dwarf_formstring.

Signed-off-by: Aleksei Vetrov <vvvvvv@google.com>
2 years agoconfigure: Error when demangler is enabled, but libstdc++ support isn't
Mark Wielaard [Wed, 15 Feb 2023 16:00:30 +0000 (17:00 +0100)] 
configure: Error when demangler is enabled, but libstdc++ support isn't

There have been a couple of cases where demangler support has been
accidentially been disabled because libstdc++ wasn't there/installed
during build. Make it an error if --disable-demangler isn't explicitly
given.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agodoc: Add .TP before -g in debuginfod.8
Mark Wielaard [Tue, 14 Feb 2023 20:03:38 +0000 (21:03 +0100)] 
doc: Add .TP before -g in debuginfod.8

Fixes indentation of -g option.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibdw: Correct data end checkfor deref_type operand in dwarf_getlocation
Mark Wielaard [Tue, 14 Feb 2023 19:24:30 +0000 (20:24 +0100)] 
libdw: Correct data end checkfor deref_type operand in dwarf_getlocation

In __libdw_intern_expression we checked for one byte too many.
We only need one byte for the size and (at least one) for the uleb128
DIE reference.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibdw: Handle DW_OP_GNU_uninit in dwarf_getlocation
Mark Wielaard [Fri, 10 Feb 2023 12:56:58 +0000 (13:56 +0100)] 
libdw: Handle DW_OP_GNU_uninit in dwarf_getlocation

dwarf_getlocation would return an error when it saw a
DW_OP_GNU_uninit. Handle it by simply recognizing as a no argument
operation.

DW_OP_GNU_uninit is emitted by GCC as a marker to flag the location
expression as referring to an uninitialized value.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibdw, readelf, elflint: Add get_(u|s)leb128 guards
Mark Wielaard [Wed, 8 Feb 2023 15:53:24 +0000 (16:53 +0100)] 
libdw, readelf, elflint: Add get_(u|s)leb128 guards

Add sanity check making sure an leb128 isn't being read beyond the
end of the current data segment. Most code already had these guards,
but some were missing. This makes sure an appropriate error is
generated instead.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibdw: check memory access in get_(u|s)leb128
Aleksei Vetrov [Mon, 13 Feb 2023 20:10:05 +0000 (20:10 +0000)] 
libdw: check memory access in get_(u|s)leb128

__libdw_get_uleb128 and __libdw_get_sleb128 should check if addrp has
already reached the end before unrolling the first step. It is done by
moving __libdw_max_len to the beginning of the function, which can
notice, that addrp is beyond the end. Then we just check the result of
this function.

Signed-off-by: Aleksei Vetrov <vvvvvv@google.com>
2 years agobackends: Handle DW_TAG_unspecified_type in dwarf_peeled_die_type
Mark Wielaard [Thu, 26 Jan 2023 17:19:15 +0000 (18:19 +0100)] 
backends: Handle DW_TAG_unspecified_type in dwarf_peeled_die_type

binutils 2.40 introduces DW_TAG_unspecified_type for assembly
functions with an unknown return type. This breaks the
run-funcretval.sh testcase because dwfl_module_return_value_location
returns an error for such functions because it cannot determine the
return value location. Fix that by treating DW_TAG_unspecified_type
as if the DIE doesn't have a DW_AT_type.

Also update the testcase to explicitly checking for
DW_TAG_unspecified_type and printing "returns unspecified type".

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoconfigure: Add --enable-sanitize-memory
Ilya Leoshkevich [Mon, 13 Feb 2023 16:45:51 +0000 (17:45 +0100)] 
configure: Add --enable-sanitize-memory

Add support for clang Memory Sanitizer [1], which detects the usage of
uninitialized values. While elfutils itself is already checked with
valgrind, checking code that depends on elfutils requires elfutils to
be built with MSan.

MSan is not linked into shared libraries, and is linked into
executables statically. Therefore, unlike the other sanitizers, MSan
needs to be configured fairly early, since we need to drop
-D_FORTIFY_SOURCE [2], -Wl,-z,defs and --no-undefined.

Disable a few tests that run for more than 5 minutes due to test files
being statically linked with MSan.

[1] https://clang.llvm.org/docs/MemorySanitizer.html
[2] https://github.com/google/sanitizers/issues/247

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
2 years agobackends: Support returning lvalue and rvalue references
Ilya Leoshkevich [Mon, 13 Feb 2023 16:45:50 +0000 (17:45 +0100)] 
backends: Support returning lvalue and rvalue references

On the low level, they are the same as pointers. The change needs to be
done for all backends, so define a function and a macro to avoid
repetition. Also add a native test, which has to be implemented in C++.
Add the configure check for it.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
2 years agoprintversion: Fix unused variable
Ilya Leoshkevich [Mon, 13 Feb 2023 16:45:49 +0000 (17:45 +0100)] 
printversion: Fix unused variable

clang complains:

    debuginfod.cxx:354:1: error: unused variable 'apba__' [-Werror,-Wunused-const-variable]
    ARGP_PROGRAM_BUG_ADDRESS_DEF = PACKAGE_BUGREPORT;
    ^
    ../lib/printversion.h:47:21: note: expanded from macro 'ARGP_PROGRAM_BUG_ADDRESS_DEF'
      const char *const apba__ __asm ("argp_program_bug_address")
                        ^

The default linkage for consts in C++ is internal, so declare them
extern. While at it, remove the debuginfod workaround for
argp_program_version_hook.

Co-developed-by: Mark Wielaard <mark@klomp.org>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
2 years agotests: Ignore dwfl-report-offline-memory
Ilya Leoshkevich [Mon, 13 Feb 2023 16:45:48 +0000 (17:45 +0100)] 
tests: Ignore dwfl-report-offline-memory

It's showing up in git status when configuring in the source directory.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
2 years agoconfigure: Add --disable-demangler
Ilya Leoshkevich [Wed, 8 Feb 2023 19:52:25 +0000 (20:52 +0100)] 
configure: Add --disable-demangler

__cxa_demangle is normally implemented in the C++ runtime library,
instrumenting which for MSan is a hassle. Add a knob for disbling it.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
2 years agoconfigure: Use -fno-addrsig if possible
Ilya Leoshkevich [Wed, 8 Feb 2023 19:52:24 +0000 (20:52 +0100)] 
configure: Use -fno-addrsig if possible

By default, clang produces .llvm_addrsig sections [1]. The GNU
toolchain does not know how to handle them yet [2], so just ask clang
not to generate them for the time being.

[1] https://llvm.org/docs/Extensions.html#sht-llvm-addrsig-section-address-significance-table
[2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105625

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
2 years agoreadelf: Fix set but not used parameter
Ilya Leoshkevich [Wed, 8 Feb 2023 19:52:22 +0000 (20:52 +0100)] 
readelf: Fix set but not used parameter

clang complains:

    readelf.c:12205:72: error: parameter 'desc' set but not used [-Werror,-Wunused-but-set-parameter]
    handle_bit_registers (const Ebl_Register_Location *regloc, const void *desc,
                                                                           ^

Mark Wielaard says:

    It is never really used since as far as I can see we don't have any
    backend with a core register sets where a register doesn't have a
    number of bits which isn't a multiple of 8 (only ia64 has some 1
    bit registers, but those don't seem part of the core register set).

    If we do accidentally try to handle such a register having an abort
    is also not very nice. Lets just warn and return/continue.

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

Co-developed-by: Mark Wielaard <mark@klomp.org>
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
2 years agolibasm: Fix xdefault_pattern initialization
Ilya Leoshkevich [Wed, 8 Feb 2023 19:52:20 +0000 (20:52 +0100)] 
libasm: Fix xdefault_pattern initialization

clang complains:

    asm_newscn.c:48:22: error: field 'pattern' with variable sized type 'struct FillPattern' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end]
      struct FillPattern pattern;
                         ^

Fix by using a union instead. Define the second union member to be a
char array 1 byte larger than struct FillPattern. This should be legal
according to 6.7.9:

    If an object that has static or thread storage duration is not
    initialized explicitly, then ... if it is a union, the first named
    member is initialized (recursively) according to these rules, and
    any padding is initialized to zero bits.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
2 years agoaddr2line: Do not test demangling in run-addr2line-i-test.sh
Ilya Leoshkevich [Mon, 6 Feb 2023 22:25:09 +0000 (23:25 +0100)] 
addr2line: Do not test demangling in run-addr2line-i-test.sh

There is run-addr2line-i-demangle-test.sh for that.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
2 years agoInitialize reglocs for VMCOREINFO
Ilya Leoshkevich [Mon, 6 Feb 2023 22:25:08 +0000 (23:25 +0100)] 
Initialize reglocs for VMCOREINFO

MSan complains:

    Uninitialized value was created by an allocation of 'reglocs' in the stack frame
       #0 0x562d35c686f0 in handle_core_note elfutils/src/readelf.c:12674:3
       #const Ebl_Register_Location *reglocs;
    ==1006199==WARNING: MemorySanitizer: use-of-uninitialized-value
       #0 0x562d35c68a2a in handle_core_note elfutils/src/readelf.c:12692:11
       #colno = handle_core_registers (ebl, ebl->elf, desc + regs_offset,
       #                               reglocs, nregloc);

Strictly speaking, this is not a problem, because nregloc == 0, but for
other note types we initialize it anyway, so do it here as well.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
2 years agoreadelf: Fix set but not used variable
Ilya Leoshkevich [Mon, 6 Feb 2023 22:25:07 +0000 (23:25 +0100)] 
readelf: Fix set but not used variable

clang complains:

    readelf.c:10250:10: error: variable 'nculist' set but not used [-Werror,-Wunused-but-set-variable]
      size_t nculist = 0;
             ^

Fix by deleting it.

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
2 years agodebuginfod-client.c: Download section even if cached executable didn't contain it.
Aaron Merey [Wed, 8 Feb 2023 02:15:33 +0000 (21:15 -0500)] 
debuginfod-client.c: Download section even if cached executable didn't contain it.

Before attempting to download a section, cache_find_section tries to
extract the section from existing files in the cache. If it's determined
that the section must not exist, cache_find_section returns -ENOENT to
indicate that the download should be skipped.

This patch fixes a bug where cache_find_section returns -ENOENT even
though the section exists.  If the cache contains the executable but
not the debuginfo with the given build-id and the section only exists
in the debuginfo (such as any of the .debug_* sections), then
debuginfod_find_section returns -ENOENT even if the section could be
downloaded.

Fix this by having cache_find_section not return -ENOENT unless cached
debuginfo was able to be read.

Signed-off-by: Aaron Merey <amerey@redhat.com>
2 years agodebuginfod: Make sure there is only one typedef for debuginfod_client
Mark Wielaard [Mon, 6 Feb 2023 09:21:58 +0000 (10:21 +0100)] 
debuginfod: Make sure there is only one typedef for debuginfod_client

Both debuginfod.h and libdwfl.h have a simple typedef for struct
debuginfod_client. Some compilers pedantically warn when including
both headers that such typedefs are only officially supported in
C11. So guard them with _ELFUTILS_DEBUGINFOD_CLIENT_TYPEDEF to
make them happy.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agotests: Check ELFUTILS_DISABLE_DEMANGLE in run-addr2line-C-test.sh
Mark Wielaard [Fri, 3 Feb 2023 12:44:17 +0000 (13:44 +0100)] 
tests: Check ELFUTILS_DISABLE_DEMANGLE in run-addr2line-C-test.sh

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibdw: Search for abstract origin in the correct CU
Mark Wielaard [Sat, 21 Jan 2023 23:31:57 +0000 (00:31 +0100)] 
libdw: Search for abstract origin in the correct CU

With gcc -flto the abstract origin of an inlined subroutine
could be in a different CU. dwarf_getscopes might return an
empty scope if it cannot find the abstract origin scope. So
make sure to search in the

We also tried to add the origin match in pc_record directly
in the current inlined scope. This always failed, causing
to do a needless traversal, followed by the full CU scan in
dwarf_getscopes. Just always stop the pc_record search and
then do the CU origin_match in dwarf_getscopes.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoaddr2line: -C should not try to handle optional (ignored) argument
Mark Wielaard [Sun, 22 Jan 2023 19:50:53 +0000 (20:50 +0100)] 
addr2line: -C should not try to handle optional (ignored) argument

The --demangle option takes an option (ignored) argument. Since -C
is the short option of --demangle it also takes that optional
argument. But that means that something like -Cfi is like -C got
fi as argument, while the user expects -Cfi to be like -C -f -i.

Separate the --demangle and -C options. --demangle still takes
an optional (ignored) argument, but -C doesn't take any arguments
so -Cfi acts the same as -fiC.

Also fix --target, -b, so that it is properly ignored (and not
accidentially enables demangling).

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agolibdwfl: add check for elf_memory return value
Aleksei Vetrov [Wed, 25 Jan 2023 14:16:57 +0000 (14:16 +0000)] 
libdwfl: add check for elf_memory return value

elf_memory call in __libdw_open_elf_memory can return NULL. It was not
checked and led to the null pointer dereference.

Signed-off-by: Aleksei Vetrov <vvvvvv@google.com>
2 years agotests: run-debuginfod-query-retry.sh /bin/sh might not have a build-id
Mark Wielaard [Thu, 19 Jan 2023 22:53:33 +0000 (23:53 +0100)] 
tests: run-debuginfod-query-retry.sh /bin/sh might not have a build-id

If /bin/sh wasn't build with build-id the test fails because
debuginfod-find will not be able to even try to fetch something.
Use libdebuginfod.so.1 instead as test file because we just
build that and configure makes sure we always produce a build-id.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agobackends: sparc uses NONE relocation type in ET_EXEC and ET_DYN files
Mark Wielaard [Thu, 19 Jan 2023 22:04:04 +0000 (23:04 +0100)] 
backends: sparc uses NONE relocation type in ET_EXEC and ET_DYN files

Using the NONE relocation doesn't do anything, but is harmless.

This fixes several (self) tests on sparc that use elflint to
check files are valid ELF.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoreadelf: Check compression status of .debug section data
Mark Wielaard [Tue, 10 Jan 2023 17:18:05 +0000 (18:18 +0100)] 
readelf: Check compression status of .debug section data

The various print_debug_*_section functions didn't get the section
data in the same way. Add a new get_debug_elf_data function that
gets the (possibly relocated) section data and that checks (and
warns) if the data might still be compressed in a way that we
cannot decompress.

Signed-off-by: Mark Wielaard <mark@klomp.org>
2 years agoFix typos from codespell
Sam James [Fri, 13 Jan 2023 22:16:07 +0000 (22:16 +0000)] 
Fix typos from codespell

debuginfod/ChangeLog:

* debuginfod-client.c: Typo simultaniously.

doc/ChangeLog:

* debuginfod.8: Typo succesfully.

lib/ChangeLog:

* dynamicsizehash_concurrent.c: Typo modul.
* system.h: Typo dependend.

libdwfl/ChangeLog:

* open.c: Typo non-existant.

src/ChangeLog:

* nm.c: Typo Covert.
* strings.c: Likewise.

tests/ChangeLog:

* elfstrmerge.c: Typo outselves.
* run-debuginfod-extraction.sh: Typo accidentially.
* run-debuginfod-fd-prefetch-caches.sh: Likewise.

Signed-off-by: Sam James <sam@gentoo.org>
2 years agodebuginfod-find.1: note on how to find a comp_dir
Serhei Makarov [Tue, 10 Jan 2023 16:20:13 +0000 (11:20 -0500)] 
debuginfod-find.1: note on how to find a comp_dir

doc/ChangeLog:

* debuginfod-find.1: add a note to DESCRIPTION section for the 'source'
  subcommand, clarifying where to find the CU compilation-directory.

I'm looking at how to improve and document the workflow for using
debuginfod-find to study the behaviour of packaged software on a system, e.g.
in conjunction with a tracing tool like SystemTap. You can read the exact
compiled source code with debuginfod-find source and use that to figure out
which source code locations are interesting to trace. But that process has
several non-obvious or inconvenient steps.

This patch is a clarification to the debuginfod-find source man page pointing
out the eu-readelf command that can show the comp_dir in downloaded debuginfo.
Since debuginfod-find source could be picked up and used by a developer
unfamiliar with DWARF terminology, I think such a clarification saves time
for newbies figuring out what a CU compilation-directory is.

Signed-off-by: Serhei Makarov <serhei@serhei.io>
2 years agodebuginfod PR29975 & PR29976: decrease default concurrency
Frank Ch. Eigler [Tue, 10 Jan 2023 22:59:35 +0000 (17:59 -0500)] 
debuginfod PR29975 & PR29976: decrease default concurrency

... based on rlimit (rlimig -n NUM)
... based on cpu-affinity (taskset -c A,B,C,D ...)

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>