Commit Graph

19 Commits

Author SHA1 Message Date
Arnaldo Carvalho de Melo 74c2078e04 dutil: elf_symtab__new() doesn't need the GElf_Ehdr *ep argument
In 3f8aad340b ("elf_symtab: Handle SHN_XINDEX index in
elf_section_by_name()") we stopped using that argument as we switched to
using elf_getshdrstrndx() to get SHN_XINDEX.

So just remove that argument and fixup its callers, this will allow
removing a good chunk of calls and variables.

Cc: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-08-20 16:40:27 -03:00
Arnaldo Carvalho de Melo f049fe9ebf dutil: Make handling of NULL by destructos consistent
All should accept a NULL and bail out, just like free().

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 11:00:18 -03:00
Arnaldo Carvalho de Melo 6784b03fd4 dutil: Adopt the zalloc()/zfree() from perf
So that we handle const pointers, also zalloc() is much simpler just
calling calloc(1, size).

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-05-27 11:00:18 -03:00
Jiri Olsa 3f8aad340b elf_symtab: Handle SHN_XINDEX index in elf_section_by_name()
Use elf_getshdrstrndx() to cover the case where the ELF header
'e_shstrndx' field contains the special value SHN_XINDEX so that we get
the proper string table index.

This is necessary to handle files with over 65536 sections, such as when
building the kernel with -f[function|data]-sections.  Other cases may
include when using FG-ASLR, LTO.

With so many sections, ELF is using extended section index table, which
is used to hold values for some of the indexes and extra code is needed
to retrieve them.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: Hao Luo <haoluo@google.com>
Cc: Joe Lawrence <joe.lawrence@redhat.com>
Cc: John Fastabend <john.fastabend@gmail.com>
Cc: KP Singh <kpsingh@chromium.org>
Cc: Mark Wieelard <mjw@redhat.com>
Cc: Martin KaFai Lau <kafai@fb.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Yonghong Song <yhs@fb.com>
Cc: bpf@vger.kernel.org
Cc: dwarves@vger.kernel.org
Cc: netdev@vger.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2021-01-25 14:25:01 -03:00
Jiri Olsa 17df51c700 btf_encoder: Detect kernel module ftrace addresses
Add support to detect kernel module ftrace addresses and use
it as filter for detected functions.

For kernel modules the ftrace addresses are stored in __mcount_loc
section. Adding the code that detects this section and reads
its data into array, which is then processed as filter by
current code.

There's one tricky point with kernel modules wrt Elf object,
which we get from dwfl_module_getelf function. This function
performs all possible relocations, including __mcount_loc
section.

So addrs array contains relocated values, which we need take
into account when we compare them to functions values which
are relative to their sections.

With this change for example for xfs.ko module in my kernel
config, I'm getting slightly bigger number of functions:

  before: 2373, after: 2601

The ftrace's available_filter_functions still shows 2701, but
it includes functions like:

  suffix_kstrtoint.constprop.0
  xchk_btree_check_minrecs.isra.0
  xfs_ascii_ci_compname.part.0

which are not part of dwarf data, the rest matches BTF functions.

Because of the malfunction DWARF's declaration tag, the 'before'
functions contain also functions that are not part of the module.
The 'after' functions contain only functions that are traceable
and part of xfs.ko.

Despite filtering out some declarations, this change also adds
static functions, hence the total number of functions is bigger.

Committer notes:

Andrii test notes:

<quote>
I've tested locally on bpf_testmod that I'm adding to selftests in [0].
All worked well. I changed the test function from global to non-inlined
static, and BTF had it. And the tests passed. So LGTM.

  [0] https://patchwork.kernel.org/user/todo/netdevbpf/?series=395715&delegate=121173&state=*
</>

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Tested-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Hao Luo <haoluo@google.com>
Cc: Yonghong Song <yhs@fb.com>
Cc: bpf@vger.kernel.org
Cc: dwarves@vger.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-12-07 12:53:11 -03:00
Arnaldo Carvalho de Melo 80af0fbbf3 dutils: Allow for having a priv area per strlist
We'll use it to parse args to a class, before we find it.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-08-05 15:16:19 -03:00
Arnaldo Carvalho de Melo 42b7a759f3 dutil: Add a strlwr() helper to lowercase a string, returning it
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-08-05 15:16:19 -03:00
Arnaldo Carvalho de Melo 37a5c7c5ba strlist: Allow iterating a strlist in the original order
I.e. when we do:

	pahole -C a,b,c,d binary

We want that the 'a' type be processed first, etc. So add a list for
that.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-08-05 15:16:19 -03:00
Domenico Andreoli e714d2eaa1 Adopt SPDX-License-Identifier
Signed-off-by: Domenico Andreoli <domenico.andreoli@linux.com>
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-01-18 15:41:48 -03:00
Arnaldo Carvalho de Melo a54515fa6e dwarves: Stop using 'self'
As Thomas Gleixner wisely pointed out, using 'self' is stupid, it
doesn't convey useful information, so use sensible names.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2012-08-17 18:47:15 -03:00
Arnaldo Carvalho de Melo 1009bc9fe7 dutil: Convert strlist to use rb_trees
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-06-18 14:02:29 -03:00
Arnaldo Carvalho de Melo 1701b6d68d dutil: Allow returning the section index in elf_section_by_name
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-03 11:53:05 -03:00
Arnaldo Carvalho de Melo 08d41fb4d2 strlist: Return false if NULL is passed to strlist__has_entry
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-03 11:49:46 -03:00
Arnaldo Carvalho de Melo 57ae9740d8 strlist: Allow strlist__add to distinguish ENOMEM from EEXIST
I.e. the operation may fail because the string is already there or
because there wasn't enough memory.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-04-03 11:47:28 -03:00
Arnaldo Carvalho de Melo 8bf5eb9bc8 dutil: Move elf_section_by_name to dutil
Will be used by more than one file.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-24 16:56:19 -03:00
Arnaldo Carvalho de Melo ccc808b88e dutil: Move zalloc to dutil
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-18 11:08:23 -03:00
Arnaldo Carvalho de Melo 4d44276d85 coding style: remove trailing whitespaces, etc
Amazing how many crept up over time, should have set the
execute bit of .git/hooks/pre-commit already, duh.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2009-03-14 13:50:36 -03:00
Arnaldo Carvalho de Melo 66b7191c18 [DUTIL]: Generalise fstrlist
Now at creation time we specify if the strings must be allocated or if using
the pointer directly.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-12-16 14:55:50 -02:00
Arnaldo Carvalho de Melo 06b3a1073e [DUTIL]: utilities for the dwarves
Can be used in other projects too.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2007-11-17 18:05:40 -02:00