From: Jean-Philippe Brucker <jean-philippe@linaro.org>
To: bpf@vger.kernel.org, andriin@fb.com
Cc: ast@kernel.org, daniel@iogearbox.net, kafai@fb.com,
songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com,
kpsingh@chromium.org, netdev@vger.kernel.org,
Jean-Philippe Brucker <jean-philippe@linaro.org>
Subject: [PATCH bpf] libbpf: Fix BTF-to-C conversion of noreturn function pointers
Date: Mon, 8 Jun 2020 17:20:52 +0200 [thread overview]
Message-ID: <20200608152052.898491-1-jean-philippe@linaro.org> (raw)
When trying to convert the BTF for a function pointer marked "noreturn"
to C code, bpftool currently generates a syntax error. This happens with
the exit() pointer in drivers/firmware/efi/libstub/efistub.h, in an
arm64 vmlinux. When dealing with this declaration:
efi_status_t __noreturn (__efiapi *exit)(...);
bpftool produces the following output:
efi_status_tvolatile (*exit)(...);
Fix the error by inserting the space before the function modifier.
Fixes: 351131b51c7a ("libbpf: add btf_dump API for BTF-to-C conversion")
Signed-off-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
---
tools/lib/bpf/btf_dump.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index 0c28ee82834b7..003f305fc2342 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -1111,9 +1111,11 @@ static void btf_dump_emit_type_decl(struct btf_dump *d, __u32 id,
d->decl_stack_cnt = stack_start;
}
-static void btf_dump_emit_mods(struct btf_dump *d, struct id_stack *decl_stack)
+static void btf__dump_emit_mods(struct btf_dump *d, struct id_stack *decl_stack,
+ const char *prefix, const char *suffix)
{
const struct btf_type *t;
+ const char *mod;
__u32 id;
while (decl_stack->cnt) {
@@ -1122,21 +1124,27 @@ static void btf_dump_emit_mods(struct btf_dump *d, struct id_stack *decl_stack)
switch (btf_kind(t)) {
case BTF_KIND_VOLATILE:
- btf_dump_printf(d, "volatile ");
+ mod = "volatile";
break;
case BTF_KIND_CONST:
- btf_dump_printf(d, "const ");
+ mod = "const";
break;
case BTF_KIND_RESTRICT:
- btf_dump_printf(d, "restrict ");
+ mod = "restrict";
break;
default:
return;
}
+ btf_dump_printf(d, "%s%s%s", prefix, mod, suffix);
decl_stack->cnt--;
}
}
+static void btf_dump_emit_mods(struct btf_dump *d, struct id_stack *decl_stack)
+{
+ btf__dump_emit_mods(d, decl_stack, "", " ");
+}
+
static void btf_dump_emit_name(const struct btf_dump *d,
const char *name, bool last_was_ptr)
{
@@ -1270,7 +1278,7 @@ static void btf_dump_emit_type_chain(struct btf_dump *d,
__u16 vlen = btf_vlen(t);
int i;
- btf_dump_emit_mods(d, decls);
+ btf__dump_emit_mods(d, decls, " ", "");
if (decls->cnt) {
btf_dump_printf(d, " (");
btf_dump_emit_type_chain(d, decls, fname, lvl);
--
2.27.0
next reply other threads:[~2020-06-08 15:21 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-08 15:20 Jean-Philippe Brucker [this message]
2020-06-08 23:50 ` [PATCH bpf] libbpf: Fix BTF-to-C conversion of noreturn function pointers Andrii Nakryiko
2020-06-09 14:05 ` Jean-Philippe Brucker
2020-06-10 5:26 ` Andrii Nakryiko
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=20200608152052.898491-1-jean-philippe@linaro.org \
--to=jean-philippe@linaro.org \
--cc=andriin@fb.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=john.fastabend@gmail.com \
--cc=kafai@fb.com \
--cc=kpsingh@chromium.org \
--cc=netdev@vger.kernel.org \
--cc=songliubraving@fb.com \
--cc=yhs@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).