aboutsummaryrefslogtreecommitdiffstats
path: root/tools/lib/bpf/btf.h
diff options
context:
space:
mode:
authorAndrii Nakryiko <andriin@fb.com>2020-09-28 21:30:45 -0700
committerAlexei Starovoitov <ast@kernel.org>2020-09-29 12:21:23 -0700
commit3289959b97cac205df006fc79c88f042bf2765ab (patch)
tree34e57189c1a2b0ddaac3b86facb6a03c6aaa0cf2 /tools/lib/bpf/btf.h
parentselftests/bpf: Move and extend ASSERT_xxx() testing macros (diff)
downloadlinux-3289959b97cac205df006fc79c88f042bf2765ab.tar.xz
linux-3289959b97cac205df006fc79c88f042bf2765ab.zip
libbpf: Support BTF loading and raw data output in both endianness
Teach BTF to recognized wrong endianness and transparently convert it internally to host endianness. Original endianness of BTF will be preserved and used during btf__get_raw_data() to convert resulting raw data to the same endianness and a source raw_data. This means that little-endian host can parse big-endian BTF with no issues, all the type data will be presented to the client application in native endianness, but when it's time for emitting BTF to persist it in a file (e.g., after BTF deduplication), original non-native endianness will be preserved and stored. It's possible to query original endianness of BTF data with new btf__endianness() API. It's also possible to override desired output endianness with btf__set_endianness(), so that if application needs to load, say, big-endian BTF and store it as little-endian BTF, it's possible to manually override this. If btf__set_endianness() was used to change endianness, btf__endianness() will reflect overridden endianness. Given there are no known use cases for supporting cross-endianness for .BTF.ext, loading .BTF.ext in non-native endianness is not supported. Signed-off-by: Andrii Nakryiko <andriin@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Link: https://lore.kernel.org/bpf/20200929043046.1324350-3-andriin@fb.com
Diffstat (limited to 'tools/lib/bpf/btf.h')
-rw-r--r--tools/lib/bpf/btf.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/tools/lib/bpf/btf.h b/tools/lib/bpf/btf.h
index f7dec0144c3c..57247240a20a 100644
--- a/tools/lib/bpf/btf.h
+++ b/tools/lib/bpf/btf.h
@@ -25,6 +25,11 @@ struct btf_type;
struct bpf_object;
+enum btf_endianness {
+ BTF_LITTLE_ENDIAN = 0,
+ BTF_BIG_ENDIAN = 1,
+};
+
LIBBPF_API void btf__free(struct btf *btf);
LIBBPF_API struct btf *btf__new(const void *data, __u32 size);
LIBBPF_API struct btf *btf__new_empty(void);
@@ -42,6 +47,8 @@ LIBBPF_API const struct btf_type *btf__type_by_id(const struct btf *btf,
__u32 id);
LIBBPF_API size_t btf__pointer_size(const struct btf *btf);
LIBBPF_API int btf__set_pointer_size(struct btf *btf, size_t ptr_sz);
+LIBBPF_API enum btf_endianness btf__endianness(const struct btf *btf);
+LIBBPF_API int btf__set_endianness(struct btf *btf, enum btf_endianness endian);
LIBBPF_API __s64 btf__resolve_size(const struct btf *btf, __u32 type_id);
LIBBPF_API int btf__resolve_type(const struct btf *btf, __u32 type_id);
LIBBPF_API int btf__align_of(const struct btf *btf, __u32 id);