There are currently unused section descriptions in the btf_header. Those sections are here to support future BTF use cases. For example, the func section (func_off) is to support function signature (e.g. the BPF prog function signature). Instead of spelling out all potential sections up-front in the btf_header. This patch makes changes to btf_header such that extending it (e.g. adding a section) is possible later. The unused ones can be removed for now and they can be added back later. This patch: 1. adds a hdr_len to the btf_header. It will allow adding sections (and other info like parent_label and parent_name) later. The check is similar to the existing bpf_attr. If a user passes in a longer hdr_len, the kernel ensures the extra tailing bytes are 0. 2. allows the section order in the BTF object to be different from its sec_off order in btf_header. 3. each sec_off is followed by a sec_len. It must not have gap or overlapping among sections. The string section is ensured to be at the end due to the 4 bytes alignment requirement of the type section. The above changes will allow enough flexibility to add new sections (and other info) to the btf_header later. This patch also removes an unnecessary !err check at the end of btf_parse().
Showing the changes to include/uapi/linux (1 of 2 files). Show all
Unified · Split
| @@ -12,15 +12,11 @@ struct btf_header { · 11 unmodified lines | |||
| 12 | __u16 magic; | 12 | __u16 magic; |
| 13 | __u8 version; | 13 | __u8 version; |
| 14 | __u8 flags; | 14 | __u8 flags; |
| 15 | 15 | __u32 hdr_len; | |
| 16 | __u32 parent_label; | ||
| 17 | __u32 parent_name; | ||
| 18 | 16 | ||
| 19 | /* All offsets are in bytes relative to the end of this header */ | 17 | /* All offsets are in bytes relative to the end of this header */ |
| 20 | __u32 label_off; /* offset of label section */ | ||
| 21 | __u32 object_off; /* offset of data object section*/ | ||
| 22 | __u32 func_off; /* offset of function section */ | ||
| 23 | __u32 type_off; /* offset of type section */ | 18 | __u32 type_off; /* offset of type section */ |
| 19 | __u32 type_len; /* length of type section */ | ||
| 24 | __u32 str_off; /* offset of string section */ | 20 | __u32 str_off; /* offset of string section */ |
| 25 | __u32 str_len; /* length of string section */ | 21 | __u32 str_len; /* length of string section */ |
| 26 | }; | 22 | }; |