Skip to content

Commit 232ce4b

Browse files
olsajiriAlexei Starovoitov
authored andcommitted
bpf: Add info about .BTF_ids section to btf.rst
Updating btf.rst doc with info about .BTF_ids section Signed-off-by: Jiri Olsa <jolsa@kernel.org> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Tested-by: Andrii Nakryiko <andriin@fb.com> Acked-by: Andrii Nakryiko <andriin@fb.com> Link: https://lore.kernel.org/bpf/20200711215329.41165-8-jolsa@kernel.org
1 parent 49f4e67 commit 232ce4b

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

‎Documentation/bpf/btf.rst‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -691,6 +691,42 @@ kernel API, the ``insn_off`` is the instruction offset in the unit of ``struct
691691
bpf_insn``. For ELF API, the ``insn_off`` is the byte offset from the
692692
beginning of section (``btf_ext_info_sec->sec_name_off``).
693693

694+
4.2 .BTF_ids section
695+
====================
696+
697+
The .BTF_ids section encodes BTF ID values that are used within the kernel.
698+
699+
This section is created during the kernel compilation with the help of
700+
macros defined in ``include/linux/btf_ids.h`` header file. Kernel code can
701+
use them to create lists and sets (sorted lists) of BTF ID values.
702+
703+
The ``BTF_ID_LIST`` and ``BTF_ID`` macros define unsorted list of BTF ID values,
704+
with following syntax::
705+
706+
BTF_ID_LIST(list)
707+
BTF_ID(type1, name1)
708+
BTF_ID(type2, name2)
709+
710+
resulting in following layout in .BTF_ids section::
711+
712+
__BTF_ID__type1__name1__1:
713+
.zero 4
714+
__BTF_ID__type2__name2__2:
715+
.zero 4
716+
717+
The ``u32 list[];`` variable is defined to access the list.
718+
719+
The ``BTF_ID_UNUSED`` macro defines 4 zero bytes. It's used when we
720+
want to define unused entry in BTF_ID_LIST, like::
721+
722+
BTF_ID_LIST(bpf_skb_output_btf_ids)
723+
BTF_ID(struct, sk_buff)
724+
BTF_ID_UNUSED
725+
BTF_ID(struct, task_struct)
726+
727+
All the BTF ID lists and sets are compiled in the .BTF_ids section and
728+
resolved during the linking phase of kernel build by ``resolve_btfids`` tool.
729+
694730
5. Using BTF
695731
************
696732

0 commit comments

Comments
 (0)