History

bpf: btf: Change how section is supported in btf_header

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().

Martin KaFai Lau committed 8 years ago

Commit f80442a1 parent dcab51f2 files · +160 −57Browse files

Showing the changes to include/uapi/linux (1 of 2 files). Show all

Unified · Split

include/uapi/linux/btf.h+2−6
@@ -12,15 +12,11 @@ struct btf_header { · 11 unmodified lines
1212 __u16 magic;
1313 __u8 version;
1414 __u8 flags;
15−
16− __u32 parent_label;
17− __u32 parent_name;
15+ __u32 hdr_len;
1816
1917 /* 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 */
2318 __u32 type_off; /* offset of type section */
19+ __u32 type_len; /* length of type section */
2420 __u32 str_off; /* offset of string section */
2521 __u32 str_len; /* length of string section */
2622 };