diff options
author | Andrii Nakryiko <andriin@fb.com> | 2019-02-15 22:52:18 -0500 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2019-02-16 21:47:18 -0500 |
commit | 5aab392c55c96f9bb26d9294f965f156a87ee81c (patch) | |
tree | cf7663d2962d5e78e4bd2cd6f7f9f09da1964086 /tools/lib/bpf/btf.c | |
parent | 9d6b3584a7a9d7fa872cb17ceda7a3b208f441eb (diff) |
tools/libbpf: support bigger BTF data sizes
While it's understandable why kernel limits number of BTF types to 65535
and size of string section to 64KB, in libbpf as user-space library it's
too restrictive. E.g., pahole converting DWARF to BTF type information
for Linux kernel generates more than 3 million BTF types and more than
3MB of strings, before deduplication. So to allow btf__dedup() to do its
work, we need to be able to load bigger BTF sections using btf__new().
Singed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'tools/lib/bpf/btf.c')
-rw-r--r-- | tools/lib/bpf/btf.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index ade1c32fb083..68b50e9bbde1 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c | |||
@@ -16,7 +16,8 @@ | |||
16 | #define max(a, b) ((a) > (b) ? (a) : (b)) | 16 | #define max(a, b) ((a) > (b) ? (a) : (b)) |
17 | #define min(a, b) ((a) < (b) ? (a) : (b)) | 17 | #define min(a, b) ((a) < (b) ? (a) : (b)) |
18 | 18 | ||
19 | #define BTF_MAX_NR_TYPES 65535 | 19 | #define BTF_MAX_NR_TYPES 0x7fffffff |
20 | #define BTF_MAX_STR_OFFSET 0x7fffffff | ||
20 | 21 | ||
21 | #define IS_MODIFIER(k) (((k) == BTF_KIND_TYPEDEF) || \ | 22 | #define IS_MODIFIER(k) (((k) == BTF_KIND_TYPEDEF) || \ |
22 | ((k) == BTF_KIND_VOLATILE) || \ | 23 | ((k) == BTF_KIND_VOLATILE) || \ |
@@ -175,7 +176,7 @@ static int btf_parse_str_sec(struct btf *btf) | |||
175 | const char *start = btf->nohdr_data + hdr->str_off; | 176 | const char *start = btf->nohdr_data + hdr->str_off; |
176 | const char *end = start + btf->hdr->str_len; | 177 | const char *end = start + btf->hdr->str_len; |
177 | 178 | ||
178 | if (!hdr->str_len || hdr->str_len - 1 > BTF_MAX_NAME_OFFSET || | 179 | if (!hdr->str_len || hdr->str_len - 1 > BTF_MAX_STR_OFFSET || |
179 | start[0] || end[-1]) { | 180 | start[0] || end[-1]) { |
180 | pr_debug("Invalid BTF string section\n"); | 181 | pr_debug("Invalid BTF string section\n"); |
181 | return -EINVAL; | 182 | return -EINVAL; |
@@ -1882,7 +1883,7 @@ static int btf_dedup_prim_types(struct btf_dedup *d) | |||
1882 | */ | 1883 | */ |
1883 | static inline bool is_type_mapped(struct btf_dedup *d, uint32_t type_id) | 1884 | static inline bool is_type_mapped(struct btf_dedup *d, uint32_t type_id) |
1884 | { | 1885 | { |
1885 | return d->map[type_id] <= BTF_MAX_TYPE; | 1886 | return d->map[type_id] <= BTF_MAX_NR_TYPES; |
1886 | } | 1887 | } |
1887 | 1888 | ||
1888 | /* | 1889 | /* |
@@ -2033,7 +2034,7 @@ static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id, | |||
2033 | canon_id = resolve_fwd_id(d, canon_id); | 2034 | canon_id = resolve_fwd_id(d, canon_id); |
2034 | 2035 | ||
2035 | hypot_type_id = d->hypot_map[canon_id]; | 2036 | hypot_type_id = d->hypot_map[canon_id]; |
2036 | if (hypot_type_id <= BTF_MAX_TYPE) | 2037 | if (hypot_type_id <= BTF_MAX_NR_TYPES) |
2037 | return hypot_type_id == cand_id; | 2038 | return hypot_type_id == cand_id; |
2038 | 2039 | ||
2039 | if (btf_dedup_hypot_map_add(d, canon_id, cand_id)) | 2040 | if (btf_dedup_hypot_map_add(d, canon_id, cand_id)) |
@@ -2252,7 +2253,7 @@ static int btf_dedup_struct_type(struct btf_dedup *d, __u32 type_id) | |||
2252 | __u32 h; | 2253 | __u32 h; |
2253 | 2254 | ||
2254 | /* already deduped or is in process of deduping (loop detected) */ | 2255 | /* already deduped or is in process of deduping (loop detected) */ |
2255 | if (d->map[type_id] <= BTF_MAX_TYPE) | 2256 | if (d->map[type_id] <= BTF_MAX_NR_TYPES) |
2256 | return 0; | 2257 | return 0; |
2257 | 2258 | ||
2258 | t = d->btf->types[type_id]; | 2259 | t = d->btf->types[type_id]; |
@@ -2329,7 +2330,7 @@ static int btf_dedup_ref_type(struct btf_dedup *d, __u32 type_id) | |||
2329 | 2330 | ||
2330 | if (d->map[type_id] == BTF_IN_PROGRESS_ID) | 2331 | if (d->map[type_id] == BTF_IN_PROGRESS_ID) |
2331 | return -ELOOP; | 2332 | return -ELOOP; |
2332 | if (d->map[type_id] <= BTF_MAX_TYPE) | 2333 | if (d->map[type_id] <= BTF_MAX_NR_TYPES) |
2333 | return resolve_type_id(d, type_id); | 2334 | return resolve_type_id(d, type_id); |
2334 | 2335 | ||
2335 | t = d->btf->types[type_id]; | 2336 | t = d->btf->types[type_id]; |
@@ -2509,7 +2510,7 @@ static int btf_dedup_remap_type_id(struct btf_dedup *d, __u32 type_id) | |||
2509 | 2510 | ||
2510 | resolved_type_id = resolve_type_id(d, type_id); | 2511 | resolved_type_id = resolve_type_id(d, type_id); |
2511 | new_type_id = d->hypot_map[resolved_type_id]; | 2512 | new_type_id = d->hypot_map[resolved_type_id]; |
2512 | if (new_type_id > BTF_MAX_TYPE) | 2513 | if (new_type_id > BTF_MAX_NR_TYPES) |
2513 | return -EINVAL; | 2514 | return -EINVAL; |
2514 | return new_type_id; | 2515 | return new_type_id; |
2515 | } | 2516 | } |