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.
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.
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>
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>
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.
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.
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:
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>
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).
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
* 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.
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.
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
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.
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'.
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.
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.
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.
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.
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.
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.
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.
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.
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>
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.
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.
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.
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.
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.
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.
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.
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>
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>
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.
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.
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.
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
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.
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.
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.