* [PATCH v2] btf_encoder: Make BTF_KIND_TAG conditional
@ 2021-10-21 17:08 Ian Rogers
2021-10-21 17:28 ` Andrii Nakryiko
0 siblings, 1 reply; 2+ messages in thread
From: Ian Rogers @ 2021-10-21 17:08 UTC (permalink / raw)
To: Arnaldo Carvalho de Melo, Yonghong Song, Alexei Starovoitov,
Andrii Nakryiko, bpf, Daniel Borkmann, Petar Penkov
Cc: Ian Rogers
BTF_KIND_TAG is present in libbtf 6.0 but not libbtf in 5.15rc4. Make
the code requiring it conditionally compiled in.
Signed-off-by: Ian Rogers <irogers@google.com>
---
btf_encoder.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/btf_encoder.c b/btf_encoder.c
index c341f95..1694679 100644
--- a/btf_encoder.c
+++ b/btf_encoder.c
@@ -31,6 +31,15 @@
#include <errno.h>
#include <stdint.h>
+#ifndef LIBBPF_MINOR_VERSION
+/*
+ * The libbpf version is not defined in older versions, workaround by assuming
+ * version 0.5.
+ */
+#define LIBBPF_MAJOR_VERSION 0
+#define LIBBPF_MINOR_VERSION 5
+#endif
+
struct elf_function {
const char *name;
bool generated;
@@ -141,7 +150,9 @@ static const char * const btf_kind_str[NR_BTF_KINDS] = {
[BTF_KIND_VAR] = "VAR",
[BTF_KIND_DATASEC] = "DATASEC",
[BTF_KIND_FLOAT] = "FLOAT",
+#if LIBBPF_MINOR_VERSION > 5
[BTF_KIND_TAG] = "TAG",
+#endif
};
static const char *btf__printable_name(const struct btf *btf, uint32_t offset)
@@ -648,6 +659,7 @@ static int32_t btf_encoder__add_datasec(struct btf_encoder *encoder, const char
static int32_t btf_encoder__add_tag(struct btf_encoder *encoder, const char *value, uint32_t type,
int component_idx)
{
+#if LIBBPF_MINOR_VERSION > 5
struct btf *btf = encoder->btf;
const struct btf_type *t;
int32_t id;
@@ -663,6 +675,10 @@ static int32_t btf_encoder__add_tag(struct btf_encoder *encoder, const char *val
}
return id;
+#else
+ fprintf(stderr, "error: unable to encode BTF_KIND_TAG due to old libbtf\n");
+ return -ENOTSUP;
+#endif
}
/*
--
2.33.0.1079.g6e70778dc9-goog
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] btf_encoder: Make BTF_KIND_TAG conditional
2021-10-21 17:08 [PATCH v2] btf_encoder: Make BTF_KIND_TAG conditional Ian Rogers
@ 2021-10-21 17:28 ` Andrii Nakryiko
0 siblings, 0 replies; 2+ messages in thread
From: Andrii Nakryiko @ 2021-10-21 17:28 UTC (permalink / raw)
To: Ian Rogers
Cc: Arnaldo Carvalho de Melo, Yonghong Song, Alexei Starovoitov,
Andrii Nakryiko, bpf, Daniel Borkmann, Petar Penkov
On Thu, Oct 21, 2021 at 10:09 AM Ian Rogers <irogers@google.com> wrote:
>
> BTF_KIND_TAG is present in libbtf 6.0 but not libbtf in 5.15rc4. Make
> the code requiring it conditionally compiled in.
>
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
> btf_encoder.c | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)
>
> diff --git a/btf_encoder.c b/btf_encoder.c
> index c341f95..1694679 100644
> --- a/btf_encoder.c
> +++ b/btf_encoder.c
> @@ -31,6 +31,15 @@
> #include <errno.h>
> #include <stdint.h>
>
> +#ifndef LIBBPF_MINOR_VERSION
> +/*
> + * The libbpf version is not defined in older versions, workaround by assuming
> + * version 0.5.
> + */
> +#define LIBBPF_MAJOR_VERSION 0
> +#define LIBBPF_MINOR_VERSION 5
> +#endif
> +
> struct elf_function {
> const char *name;
> bool generated;
> @@ -141,7 +150,9 @@ static const char * const btf_kind_str[NR_BTF_KINDS] = {
> [BTF_KIND_VAR] = "VAR",
> [BTF_KIND_DATASEC] = "DATASEC",
> [BTF_KIND_FLOAT] = "FLOAT",
> +#if LIBBPF_MINOR_VERSION > 5
this will break on 1.0
> [BTF_KIND_TAG] = "TAG",
> +#endif
> };
>
> static const char *btf__printable_name(const struct btf *btf, uint32_t offset)
> @@ -648,6 +659,7 @@ static int32_t btf_encoder__add_datasec(struct btf_encoder *encoder, const char
> static int32_t btf_encoder__add_tag(struct btf_encoder *encoder, const char *value, uint32_t type,
> int component_idx)
> {
> +#if LIBBPF_MINOR_VERSION > 5
> struct btf *btf = encoder->btf;
> const struct btf_type *t;
> int32_t id;
> @@ -663,6 +675,10 @@ static int32_t btf_encoder__add_tag(struct btf_encoder *encoder, const char *val
> }
>
> return id;
> +#else
> + fprintf(stderr, "error: unable to encode BTF_KIND_TAG due to old libbtf\n");
> + return -ENOTSUP;
> +#endif
> }
>
> /*
> --
> 2.33.0.1079.g6e70778dc9-goog
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-10-21 17:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-21 17:08 [PATCH v2] btf_encoder: Make BTF_KIND_TAG conditional Ian Rogers
2021-10-21 17:28 ` Andrii Nakryiko
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).