platform/upstream/elfutils.git
3 years agoarlib-argp: Pull text_for_default() into file scope
Timm Bäder [Fri, 8 Jan 2021 08:13:28 +0000 (09:13 +0100)]
arlib-argp: Pull text_for_default() into file scope

Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agozstrptr: Pull print_string() into file scope
Timm Bäder [Fri, 8 Jan 2021 08:13:26 +0000 (09:13 +0100)]
zstrptr: Pull print_string() into file scope

Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agoaddr2line: Pull show_note() and show_int() in file scope
Timm Bäder [Fri, 8 Jan 2021 08:13:25 +0000 (09:13 +0100)]
addr2line: Pull show_note() and show_int() in file scope

Get rid of the nested functions

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agoelf-from-memory: Refactor to get rid of nested function
Timm Bäder [Fri, 8 Jan 2021 08:09:56 +0000 (09:09 +0100)]
elf-from-memory: Refactor to get rid of nested function

Try to unify the 32/64 bit code paths and get rid of the nested
handle_segment() this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agoelf-from-memory: Restructure code to get rid of nested handle_segment()
Timm Bäder [Fri, 8 Jan 2021 08:09:55 +0000 (09:09 +0100)]
elf-from-memory: Restructure code to get rid of nested handle_segment()

Use one loop for both 32 and 64  bit case. This allows for only one call
site of the old handle_segment(), which we can then inline into the for
loop.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agostrip: Remove no_symtab_updates() function
Timm Bäder [Fri, 8 Jan 2021 08:04:49 +0000 (09:04 +0100)]
strip: Remove no_symtab_updates() function

The no_symtab_updates() function was being called at the beginning of
all case labels in this switch, so we can just call it once before the
switch. Then it only has one call-site, so inline this short function
there.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agostrip: Pull update_section_size() into file scope
Timm Bäder [Fri, 8 Jan 2021 08:04:48 +0000 (09:04 +0100)]
strip: Pull update_section_size() into file scope

Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agostrip: Pull relocate() info file scope
Timm Bäder [Fri, 8 Jan 2021 08:04:47 +0000 (09:04 +0100)]
strip: Pull relocate() info file scope

Pull relocate() info file scope and get rid of a nested function this
way. Refactor remove_debug_relocations() to minimize the parameters we
need to pass to relocate().

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agostrip: Replace nested check_preserved function with loop
Timm Bäder [Fri, 8 Jan 2021 08:04:46 +0000 (09:04 +0100)]
strip: Replace nested check_preserved function with loop

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agoelflint: Recognize SHF_GNU_RETAIN as extra section flag.
Mark Wielaard [Tue, 12 Jan 2021 10:35:10 +0000 (11:35 +0100)]
elflint: Recognize SHF_GNU_RETAIN as extra section flag.

SHF_GNU_RETAIN is like SHF_LINK_ORDER it can appear on any section
and should be ignored by elflint. Add all such flags to a new
EXTRA_SHFLAGS and use it consistently in check_sections.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agoAdd coverage target
Dmitry V. Levin [Tue, 12 Jan 2021 08:00:00 +0000 (08:00 +0000)]
Add coverage target

Implement a target for capturing code coverage using lcov.
It is available when elfutils is configured using --enable-gcov.

Tested with
autoreconf -if && ./configure --enable-maintainer-mode --enable-gcov &&
make && make check && make coverage

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agosrc/elflint.c: add debug print for GNU_RETAIN and others
Sergei Trofimovich [Thu, 31 Dec 2020 12:11:34 +0000 (12:11 +0000)]
src/elflint.c: add debug print for GNU_RETAIN and others

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agosrc/elflint.c: fix printing of unknown flags
Sergei Trofimovich [Thu, 31 Dec 2020 12:11:42 +0000 (12:11 +0000)]
src/elflint.c: fix printing of unknown flags

before the change section_flags_string() ignored unknown section
flags: snprintf() did write numeric value into buffer, but
"*cp = '\0'" negated the effect.

The change advances the 'cp' pointer'.

While at it add a '|' separator between known and unknown flags.

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
3 years agosrc/readelf: use qsort instead of qsort_r.
Érico Rolim [Wed, 16 Dec 2020 22:30:12 +0000 (19:30 -0300)]
src/readelf: use qsort instead of qsort_r.

This program is single threaded, so using qsort with a global variable
isn't a danger. The interface for qsort_r isn't standardized (and
diverges between glibc and FreeBSD, for example), which makes usage of
qsort, where possible, preferrable.

Signed-off-by: Érico Rolim <erico.erc@gmail.com>
3 years agoSplit the top level .gitignore file
Dmitry V. Levin [Sun, 20 Dec 2020 08:00:00 +0000 (08:00 +0000)]
Split the top level .gitignore file

Move subdirectory parts of the top level .gitignore into appropriate
subdirectories.  This would be consistent with ChangeLog files,
currently one has to update the top level ChangeLog file when
the top level .gitignore file is changed in a way that affects
a specific subdirectory only.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years ago.gitignore: update
Dmitry V. Levin [Sun, 20 Dec 2020 08:00:00 +0000 (08:00 +0000)]
.gitignore: update

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agolibcpu: linking i386_gendis requires obstack.
Érico Rolim [Wed, 16 Dec 2020 18:56:14 +0000 (15:56 -0300)]
libcpu: linking i386_gendis requires obstack.

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agoHandle SHF_GNU_RETAIN in eu-readelf and eu-elflint.
Mark Wielaard [Sat, 12 Dec 2020 22:36:15 +0000 (23:36 +0100)]
Handle SHF_GNU_RETAIN in eu-readelf and eu-elflint.

readelf -S now shows 'R' when SHF_GNU_RETAIN is set.
elflint accepts SHF_GNU_RETAIN when set on section in --gnu mode.

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agolibelf: Sync elf.h from glibc.
Mark Wielaard [Sat, 12 Dec 2020 19:48:40 +0000 (20:48 +0100)]
libelf: Sync elf.h from glibc.

Adds SHF_GNU_RETAIN.

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agoModernize gettext infrastructure
Dmitry V. Levin [Tue, 15 Dec 2020 08:00:00 +0000 (08:00 +0000)]
Modernize gettext infrastructure

Switch to use AM_GNU_GETTEXT, AM_GNU_GETTEXT_VERSION, and
AM_GNU_GETTEXT_REQUIRE_VERSION, this allows to stop bundling gettext
infrastructure files and let autoreconf invoke autopoint which will set
the gettext infrastructure up.

Use this opportunity to create separate .gitignore files for m4/ and po/
directories.

Tested with
autoreconf -if && ./configure --enable-maintainer-mode && make && make distcheck

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agosrc: consistently use _(Str) instead of gettext(Str)
Dmitry V. Levin [Wed, 16 Dec 2020 08:00:00 +0000 (08:00 +0000)]
src: consistently use _(Str) instead of gettext(Str)

Make use of the _(Str) macro provided by <config.h>.

The change was made automatically using the following command:
$ git grep -l '\<gettext *(' src |xargs sed -i 's/\<gettext *(/_(/g'

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agolibcpu: consistently use _(Str) instead of gettext(Str)
Dmitry V. Levin [Wed, 16 Dec 2020 08:00:00 +0000 (08:00 +0000)]
libcpu: consistently use _(Str) instead of gettext(Str)

eu-config.h defines _(Str) to dgettext ("elfutils", Str) instead of
a simple gettext (Str) for a reason: the library might be indirectly
used by clients that called bindtextdomain with a domain different
from "elfutils".

The change was made automatically using the following command:
$ git grep -l '\<gettext *(' libcpu |xargs sed -i 's/\<gettext *(/_(/g'

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agolib: consistently use _(Str) instead of gettext(Str)
Dmitry V. Levin [Wed, 16 Dec 2020 08:00:00 +0000 (08:00 +0000)]
lib: consistently use _(Str) instead of gettext(Str)

eu-config.h defines _(Str) to dgettext ("elfutils", Str) instead of
a simple gettext (Str) for a reason: the library might be indirectly
used by clients that called bindtextdomain with a domain different
from "elfutils".

The change was made automatically using the following command:
$ git grep -l '\<gettext *(' lib |xargs sed -i 's/\<gettext *(/_(/g'

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agoConsistently define _(Str) using dgettext ("elfutils", Str)
Dmitry V. Levin [Wed, 16 Dec 2020 08:00:00 +0000 (08:00 +0000)]
Consistently define _(Str) using dgettext ("elfutils", Str)

Move the definition of _(Str) macro to lib/eu-config.h which already
provides a definition of N_(Str) macro.  Since lib/eu-config.h is
appended to config.h, it is included into every compilation unit
and therefore both macros are now universally available.

Remove all other definitions of N_(Str) and _(Str) macros from other files
to avoid conflicts and redundancies.

The next step is to replace all uses of gettext(Str) with _(Str).

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agolibebl: consistently use _(Str) instead of gettext(Str)
Dmitry V. Levin [Tue, 15 Dec 2020 08:00:00 +0000 (08:00 +0000)]
libebl: consistently use _(Str) instead of gettext(Str)

libeblP.h defines _(Str) to dgettext ("elfutils", Str) instead of
a simple gettext (Str) for a reason: the library might be indirectly
used by clients that called bindtextdomain with a domain different
from "elfutils".

The change was made automatically using the following command:
$ git grep -l '\<gettext *(' libebl |xargs sed -i 's/\<gettext *(/_(/g'

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agolibelf: Make sure we have at least a full ELF header available.
Mark Wielaard [Wed, 16 Dec 2020 09:57:22 +0000 (10:57 +0100)]
libelf: Make sure we have at least a full ELF header available.

When elf_memory is called we could get a slightly too small image
that doesn't contain a full ELF header (but does contain at least
the e_ident values). Require the full header before even validating
the rest of the ELF header fields.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agoelflint: Always print symbol name (if known) in error messages.
Mark Wielaard [Tue, 15 Dec 2020 20:49:43 +0000 (21:49 +0100)]
elflint: Always print symbol name (if known) in error messages.

Adding the symbol name associated with the symbol index number
makes the error messages a little bit more useful. We used to say:

section [59] '.symtab': symbol 9: st_value out of bounds

But now says:

section [59] '.symtab': symbol 9 (.annobin_size.c.hot): st_value out of bounds

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agopo: remove empty translation files
Dmitry V. Levin [Tue, 15 Dec 2020 20:56:37 +0000 (23:56 +0300)]
po: remove empty translation files

Remove translation files that do not contain any translation strings,
not even a single fuzzy one.  These files are also unused because they
are not listed in the LINGUAS file.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agom4: remove unneeded Makefile.am
Dmitry V. Levin [Tue, 15 Dec 2020 14:40:38 +0000 (17:40 +0300)]
m4: remove unneeded Makefile.am

m4 files do not have to listed in EXTRA_DIST, in fact,
biarch.m4 has not been listed since its very beginning in 2013,
and nobody seems to have noticed so far.

Tested with
autoreconf -if && ./configure --enable-maintainer-mode && make && make distcheck

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agoconfigure.ac: remove unneeded AC_CONFIG_MACRO_DIR([m4])
Dmitry V. Levin [Tue, 15 Dec 2020 14:40:01 +0000 (17:40 +0300)]
configure.ac: remove unneeded AC_CONFIG_MACRO_DIR([m4])

Makefile.am already contains "ACLOCAL_AMFLAGS = -I m4",
that is enough for autoreconf to do the right thing.

Tested with
autoreconf -if && ./configure --enable-maintainer-mode && make && make distcheck

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agoFix spelling typos in NEWS, NOTES, TODO, and in comments of configure.ac
Dmitry V. Levin [Sat, 12 Dec 2020 16:52:49 +0000 (19:52 +0300)]
Fix spelling typos in NEWS, NOTES, TODO, and in comments of configure.ac

accidently -> accidentally
approriate -> appropriate
depencies -> dependencies
endianess -> endianness
funtions -> functions
indeces -> indices
indentified -> identified
ist -> is
mutliple -> multiple
nessesary -> necessary
optimze -> optimize
severly -> severely
suport -> support
tranformation -> transformation

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agotests: fix spelling typos in error diagnostics and comments
Dmitry V. Levin [Sat, 12 Dec 2020 16:52:43 +0000 (19:52 +0300)]
tests: fix spelling typos in error diagnostics and comments

Cannnot -> Cannot
decriptors -> descriptors
experssions -> expressions
explit -> explicit
falg -> flag
irrelevent -> irrelevant
mininum -> minimum
outselves -> ourselves
proces -> process
versio -> version

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agosrc: fix spelling typos in comments and ChangeLog
Dmitry V. Levin [Sat, 12 Dec 2020 16:52:37 +0000 (19:52 +0300)]
src: fix spelling typos in comments and ChangeLog

Indeces -> Indices
adress -> address
affort -> afford
dont' -> don't
futher -> further
higest -> highest
indeces -> indices
interate -> iterate
occured -> occurred
overlow -> overflow
sectin -> section
succesful -> successful
teminated -> terminated

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agolibelf: fix spelling typos in comments
Dmitry V. Levin [Sat, 12 Dec 2020 16:52:26 +0000 (19:52 +0300)]
libelf: fix spelling typos in comments

Auxialiary -> Auxiliary
constucted -> constructed
desriptor -> descriptor
endianess -> endianness
responsibilty -> responsibility
sufficent -> sufficient

elf.h comes from glibc and therefore is excluded.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agolibdwfl: fix spelling typos in comments and ChangeLog
Dmitry V. Levin [Sat, 12 Dec 2020 16:51:24 +0000 (19:51 +0300)]
libdwfl: fix spelling typos in comments and ChangeLog

adresses -> addresses
boundery -> boundary
explictly -> explicitly
fo -> for
layed -> laid
partical -> particular
setion -> section
substract -> subtract
wil -> will

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agolibdwelf: fix spelling typos in comments
Dmitry V. Levin [Sat, 12 Dec 2020 16:51:15 +0000 (19:51 +0300)]
libdwelf: fix spelling typos in comments

algorith -> algorithm
occured -> occurred

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agolibdw: fix spelling typos in comments and ChangeLog
Dmitry V. Levin [Sat, 12 Dec 2020 16:51:08 +0000 (19:51 +0300)]
libdw: fix spelling typos in comments and ChangeLog

Retieve -> Retrieve
apporiate -> appropriate
distinquish -> distinguish
dynamicly -> dynamically
indeces -> indices
lenght -> length
minium -> minimum
occured -> occurred
setion -> section
unknow -> unknown

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agolibcpu: fix spelling typos in comments
Dmitry V. Levin [Sat, 12 Dec 2020 16:50:57 +0000 (19:50 +0300)]
libcpu: fix spelling typos in comments

layed -> laid
adressing -> addressing

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agolibasm: fix spelling typos in comments
Dmitry V. Levin [Sat, 12 Dec 2020 16:50:45 +0000 (19:50 +0300)]
libasm: fix spelling typos in comments

endianess -> endianness
setion -> section

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agoconfig: fix spelling typos in comments and %changelog
Dmitry V. Levin [Sat, 12 Dec 2020 16:50:33 +0000 (19:50 +0300)]
config: fix spelling typos in comments and %changelog

directoy -> directory
fo -> for
funtions -> functions
ist -> is
mutliple -> multiple
priviliges -> privileges
reenable -> re-enable

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agobackends: fix spelling typos in comments
Dmitry V. Levin [Sat, 12 Dec 2020 16:50:20 +0000 (19:50 +0300)]
backends: fix spelling typos in comments

adress -> address
sigle -> single

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agodebuginfod: fix spelling typos in error diagnostics and comments
Dmitry V. Levin [Sat, 12 Dec 2020 16:50:12 +0000 (19:50 +0300)]
debuginfod: fix spelling typos in error diagnostics and comments

Initalize -> Initialize
Unsucessful -> Unsuccessful
expession -> expression
incompatiblity -> incompatibility

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agosrc: fix spelling typos in argp help text and error diagnostics
Dmitry V. Levin [Sat, 12 Dec 2020 01:27:37 +0000 (04:27 +0300)]
src: fix spelling typos in argp help text and error diagnostics

Since all these help text strings are marked for translation, apply the fixes
to translation strings as well, this helps to avoid translations becoming fuzzy.

lenght -> length
occured -> occurred
endianess -> endianness
reversable -> reversible

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agolibdwelf: fix spelling typos in strings returned by dwelf_elf_e_machine_string
Dmitry V. Levin [Sat, 12 Dec 2020 01:06:00 +0000 (04:06 +0300)]
libdwelf: fix spelling typos in strings returned by dwelf_elf_e_machine_string

embeded -> embedded
Semicondutor -> Semiconductor

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agodoc: fix spelling typos
Dmitry V. Levin [Fri, 11 Dec 2020 13:01:55 +0000 (16:01 +0300)]
doc: fix spelling typos

filesytem -> filesystem
requries -> requires
hte -> the
recieve -> receive
varients -> variants
preceeded -> preceded

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agoRemove unused tests/configure.ac
Dmitry V. Levin [Fri, 11 Dec 2020 01:43:35 +0000 (04:43 +0300)]
Remove unused tests/configure.ac

tests/configure.ac was introduced 15 years ago by commit
d7f8d0caa7a357f9f4765e5dc93255f5057eba2e.  However, the ability to build
tests as a separate project was broken by the same author 4 years later
by commit 22359e265395fd2f8267190ef97f5417770e6206, if not earlier.

An attempt to run autoreconf in tests would currently fail
with the following automake error:
automake: error: cannot open < config/eu.am: No such file or directory

Apparently, nobody builds tests as a separate project for more than 10
years, so cleanup the remains of that unused and broken code.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agoconfigure.ac: simplify argp check
Dmitry V. Levin [Fri, 11 Dec 2020 00:59:40 +0000 (03:59 +0300)]
configure.ac: simplify argp check

Rewrite argp check using the same AC_SEARCH_LIBS based method used
earlier in the fts check.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agoconfigure.ac: fix typo in error diagnostics
Dmitry V. Levin [Fri, 11 Dec 2020 00:59:00 +0000 (03:59 +0300)]
configure.ac: fix typo in error diagnostics

Fixes: da855fc9c ("Support building when fts and obstack aren't part of libc")
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agoRemove unused Makefile variable GCC_INCLUDE
Dmitry V. Levin [Fri, 11 Dec 2020 00:27:24 +0000 (03:27 +0300)]
Remove unused Makefile variable GCC_INCLUDE

It appears to be unused since the first commit in the revision history.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agolink_map: Pull read_addrs() into file scope
Timm Bäder [Mon, 7 Dec 2020 11:11:06 +0000 (12:11 +0100)]
link_map: Pull read_addrs() into file scope

Get rid of a nested function this way.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agolink_map: Pull release_buffer() into file scope
Timm Bäder [Mon, 7 Dec 2020 11:11:05 +0000 (12:11 +0100)]
link_map: Pull release_buffer() into file scope

Get rid of a nested function this way. Add a memory_closure struct to
keep the functions clean.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agoFix automake warnings
Dmitry V. Levin [Wed, 9 Dec 2020 23:34:55 +0000 (02:34 +0300)]
Fix automake warnings

Apparently, commit 2f02e81510946a4c8e9157ad0b72d92894b9acd7 that removed
$(EXEEXT) suffix from shared libraries was incomplete: it missed the
fact that some libraries were included into noinst_PROGRAMS, resulting
to the following automake warnings:

libasm/Makefile.am:66: warning: deprecated feature: target 'libasm.so' overrides 'libasm.so$(EXEEXT)'
libdw/Makefile.am:114: warning: deprecated feature: target 'libdw.so' overrides 'libdw.so$(EXEEXT)'
libelf/Makefile.am:116: warning: deprecated feature: target 'libelf.so' overrides 'libelf.so$(EXEEXT)'

Fix this by renaming noinst_PROGRAMS to noinst_DATA and removing no
longer needed lib{asm,dw,elf}_so_SOURCES variables and add lib{asm,dw,elf).so
to CLEANFILES.

Fixes: 2f02e8151094 ("Drop $(EXEEXT) suffix from shared libraries")
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agolibdwfl: switch to DEBUGINFOD_SONAME, remove libdebuginfod.so fallback
Dmitry V. Levin [Wed, 9 Dec 2020 00:13:27 +0000 (03:13 +0300)]
libdwfl: switch to DEBUGINFOD_SONAME, remove libdebuginfod.so fallback

Since DEBUGINFOD_SONAME is as good as ("libdebuginfod-" VERSION ".so")
for dlopen, switch to use the name which is a part of the API.

Given that DEBUGINFOD_SONAME is always available now, remove the no longer
needed fall back to dlopen of "libdebuginfod.so".

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agodebuginfod: create libdebuginfod.so.1 before libdebuginfod.so
Dmitry V. Levin [Wed, 9 Dec 2020 00:13:12 +0000 (03:13 +0300)]
debuginfod: create libdebuginfod.so.1 before libdebuginfod.so

This would allow to switch from "libdebuginfod-" VERSION ".so"
to DEBUGINFOD_SONAME in __libdwfl_debuginfod_init, and to remove the
fall back to dlopen of "libdebuginfod.so" which would no longer be needed.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agodebuginfod: export DEBUGINFOD_SONAME macro in debuginfod.h
Dmitry V. Levin [Wed, 9 Dec 2020 00:12:53 +0000 (03:12 +0300)]
debuginfod: export DEBUGINFOD_SONAME macro in debuginfod.h

Add DEBUGINFOD_SONAME macro to API for use by those of libdebuginfod
clients that would like to dlopen the library in the same way as
__libdwfl_debuginfod_init does.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agolink_map: Inline consider_phdr() into only caller
Timm Bäder [Tue, 1 Dec 2020 08:38:54 +0000 (09:38 +0100)]
link_map: Inline consider_phdr() into only caller

This gets rid of the tested function and is shorter.

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agoDrop $(EXEEXT) suffix from shared libraries
Dmitry V. Levin [Mon, 30 Nov 2020 08:00:00 +0000 (08:00 +0000)]
Drop $(EXEEXT) suffix from shared libraries

According to GNU Automake documentation [1], $(EXEEXT) is the suffix
that should be used for executables, it is not applicable for shared libraries.

[1] https://www.gnu.org/software/automake/manual/html_node/EXEEXT.html

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
3 years agolibdwfl: Use 64bit GElf_Addr instead of size_t to calculate address.
Mark Wielaard [Sun, 29 Nov 2020 00:57:53 +0000 (01:57 +0100)]
libdwfl: Use 64bit GElf_Addr instead of size_t to calculate address.

size_t is too small on 32 bit systems to analyze a 64 bit core file.

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agosegment_report_module: Inline consider_notes() into only caller
Timm Bäder [Thu, 26 Nov 2020 14:10:48 +0000 (15:10 +0100)]
segment_report_module: Inline consider_notes() into only caller

Get rid of a nested function this way.

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agosegment_report_module: Pull read_portion() into file scope
Timm Bäder [Thu, 26 Nov 2020 14:10:47 +0000 (15:10 +0100)]
segment_report_module: Pull read_portion() into file scope

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agosegment_report_module: Pull finish_portion() into file scope
Timm Bäder [Thu, 26 Nov 2020 14:10:46 +0000 (15:10 +0100)]
segment_report_module: Pull finish_portion() into file scope

Use a read_state struct here to minimize the amount of parameters we
pass.

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agodebuginfod: correct prometheus metric typo
Frank Ch. Eigler [Thu, 26 Nov 2020 02:20:27 +0000 (21:20 -0500)]
debuginfod: correct prometheus metric typo

The "-" character is not allowed in a metric label_name, whoops,
so use "_" for one of the new sqlite metrics.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3 years agodebuginfod: use clock_gettime(CLOCK_MONOTONIC) for intervals
Frank Ch. Eigler [Thu, 26 Nov 2020 00:41:03 +0000 (19:41 -0500)]
debuginfod: use clock_gettime(CLOCK_MONOTONIC) for intervals

On Mark's request, use a monotonic clock for metrics/reports related
to time interval measurement.  gettimeofday can jump a bit, which
could distort metrics.  Tests unaffected.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3 years agodebuginfod: sqlite3 metrics
Frank Ch. Eigler [Tue, 24 Nov 2020 00:58:10 +0000 (19:58 -0500)]
debuginfod: sqlite3 metrics

Add metrics for tracking sqlite3 error counts and query performance.

The former looks like a new sibling of the "error_count" family, and
is tested by dd-corrupting a live database file then triggering some
debuginfod activity.

    error_count{sqlite3="file is not a database"} 1

The latter looks like _count/_sum pairs for each type of sqlite
prepared-statement used in the code, and is grep smoke-tested.  They
should assist a sysadmin in tuning db storage.  This example shows a
6.4 ms/operation cost:

    sqlite3_milliseconds_count{step-done="rpm-file-intern"} 318
    sqlite3_milliseconds_sum{reset="rpm-file-intern"} 2033

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3 years agosegment_report_module: Inline consider_phdr() into only caller
Timm Bäder [Mon, 23 Nov 2020 12:27:12 +0000 (13:27 +0100)]
segment_report_module: Inline consider_phdr() into only caller

Get rid of the nested function this way

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agosegment_report_module: Inline consider_dyn() into only caller
Timm Bäder [Mon, 23 Nov 2020 12:27:11 +0000 (13:27 +0100)]
segment_report_module: Inline consider_dyn() into only caller

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agosegment_report_module: Unify d32/d64 loops
Timm Bäder [Mon, 23 Nov 2020 12:27:10 +0000 (13:27 +0100)]
segment_report_module: Unify d32/d64 loops

Just like we did before, use only one loop here and check for 32/64 bit
in the loop body. This way we only have one call site for consider_dyn

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agosegment_report_module: Inline read_phdr() into only caller
Timm Bäder [Mon, 23 Nov 2020 12:27:09 +0000 (13:27 +0100)]
segment_report_module: Inline read_phdr() into only caller

There is now only one caller for this nested function, so get rid of it
by just inlining it there.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agosegment_report_module: Use one loop for p32/p64 arrays
Timm Bäder [Mon, 23 Nov 2020 12:27:08 +0000 (13:27 +0100)]
segment_report_module: Use one loop for p32/p64 arrays

Do one loop check for 32/64 bit inside the loop, instead of outside.
This way we have only one call site for the function called in the loop
body.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agosegment_report_module: Get rid of nested final_read() function
Timm Bäder [Mon, 23 Nov 2020 12:27:07 +0000 (13:27 +0100)]
segment_report_module: Get rid of nested final_read() function

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agosegment_report_module: Use a struct for build id information
Timm Bäder [Mon, 23 Nov 2020 12:27:05 +0000 (13:27 +0100)]
segment_report_module: Use a struct for build id information

Keep the three build id fields in a struct. This will be an important
clean up later.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agosegment_report_module: Remove nested release_buffer() function
Timm Bäder [Mon, 23 Nov 2020 12:27:02 +0000 (13:27 +0100)]
segment_report_module: Remove nested release_buffer() function

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agosegment_report_module: Get rid of segment_read()
Timm Bäder [Mon, 23 Nov 2020 12:27:01 +0000 (13:27 +0100)]
segment_report_module: Get rid of segment_read()

Just inline the memory_callback call everywhere segmenty_read was used.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
3 years agodebuginfod-client: Initialize struct handle_data errbuf to the empty string.
Mark Wielaard [Mon, 23 Nov 2020 16:52:02 +0000 (17:52 +0100)]
debuginfod-client: Initialize struct handle_data errbuf to the empty string.

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agodebuginfod-client: Add debuginfod_set_verbose_fd and DEBUGINFOD_VERBOSE
Mark Wielaard [Tue, 10 Nov 2020 23:23:08 +0000 (00:23 +0100)]
debuginfod-client: Add debuginfod_set_verbose_fd and DEBUGINFOD_VERBOSE

Introduce a new function debuginfod_set_verbose_fd which will produce
verbose output on a given file descriptor (STDERR_FILENO if the
environment variable DEBUGINFOD_VERBOSE is set) showing how the search
for a particular client query is going.

Example output:

debuginfod_find_debuginfo 1234567890
server urls "https://debuginfod.elfutils.org/ http://dbgd.usersys.com:3632/"
checking build-id
checking cache dir /home/mark/.cache/debuginfod_client
using timeout 90
init server 0 https://debuginfod.elfutils.org/
url 0 https://debuginfod.elfutils.org/buildid/1234567890/debuginfo
init server 1 http://dbgd.usersys.com:3632/
url 1 http://dbgd.usersys.com:3632/buildid/1234567890/debuginfo
query 2 urls in parallel
server response HTTP response code said error
url 0 The requested URL returned error: 404 Not Found
server response HTTP response code said error
url 1 The requested URL returned error: 404 Not Found
not found No such file or directory (err=-2)

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agodebuginfod: Handle "/" and report unrecognized operations
Mark Wielaard [Sat, 21 Nov 2020 19:20:50 +0000 (20:20 +0100)]
debuginfod: Handle "/" and report unrecognized operations

This doesn't change any functionality, but simply shows something a little
user friendlier when accessing the server "by hand" (in a browser).

Signed-off-by: Mark Wielaard <mark@klomp.org>
3 years agodebuginfod: add thread-busy metrics to webapi service
Frank Ch. Eigler [Thu, 19 Nov 2020 18:16:10 +0000 (13:16 -0500)]
debuginfod: add thread-busy metrics to webapi service

Improve monitoring of debuginfod instances by tracking thread_busy
status for the threads responding to http requests.  While these are
usually short-lived, longer archive-uncompress operations can take
long enough time to show up on top/uptime.  This should also assist
noticing abusive clients and guide scaling of the service.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
3 years agoIBM Z: Fix endianess problem in pid_memory_read
Andreas Krebbel [Thu, 19 Nov 2020 19:32:24 +0000 (20:32 +0100)]
IBM Z: Fix endianess problem in pid_memory_read

The cached reads lack the big endian adjustments done in the fallback
path.

Signed-off-by: Andreas Krebbel <krebbel@linux.ibm.com>
4 years agosegment_report_module: Remove nested finish() function
Timm Bäder [Thu, 12 Nov 2020 15:04:01 +0000 (16:04 +0100)]
segment_report_module: Remove nested finish() function

This works just as well with a goto-out style label.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
4 years agosegment_report_module: Get rid of variable-length arrays
Timm Bäder [Thu, 12 Nov 2020 15:03:59 +0000 (16:03 +0100)]
segment_report_module: Get rid of variable-length arrays

This prevents a jump which is needed in a later patch.

Signed-off-by: Timm Bäder <tbaeder@redhat.com>
4 years agobackends: Handle SHT_X86_64_UNWIND as valid relocation target type.
Mark Wielaard [Tue, 17 Nov 2020 14:08:05 +0000 (15:08 +0100)]
backends: Handle SHT_X86_64_UNWIND as valid relocation target type.

The x86_64 abi defines a special section type for .eh_frame[_hdr],
SHT_X86_64_UNWIND, which is a valid relocation target type.

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

Signed-off-by: Mark Wielaard <mark@klomp.org>
4 years agodebuginfod-find: Be a bit less verbose with -v
Mark Wielaard [Wed, 11 Nov 2020 20:28:07 +0000 (21:28 +0100)]
debuginfod-find: Be a bit less verbose with -v

debuginfod-find -v enables a progressfn that prints the Progress every
time the callback is called. For slow transfers or big downloads this
can be really verbose (hundreds a times a second). Slow it down a bit,
so it only prints the progress at most 5 times a second.

Signed-off-by: Mark Wielaard <mark@klomp.org>
4 years agolibelf: Update SH_ENTSIZE_HASH comment.
Mark Wielaard [Fri, 6 Nov 2020 17:16:24 +0000 (18:16 +0100)]
libelf: Update SH_ENTSIZE_HASH comment.

The elf-knowledge.h contains various macros to deal with specific ELF
knowledge needed to interpret some ELF constructs that can be ambigious
depending on architecture ABI. Update the comment of SH_ENTSIZE_HASH
to add a more technical description of why it is needed.

Signed-off-by: Mark Wielaard <mark@klomp.org>
4 years agoconfig: do not define DEBUGINFOD_URLS environment variable unnecessarily
Dmitry V. Levin [Wed, 4 Nov 2020 08:00:00 +0000 (08:00 +0000)]
config: do not define DEBUGINFOD_URLS environment variable unnecessarily

Before this change, when elfutils was configured without
--enable-debuginfod-urls, the installed profile.d/debuginfod.sh and
profile.d/debuginfod.csh scripts used to define the DEBUGINFOD_URLS
environment variable as an non-empty string containing spaces, making
all libdebuginfod users do extra work.

Change these scripts to avoid defining the DEBUGINFOD_URLS environment
variable unless configured using --enable-debuginfod-urls.

Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
4 years agoconfig: Conditionalize on LIBDEBUGINFOD instead of DEBUGINFOD
Dmitry V. Levin [Mon, 2 Nov 2020 08:00:00 +0000 (08:00 +0000)]
config: Conditionalize on LIBDEBUGINFOD instead of DEBUGINFOD

When elfutils is configured using --enable-libdebuginfod
--disable-debuginfod, that is, when the library is built and installed
but the server is not, it makes sense to install libdebuginfod.pc
because the latter complements the library rather than the server.

Likewise, it makes sense to install profile.d/debuginfod.*sh files
along with libdebuginfod because the library can use DEBUGINFOD_URLS
environment variable as well as the server.

This change does not affect --enable-debuginfod mode as the latter
requires --enable-libdebuginfod.

Fixes: fed3c3ceeaa6 ("Do not install libdebuginfod.pc unless debuginfod is enabled")
Fixes: b503c358dde8 ("Do not install profile.d/debuginfod.*sh files unless debuginfod is enabled")
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
4 years agolibelf: Check header exists in elf_strptr
Mark Wielaard [Sun, 1 Nov 2020 17:52:15 +0000 (18:52 +0100)]
libelf: Check header exists in elf_strptr

We already checked the header actually existed for ELFCLASS64 but not
for the ELFCLASS32 case. It is very unlikely it is at this point in the
code, but theoretically it could happen.

Signed-off-by: Mark Wielaard <mark@klomp.org>
4 years agolibelf: Set dst to zero on failure in __elf_getphdrnum_rdlock
Mark Wielaard [Sun, 1 Nov 2020 17:51:02 +0000 (18:51 +0100)]
libelf: Set dst to zero on failure in __elf_getphdrnum_rdlock

GCC with -flto finds some (very) unlikely error paths. It flags callers
of __elf_getphdrnum_chk_rdlock with *dst not yet set because an internal
call to __elf_getphdrnum_rdlock might not initialize *dst either in one
particular failure path. The sanity check that __elf_getphdrnum_chk_rdlock
then performs might happen against uninitialized data. So just set *dst
to zero on failure in __elf_getphdrnum_rdlock so any caller can simply
check either the result/error code or whether *dst is zero or not.

Signed-off-by: Mark Wielaard <mark@klomp.org>
4 years agolibelf: Use GElf_Ehdr instead of Elf handle in __libelf_data_type
Mark Wielaard [Sun, 1 Nov 2020 17:50:04 +0000 (18:50 +0100)]
libelf: Use GElf_Ehdr instead of Elf handle in __libelf_data_type

GCC with -flto detects some (very) unlikely issues in error paths.
In theory getting the Ehdr from an Elf handle might fail. But in
most cases where __libelf_data_type is used, we already have the
Ehdr anyway. So simply pass that to __libelf_data_type. In the one
place where we don't have it yet, get it and check for failure
before calling __libelf_data_type.

Signed-off-by: Mark Wielaard <mark@klomp.org>
4 years agotests: Create bogus R/nothing.rpm with cyclic symlink.
Mark Wielaard [Mon, 2 Nov 2020 14:20:54 +0000 (15:20 +0100)]
tests: Create bogus R/nothing.rpm with cyclic symlink.

We used to try to trigger an error during debuginfod scanning using
a chmod 000 file. But this doesn't always result in an error. Create
a cyclic symlink instead, which always results in a failure to open/read.

Signed-off-by: Mark Wielaard <mark@klomp.org>
4 years agoSwitch from numerical to defined constants for permissions.
Érico Rolim [Mon, 2 Nov 2020 01:49:46 +0000 (22:49 -0300)]
Switch from numerical to defined constants for permissions.

Use defined constants for permission values. Also add fallback
definitions for them in system.h, to allow for compatibility with
systems that don't provide these macros.

Include system.h in all tests/ files that required it.

Signed-off-by: Érico Rolim <erico.erc@gmail.com>
Signed-off-by: Mark Wielaard <mark@klomp.org>
4 years agodebuginfod.cxx: include libintl.h.
Érico Rolim [Mon, 2 Nov 2020 00:58:04 +0000 (21:58 -0300)]
debuginfod.cxx: include libintl.h.

Uncomment the <libintl.h> include, since textdomain() and
bindtextdomain() functions provided by it are being used.

Signed-off-by: Érico Rolim <erico.erc@gmail.com>
4 years agoSupport building when fts and obstack aren't part of libc.
Érico Rolim [Mon, 2 Nov 2020 00:48:50 +0000 (21:48 -0300)]
Support building when fts and obstack aren't part of libc.

- Make configure.ac test for fts and obstack availability;
- Add fts and obstack ldflags to all files that need them;
- Add missing argp ldflags to programs in debuginfod/.

Signed-off-by: Érico Rolim <erico.erc@gmail.com>
4 years agoDo not install profile.d/debuginfod.*sh files unless debuginfod is enabled elfutils-0.182
Dmitry V. Levin [Sat, 31 Oct 2020 18:55:28 +0000 (21:55 +0300)]
Do not install profile.d/debuginfod.*sh files unless debuginfod is enabled

Fixes: 94708e964601 ("PR25461: add /etc/profile.d files for default $DEBUGINFOD_URLS")
Fixes: fee123fb771f ("PR25461: uninstall /etc/profile.d files for distuninstallcheck")
Signed-off-by: Dmitry V. Levin <ldv@altlinux.org>
4 years agoPrepare for 0.182
Mark Wielaard [Sat, 31 Oct 2020 16:57:47 +0000 (17:57 +0100)]
Prepare for 0.182

Set version to 0.182.
Update NEWS and elfutils.spec.in.
Regenerate po/*.po files.

Signed-off-by: Mark Wielaard <mark@klomp.org>
4 years agodebuginfod: Accelerate traversal, shutdowns, improve metrics
Frank Ch. Eigler [Sat, 31 Oct 2020 13:48:56 +0000 (09:48 -0400)]
debuginfod: Accelerate traversal, shutdowns, improve metrics

Added new metrics for scanning that allow estimation of its reading
bandwidth.  Accelerated responsivity to SIGINT shutdown during
archive-scanning phase, which previously insisted on completely
processing the current archive.  Noted in systemd service file that in
the worst case, it might still take a long time.  Accelerated
traversals by moving regex -I/-X handling to apply to file names only
(as always documented), so directory traversal metrics are accurate
regardless of their name.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
4 years agotests: Add dlopen override to dwfl-proc-attach for old glibc/valgrind.
Mark Wielaard [Sat, 31 Oct 2020 12:43:42 +0000 (13:43 +0100)]
tests: Add dlopen override to dwfl-proc-attach for old glibc/valgrind.

Some combination of old glibc and valgrind create unsuppressable memory
leak warnings when the process is run under valgrind, is multi-threaded
and uses dlopen. libdw will try to dlopen libdebuginfod be default.
So simply override dlopen and always return NULL to make sure
libdebuginfod is never loaded.  The dwfl-proc-attach test doesn't rely
on libdebuginfod anyway.

This was seen on the armbian buildbot which uses valgrind 3.14.0 and
glibc 2.28.

Signed-off-by: Mark Wielaard <mark@klomp.org>
4 years agotests: Remove bashism from test-wrapper.sh /bin/sh script.
Mark Wielaard [Sat, 31 Oct 2020 10:19:23 +0000 (11:19 +0100)]
tests: Remove bashism from test-wrapper.sh /bin/sh script.

Debian uses dash as /bin/sh which is pretty strict about syntax. It
didn't like the == in  the test for strings in the test-wrapper.sh.
Replace by single =.

Signed-off-by: Mark Wielaard <mark@klomp.org>
4 years agotests: Run valgrind also on binary tests.
Mark Wielaard [Thu, 29 Oct 2020 15:43:14 +0000 (16:43 +0100)]
tests: Run valgrind also on binary tests.

When configuring with --enable-valgrind we were only running valgrind
on tests with a shell wrapper script. This patch makes sure to also run
valgrind on "pure" binary tests. This found one small issue in libasm
where we could be writing some uninitialized padding to an ELF file.
And there were a couple tests that didn't clean up all the resources
they used. Both issues are also fixed with this patch.

Signed-off-by: Mark Wielaard <mark@klomp.org>
4 years agoelfutils.spec.in: fix debuginfod state/config file flags
Frank Ch. Eigler [Fri, 30 Oct 2020 23:14:02 +0000 (19:14 -0400)]
elfutils.spec.in: fix debuginfod state/config file flags

During a test upgrade of an RPM based on this spec file, it was
observed that, er, the /var/cache/.../debuginfod.sqlite file was
zeroed.  Whoops!  We don't want to lose this data.  Removed the
%verify attributes and added %ghost for the sqlite database.

Signed-off-by: Frank Ch. Eigler <fche@redhat.com>
4 years agoPR26775: restore thread_work_groom metric to cycle count
Frank Ch. Eigler [Fri, 30 Oct 2020 22:26:04 +0000 (18:26 -0400)]
PR26775: restore thread_work_groom metric to cycle count

... and add new metrics about progress of traversal and groom
processes.  Correct one control flow abnormality that could
prematurely end a scanner thread and might have accounted for
the inconsistent test results from the previous patch.

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