From: Jiri Olsa <jolsa@redhat.com>
To: Martin KaFai Lau <kafai@fb.com>
Cc: dwarves@vger.kernel.org,
Arnaldo Carvalho de Melo <acme@kernel.org>,
bpf@vger.kernel.org, kernel-team@fb.com,
Andrii Nakryiko <andrii@kernel.org>
Subject: Re: [PATCH dwarves] btf: Generate btf for functions in the .BTF_ids section
Date: Tue, 27 Apr 2021 13:42:40 +0200 [thread overview]
Message-ID: <YIf4sF2H/xkex2Q1@krava> (raw)
In-Reply-To: <20210423213728.3538141-1-kafai@fb.com>
On Fri, Apr 23, 2021 at 02:37:28PM -0700, Martin KaFai Lau wrote:
SNIP
> +static int collect_listed_functions(struct btf_elf *btfe, GElf_Sym *sym,
> + size_t sym_sec_idx)
> +{
> + int len, digits = 0, underscores = 0;
> + const char *name;
> + char *func_name;
> +
> + if (!btfe->btf_ids_shndx ||
> + btfe->btf_ids_shndx != sym_sec_idx)
> + return 0;
> +
> + /* The kernel function in the btf id list will have symbol like:
> + * __BTF_ID__func__<kernel_func_name>__[digit]+
> + */
> + name = elf_sym__name(sym, btfe->symtab);
> + if (strncmp(name, BTF_ID_FUNC_PREFIX, BTF_ID_FUNC_PREFIX_LEN))
> + return 0;
> +
> + name += BTF_ID_FUNC_PREFIX_LEN;
> +
> + /* name: <kernel_func_name>__[digit]+
> + * Strip the ending __[digit]+
> + */
> + for (len = strlen(name); len && underscores != 2; len--) {
> + char c = name[len - 1];
> +
> + if (c == '_') {
> + if (!digits)
> + return 0;
> + underscores++;
> + } else if (isdigit(c)) {
> + if (underscores)
> + return 0;
> + digits++;
> + } else {
> + return 0;
> + }
> + }
> +
> + if (!len)
> + return 0;
> +
> + func_name = strndup(name, len);
> + if (!func_name) {
> + fprintf(stderr,
> + "Failed to alloc memory for listed function %s%s\n",
> + BTF_ID_FUNC_PREFIX, name);
> + return -1;
> + }
> +
> + if (is_listed_func(func_name)) {
> + /* already captured */
> + free(func_name);
> + return 0;
> + }
> +
> + /* grow listed_functions */
> + if (listed_functions_cnt == listed_functions_alloc) {
> + char **new;
> +
> + listed_functions_alloc = max(100,
> + listed_functions_alloc * 3 / 2);
> + new = realloc(listed_functions,
> + listed_functions_alloc * sizeof(*listed_functions));
> + if (!new) {
> + fprintf(stderr,
> + "Failed to alloc memory for listed function %s%s\n",
> + BTF_ID_FUNC_PREFIX, name);
> + free(func_name);
> + return -1;
> + }
> + listed_functions = new;
> + }
> +
> + listed_functions[listed_functions_cnt++] = func_name;
> + qsort(listed_functions, listed_functions_cnt,
> + sizeof(*listed_functions), listed_function_cmp);
I was thinking of doing this at the end in setup_functions,
but we need to do name lookups before adding.. also there are
not too many BTF_ID instances anyway
I'll run the test script with your change
jirka
next prev parent reply other threads:[~2021-04-27 11:42 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-23 21:37 [PATCH dwarves] btf: Generate btf for functions in the .BTF_ids section Martin KaFai Lau
2021-04-26 23:26 ` Andrii Nakryiko
2021-04-27 11:38 ` Jiri Olsa
2021-04-27 12:34 ` Arnaldo Carvalho de Melo
2021-04-27 12:43 ` Jiri Olsa
2021-04-27 20:38 ` Andrii Nakryiko
2021-04-28 13:10 ` Arnaldo Carvalho de Melo
2021-04-28 19:45 ` Andrii Nakryiko
2021-04-28 22:05 ` Arnaldo Carvalho de Melo
2021-05-01 0:16 ` Martin KaFai Lau
2021-05-01 22:23 ` Jiri Olsa
2021-04-27 11:42 ` Jiri Olsa [this message]
2021-04-27 18:20 ` Martin KaFai Lau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YIf4sF2H/xkex2Q1@krava \
--to=jolsa@redhat.com \
--cc=acme@kernel.org \
--cc=andrii@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=dwarves@vger.kernel.org \
--cc=kafai@fb.com \
--cc=kernel-team@fb.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).