]> git.baikalelectronics.ru Git - kernel.git/commit
libbpf: Support BTF loading and raw data output in both endianness
authorAndrii Nakryiko <andriin@fb.com>
Tue, 29 Sep 2020 04:30:45 +0000 (21:30 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 29 Sep 2020 19:21:23 +0000 (12:21 -0700)
commitae341790ea24e1bf1b1db4103d3d34529c4ffc87
tree34e57189c1a2b0ddaac3b86facb6a03c6aaa0cf2
parent87fa5dfc4367af77b580e83125b4f5f0b9e53ac5
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
tools/lib/bpf/btf.c
tools/lib/bpf/btf.h
tools/lib/bpf/libbpf.map