diff options
author | Andrii Nakryiko <andriin@fb.com> | 2019-08-07 17:39:49 -0400 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2019-08-07 17:43:49 -0400 |
commit | b03bc6853c0e0c97da842434e8056f1b9d9a1f4a (patch) | |
tree | ef340b1b00bea3e0349d5ed4dff5bbf8fd054d6d | |
parent | ef20a9b27c66278ac2f85006db8ea11d5f61a781 (diff) |
libbpf: convert libbpf code to use new btf helpers
Simplify code by relying on newly added BTF helper functions.
Signed-off-by: Andrii Nakryiko <andriin@fb.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
-rw-r--r-- | tools/lib/bpf/btf.c | 181 | ||||
-rw-r--r-- | tools/lib/bpf/btf_dump.c | 138 | ||||
-rw-r--r-- | tools/lib/bpf/libbpf.c | 60 |
3 files changed, 158 insertions, 221 deletions
diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index 467224feb43b..1cd4e5d67158 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c | |||
@@ -19,13 +19,6 @@ | |||
19 | #define BTF_MAX_NR_TYPES 0x7fffffff | 19 | #define BTF_MAX_NR_TYPES 0x7fffffff |
20 | #define BTF_MAX_STR_OFFSET 0x7fffffff | 20 | #define BTF_MAX_STR_OFFSET 0x7fffffff |
21 | 21 | ||
22 | #define IS_MODIFIER(k) (((k) == BTF_KIND_TYPEDEF) || \ | ||
23 | ((k) == BTF_KIND_VOLATILE) || \ | ||
24 | ((k) == BTF_KIND_CONST) || \ | ||
25 | ((k) == BTF_KIND_RESTRICT)) | ||
26 | |||
27 | #define IS_VAR(k) ((k) == BTF_KIND_VAR) | ||
28 | |||
29 | static struct btf_type btf_void; | 22 | static struct btf_type btf_void; |
30 | 23 | ||
31 | struct btf { | 24 | struct btf { |
@@ -192,9 +185,9 @@ static int btf_parse_str_sec(struct btf *btf) | |||
192 | static int btf_type_size(struct btf_type *t) | 185 | static int btf_type_size(struct btf_type *t) |
193 | { | 186 | { |
194 | int base_size = sizeof(struct btf_type); | 187 | int base_size = sizeof(struct btf_type); |
195 | __u16 vlen = BTF_INFO_VLEN(t->info); | 188 | __u16 vlen = btf_vlen(t); |
196 | 189 | ||
197 | switch (BTF_INFO_KIND(t->info)) { | 190 | switch (btf_kind(t)) { |
198 | case BTF_KIND_FWD: | 191 | case BTF_KIND_FWD: |
199 | case BTF_KIND_CONST: | 192 | case BTF_KIND_CONST: |
200 | case BTF_KIND_VOLATILE: | 193 | case BTF_KIND_VOLATILE: |
@@ -219,7 +212,7 @@ static int btf_type_size(struct btf_type *t) | |||
219 | case BTF_KIND_DATASEC: | 212 | case BTF_KIND_DATASEC: |
220 | return base_size + vlen * sizeof(struct btf_var_secinfo); | 213 | return base_size + vlen * sizeof(struct btf_var_secinfo); |
221 | default: | 214 | default: |
222 | pr_debug("Unsupported BTF_KIND:%u\n", BTF_INFO_KIND(t->info)); | 215 | pr_debug("Unsupported BTF_KIND:%u\n", btf_kind(t)); |
223 | return -EINVAL; | 216 | return -EINVAL; |
224 | } | 217 | } |
225 | } | 218 | } |
@@ -263,7 +256,7 @@ const struct btf_type *btf__type_by_id(const struct btf *btf, __u32 type_id) | |||
263 | 256 | ||
264 | static bool btf_type_is_void(const struct btf_type *t) | 257 | static bool btf_type_is_void(const struct btf_type *t) |
265 | { | 258 | { |
266 | return t == &btf_void || BTF_INFO_KIND(t->info) == BTF_KIND_FWD; | 259 | return t == &btf_void || btf_is_fwd(t); |
267 | } | 260 | } |
268 | 261 | ||
269 | static bool btf_type_is_void_or_null(const struct btf_type *t) | 262 | static bool btf_type_is_void_or_null(const struct btf_type *t) |
@@ -284,7 +277,7 @@ __s64 btf__resolve_size(const struct btf *btf, __u32 type_id) | |||
284 | t = btf__type_by_id(btf, type_id); | 277 | t = btf__type_by_id(btf, type_id); |
285 | for (i = 0; i < MAX_RESOLVE_DEPTH && !btf_type_is_void_or_null(t); | 278 | for (i = 0; i < MAX_RESOLVE_DEPTH && !btf_type_is_void_or_null(t); |
286 | i++) { | 279 | i++) { |
287 | switch (BTF_INFO_KIND(t->info)) { | 280 | switch (btf_kind(t)) { |
288 | case BTF_KIND_INT: | 281 | case BTF_KIND_INT: |
289 | case BTF_KIND_STRUCT: | 282 | case BTF_KIND_STRUCT: |
290 | case BTF_KIND_UNION: | 283 | case BTF_KIND_UNION: |
@@ -303,7 +296,7 @@ __s64 btf__resolve_size(const struct btf *btf, __u32 type_id) | |||
303 | type_id = t->type; | 296 | type_id = t->type; |
304 | break; | 297 | break; |
305 | case BTF_KIND_ARRAY: | 298 | case BTF_KIND_ARRAY: |
306 | array = (const struct btf_array *)(t + 1); | 299 | array = btf_array(t); |
307 | if (nelems && array->nelems > UINT32_MAX / nelems) | 300 | if (nelems && array->nelems > UINT32_MAX / nelems) |
308 | return -E2BIG; | 301 | return -E2BIG; |
309 | nelems *= array->nelems; | 302 | nelems *= array->nelems; |
@@ -334,8 +327,7 @@ int btf__resolve_type(const struct btf *btf, __u32 type_id) | |||
334 | t = btf__type_by_id(btf, type_id); | 327 | t = btf__type_by_id(btf, type_id); |
335 | while (depth < MAX_RESOLVE_DEPTH && | 328 | while (depth < MAX_RESOLVE_DEPTH && |
336 | !btf_type_is_void_or_null(t) && | 329 | !btf_type_is_void_or_null(t) && |
337 | (IS_MODIFIER(BTF_INFO_KIND(t->info)) || | 330 | (btf_is_mod(t) || btf_is_typedef(t) || btf_is_var(t))) { |
338 | IS_VAR(BTF_INFO_KIND(t->info)))) { | ||
339 | type_id = t->type; | 331 | type_id = t->type; |
340 | t = btf__type_by_id(btf, type_id); | 332 | t = btf__type_by_id(btf, type_id); |
341 | depth++; | 333 | depth++; |
@@ -554,11 +546,11 @@ static int compare_vsi_off(const void *_a, const void *_b) | |||
554 | static int btf_fixup_datasec(struct bpf_object *obj, struct btf *btf, | 546 | static int btf_fixup_datasec(struct bpf_object *obj, struct btf *btf, |
555 | struct btf_type *t) | 547 | struct btf_type *t) |
556 | { | 548 | { |
557 | __u32 size = 0, off = 0, i, vars = BTF_INFO_VLEN(t->info); | 549 | __u32 size = 0, off = 0, i, vars = btf_vlen(t); |
558 | const char *name = btf__name_by_offset(btf, t->name_off); | 550 | const char *name = btf__name_by_offset(btf, t->name_off); |
559 | const struct btf_type *t_var; | 551 | const struct btf_type *t_var; |
560 | struct btf_var_secinfo *vsi; | 552 | struct btf_var_secinfo *vsi; |
561 | struct btf_var *var; | 553 | const struct btf_var *var; |
562 | int ret; | 554 | int ret; |
563 | 555 | ||
564 | if (!name) { | 556 | if (!name) { |
@@ -574,12 +566,11 @@ static int btf_fixup_datasec(struct bpf_object *obj, struct btf *btf, | |||
574 | 566 | ||
575 | t->size = size; | 567 | t->size = size; |
576 | 568 | ||
577 | for (i = 0, vsi = (struct btf_var_secinfo *)(t + 1); | 569 | for (i = 0, vsi = btf_var_secinfos(t); i < vars; i++, vsi++) { |
578 | i < vars; i++, vsi++) { | ||
579 | t_var = btf__type_by_id(btf, vsi->type); | 570 | t_var = btf__type_by_id(btf, vsi->type); |
580 | var = (struct btf_var *)(t_var + 1); | 571 | var = btf_var(t_var); |
581 | 572 | ||
582 | if (BTF_INFO_KIND(t_var->info) != BTF_KIND_VAR) { | 573 | if (!btf_is_var(t_var)) { |
583 | pr_debug("Non-VAR type seen in section %s\n", name); | 574 | pr_debug("Non-VAR type seen in section %s\n", name); |
584 | return -EINVAL; | 575 | return -EINVAL; |
585 | } | 576 | } |
@@ -595,7 +586,8 @@ static int btf_fixup_datasec(struct bpf_object *obj, struct btf *btf, | |||
595 | 586 | ||
596 | ret = bpf_object__variable_offset(obj, name, &off); | 587 | ret = bpf_object__variable_offset(obj, name, &off); |
597 | if (ret) { | 588 | if (ret) { |
598 | pr_debug("No offset found in symbol table for VAR %s\n", name); | 589 | pr_debug("No offset found in symbol table for VAR %s\n", |
590 | name); | ||
599 | return -ENOENT; | 591 | return -ENOENT; |
600 | } | 592 | } |
601 | 593 | ||
@@ -619,7 +611,7 @@ int btf__finalize_data(struct bpf_object *obj, struct btf *btf) | |||
619 | * is section size and global variable offset. We use | 611 | * is section size and global variable offset. We use |
620 | * the info from the ELF itself for this purpose. | 612 | * the info from the ELF itself for this purpose. |
621 | */ | 613 | */ |
622 | if (BTF_INFO_KIND(t->info) == BTF_KIND_DATASEC) { | 614 | if (btf_is_datasec(t)) { |
623 | err = btf_fixup_datasec(obj, btf, t); | 615 | err = btf_fixup_datasec(obj, btf, t); |
624 | if (err) | 616 | if (err) |
625 | break; | 617 | break; |
@@ -774,14 +766,13 @@ int btf__get_map_kv_tids(const struct btf *btf, const char *map_name, | |||
774 | return -EINVAL; | 766 | return -EINVAL; |
775 | } | 767 | } |
776 | 768 | ||
777 | if (BTF_INFO_KIND(container_type->info) != BTF_KIND_STRUCT || | 769 | if (!btf_is_struct(container_type) || btf_vlen(container_type) < 2) { |
778 | BTF_INFO_VLEN(container_type->info) < 2) { | ||
779 | pr_warning("map:%s container_name:%s is an invalid container struct\n", | 770 | pr_warning("map:%s container_name:%s is an invalid container struct\n", |
780 | map_name, container_name); | 771 | map_name, container_name); |
781 | return -EINVAL; | 772 | return -EINVAL; |
782 | } | 773 | } |
783 | 774 | ||
784 | key = (struct btf_member *)(container_type + 1); | 775 | key = btf_members(container_type); |
785 | value = key + 1; | 776 | value = key + 1; |
786 | 777 | ||
787 | key_size = btf__resolve_size(btf, key->type); | 778 | key_size = btf__resolve_size(btf, key->type); |
@@ -1440,10 +1431,9 @@ static struct btf_dedup *btf_dedup_new(struct btf *btf, struct btf_ext *btf_ext, | |||
1440 | d->map[0] = 0; | 1431 | d->map[0] = 0; |
1441 | for (i = 1; i <= btf->nr_types; i++) { | 1432 | for (i = 1; i <= btf->nr_types; i++) { |
1442 | struct btf_type *t = d->btf->types[i]; | 1433 | struct btf_type *t = d->btf->types[i]; |
1443 | __u16 kind = BTF_INFO_KIND(t->info); | ||
1444 | 1434 | ||
1445 | /* VAR and DATASEC are never deduped and are self-canonical */ | 1435 | /* VAR and DATASEC are never deduped and are self-canonical */ |
1446 | if (kind == BTF_KIND_VAR || kind == BTF_KIND_DATASEC) | 1436 | if (btf_is_var(t) || btf_is_datasec(t)) |
1447 | d->map[i] = i; | 1437 | d->map[i] = i; |
1448 | else | 1438 | else |
1449 | d->map[i] = BTF_UNPROCESSED_ID; | 1439 | d->map[i] = BTF_UNPROCESSED_ID; |
@@ -1484,11 +1474,11 @@ static int btf_for_each_str_off(struct btf_dedup *d, str_off_fn_t fn, void *ctx) | |||
1484 | if (r) | 1474 | if (r) |
1485 | return r; | 1475 | return r; |
1486 | 1476 | ||
1487 | switch (BTF_INFO_KIND(t->info)) { | 1477 | switch (btf_kind(t)) { |
1488 | case BTF_KIND_STRUCT: | 1478 | case BTF_KIND_STRUCT: |
1489 | case BTF_KIND_UNION: { | 1479 | case BTF_KIND_UNION: { |
1490 | struct btf_member *m = (struct btf_member *)(t + 1); | 1480 | struct btf_member *m = btf_members(t); |
1491 | __u16 vlen = BTF_INFO_VLEN(t->info); | 1481 | __u16 vlen = btf_vlen(t); |
1492 | 1482 | ||
1493 | for (j = 0; j < vlen; j++) { | 1483 | for (j = 0; j < vlen; j++) { |
1494 | r = fn(&m->name_off, ctx); | 1484 | r = fn(&m->name_off, ctx); |
@@ -1499,8 +1489,8 @@ static int btf_for_each_str_off(struct btf_dedup *d, str_off_fn_t fn, void *ctx) | |||
1499 | break; | 1489 | break; |
1500 | } | 1490 | } |
1501 | case BTF_KIND_ENUM: { | 1491 | case BTF_KIND_ENUM: { |
1502 | struct btf_enum *m = (struct btf_enum *)(t + 1); | 1492 | struct btf_enum *m = btf_enum(t); |
1503 | __u16 vlen = BTF_INFO_VLEN(t->info); | 1493 | __u16 vlen = btf_vlen(t); |
1504 | 1494 | ||
1505 | for (j = 0; j < vlen; j++) { | 1495 | for (j = 0; j < vlen; j++) { |
1506 | r = fn(&m->name_off, ctx); | 1496 | r = fn(&m->name_off, ctx); |
@@ -1511,8 +1501,8 @@ static int btf_for_each_str_off(struct btf_dedup *d, str_off_fn_t fn, void *ctx) | |||
1511 | break; | 1501 | break; |
1512 | } | 1502 | } |
1513 | case BTF_KIND_FUNC_PROTO: { | 1503 | case BTF_KIND_FUNC_PROTO: { |
1514 | struct btf_param *m = (struct btf_param *)(t + 1); | 1504 | struct btf_param *m = btf_params(t); |
1515 | __u16 vlen = BTF_INFO_VLEN(t->info); | 1505 | __u16 vlen = btf_vlen(t); |
1516 | 1506 | ||
1517 | for (j = 0; j < vlen; j++) { | 1507 | for (j = 0; j < vlen; j++) { |
1518 | r = fn(&m->name_off, ctx); | 1508 | r = fn(&m->name_off, ctx); |
@@ -1801,16 +1791,16 @@ static long btf_hash_enum(struct btf_type *t) | |||
1801 | /* Check structural equality of two ENUMs. */ | 1791 | /* Check structural equality of two ENUMs. */ |
1802 | static bool btf_equal_enum(struct btf_type *t1, struct btf_type *t2) | 1792 | static bool btf_equal_enum(struct btf_type *t1, struct btf_type *t2) |
1803 | { | 1793 | { |
1804 | struct btf_enum *m1, *m2; | 1794 | const struct btf_enum *m1, *m2; |
1805 | __u16 vlen; | 1795 | __u16 vlen; |
1806 | int i; | 1796 | int i; |
1807 | 1797 | ||
1808 | if (!btf_equal_common(t1, t2)) | 1798 | if (!btf_equal_common(t1, t2)) |
1809 | return false; | 1799 | return false; |
1810 | 1800 | ||
1811 | vlen = BTF_INFO_VLEN(t1->info); | 1801 | vlen = btf_vlen(t1); |
1812 | m1 = (struct btf_enum *)(t1 + 1); | 1802 | m1 = btf_enum(t1); |
1813 | m2 = (struct btf_enum *)(t2 + 1); | 1803 | m2 = btf_enum(t2); |
1814 | for (i = 0; i < vlen; i++) { | 1804 | for (i = 0; i < vlen; i++) { |
1815 | if (m1->name_off != m2->name_off || m1->val != m2->val) | 1805 | if (m1->name_off != m2->name_off || m1->val != m2->val) |
1816 | return false; | 1806 | return false; |
@@ -1822,8 +1812,7 @@ static bool btf_equal_enum(struct btf_type *t1, struct btf_type *t2) | |||
1822 | 1812 | ||
1823 | static inline bool btf_is_enum_fwd(struct btf_type *t) | 1813 | static inline bool btf_is_enum_fwd(struct btf_type *t) |
1824 | { | 1814 | { |
1825 | return BTF_INFO_KIND(t->info) == BTF_KIND_ENUM && | 1815 | return btf_is_enum(t) && btf_vlen(t) == 0; |
1826 | BTF_INFO_VLEN(t->info) == 0; | ||
1827 | } | 1816 | } |
1828 | 1817 | ||
1829 | static bool btf_compat_enum(struct btf_type *t1, struct btf_type *t2) | 1818 | static bool btf_compat_enum(struct btf_type *t1, struct btf_type *t2) |
@@ -1843,8 +1832,8 @@ static bool btf_compat_enum(struct btf_type *t1, struct btf_type *t2) | |||
1843 | */ | 1832 | */ |
1844 | static long btf_hash_struct(struct btf_type *t) | 1833 | static long btf_hash_struct(struct btf_type *t) |
1845 | { | 1834 | { |
1846 | struct btf_member *member = (struct btf_member *)(t + 1); | 1835 | const struct btf_member *member = btf_members(t); |
1847 | __u32 vlen = BTF_INFO_VLEN(t->info); | 1836 | __u32 vlen = btf_vlen(t); |
1848 | long h = btf_hash_common(t); | 1837 | long h = btf_hash_common(t); |
1849 | int i; | 1838 | int i; |
1850 | 1839 | ||
@@ -1864,16 +1853,16 @@ static long btf_hash_struct(struct btf_type *t) | |||
1864 | */ | 1853 | */ |
1865 | static bool btf_shallow_equal_struct(struct btf_type *t1, struct btf_type *t2) | 1854 | static bool btf_shallow_equal_struct(struct btf_type *t1, struct btf_type *t2) |
1866 | { | 1855 | { |
1867 | struct btf_member *m1, *m2; | 1856 | const struct btf_member *m1, *m2; |
1868 | __u16 vlen; | 1857 | __u16 vlen; |
1869 | int i; | 1858 | int i; |
1870 | 1859 | ||
1871 | if (!btf_equal_common(t1, t2)) | 1860 | if (!btf_equal_common(t1, t2)) |
1872 | return false; | 1861 | return false; |
1873 | 1862 | ||
1874 | vlen = BTF_INFO_VLEN(t1->info); | 1863 | vlen = btf_vlen(t1); |
1875 | m1 = (struct btf_member *)(t1 + 1); | 1864 | m1 = btf_members(t1); |
1876 | m2 = (struct btf_member *)(t2 + 1); | 1865 | m2 = btf_members(t2); |
1877 | for (i = 0; i < vlen; i++) { | 1866 | for (i = 0; i < vlen; i++) { |
1878 | if (m1->name_off != m2->name_off || m1->offset != m2->offset) | 1867 | if (m1->name_off != m2->name_off || m1->offset != m2->offset) |
1879 | return false; | 1868 | return false; |
@@ -1890,7 +1879,7 @@ static bool btf_shallow_equal_struct(struct btf_type *t1, struct btf_type *t2) | |||
1890 | */ | 1879 | */ |
1891 | static long btf_hash_array(struct btf_type *t) | 1880 | static long btf_hash_array(struct btf_type *t) |
1892 | { | 1881 | { |
1893 | struct btf_array *info = (struct btf_array *)(t + 1); | 1882 | const struct btf_array *info = btf_array(t); |
1894 | long h = btf_hash_common(t); | 1883 | long h = btf_hash_common(t); |
1895 | 1884 | ||
1896 | h = hash_combine(h, info->type); | 1885 | h = hash_combine(h, info->type); |
@@ -1908,13 +1897,13 @@ static long btf_hash_array(struct btf_type *t) | |||
1908 | */ | 1897 | */ |
1909 | static bool btf_equal_array(struct btf_type *t1, struct btf_type *t2) | 1898 | static bool btf_equal_array(struct btf_type *t1, struct btf_type *t2) |
1910 | { | 1899 | { |
1911 | struct btf_array *info1, *info2; | 1900 | const struct btf_array *info1, *info2; |
1912 | 1901 | ||
1913 | if (!btf_equal_common(t1, t2)) | 1902 | if (!btf_equal_common(t1, t2)) |
1914 | return false; | 1903 | return false; |
1915 | 1904 | ||
1916 | info1 = (struct btf_array *)(t1 + 1); | 1905 | info1 = btf_array(t1); |
1917 | info2 = (struct btf_array *)(t2 + 1); | 1906 | info2 = btf_array(t2); |
1918 | return info1->type == info2->type && | 1907 | return info1->type == info2->type && |
1919 | info1->index_type == info2->index_type && | 1908 | info1->index_type == info2->index_type && |
1920 | info1->nelems == info2->nelems; | 1909 | info1->nelems == info2->nelems; |
@@ -1927,14 +1916,10 @@ static bool btf_equal_array(struct btf_type *t1, struct btf_type *t2) | |||
1927 | */ | 1916 | */ |
1928 | static bool btf_compat_array(struct btf_type *t1, struct btf_type *t2) | 1917 | static bool btf_compat_array(struct btf_type *t1, struct btf_type *t2) |
1929 | { | 1918 | { |
1930 | struct btf_array *info1, *info2; | ||
1931 | |||
1932 | if (!btf_equal_common(t1, t2)) | 1919 | if (!btf_equal_common(t1, t2)) |
1933 | return false; | 1920 | return false; |
1934 | 1921 | ||
1935 | info1 = (struct btf_array *)(t1 + 1); | 1922 | return btf_array(t1)->nelems == btf_array(t2)->nelems; |
1936 | info2 = (struct btf_array *)(t2 + 1); | ||
1937 | return info1->nelems == info2->nelems; | ||
1938 | } | 1923 | } |
1939 | 1924 | ||
1940 | /* | 1925 | /* |
@@ -1944,8 +1929,8 @@ static bool btf_compat_array(struct btf_type *t1, struct btf_type *t2) | |||
1944 | */ | 1929 | */ |
1945 | static long btf_hash_fnproto(struct btf_type *t) | 1930 | static long btf_hash_fnproto(struct btf_type *t) |
1946 | { | 1931 | { |
1947 | struct btf_param *member = (struct btf_param *)(t + 1); | 1932 | const struct btf_param *member = btf_params(t); |
1948 | __u16 vlen = BTF_INFO_VLEN(t->info); | 1933 | __u16 vlen = btf_vlen(t); |
1949 | long h = btf_hash_common(t); | 1934 | long h = btf_hash_common(t); |
1950 | int i; | 1935 | int i; |
1951 | 1936 | ||
@@ -1966,16 +1951,16 @@ static long btf_hash_fnproto(struct btf_type *t) | |||
1966 | */ | 1951 | */ |
1967 | static bool btf_equal_fnproto(struct btf_type *t1, struct btf_type *t2) | 1952 | static bool btf_equal_fnproto(struct btf_type *t1, struct btf_type *t2) |
1968 | { | 1953 | { |
1969 | struct btf_param *m1, *m2; | 1954 | const struct btf_param *m1, *m2; |
1970 | __u16 vlen; | 1955 | __u16 vlen; |
1971 | int i; | 1956 | int i; |
1972 | 1957 | ||
1973 | if (!btf_equal_common(t1, t2)) | 1958 | if (!btf_equal_common(t1, t2)) |
1974 | return false; | 1959 | return false; |
1975 | 1960 | ||
1976 | vlen = BTF_INFO_VLEN(t1->info); | 1961 | vlen = btf_vlen(t1); |
1977 | m1 = (struct btf_param *)(t1 + 1); | 1962 | m1 = btf_params(t1); |
1978 | m2 = (struct btf_param *)(t2 + 1); | 1963 | m2 = btf_params(t2); |
1979 | for (i = 0; i < vlen; i++) { | 1964 | for (i = 0; i < vlen; i++) { |
1980 | if (m1->name_off != m2->name_off || m1->type != m2->type) | 1965 | if (m1->name_off != m2->name_off || m1->type != m2->type) |
1981 | return false; | 1966 | return false; |
@@ -1992,7 +1977,7 @@ static bool btf_equal_fnproto(struct btf_type *t1, struct btf_type *t2) | |||
1992 | */ | 1977 | */ |
1993 | static bool btf_compat_fnproto(struct btf_type *t1, struct btf_type *t2) | 1978 | static bool btf_compat_fnproto(struct btf_type *t1, struct btf_type *t2) |
1994 | { | 1979 | { |
1995 | struct btf_param *m1, *m2; | 1980 | const struct btf_param *m1, *m2; |
1996 | __u16 vlen; | 1981 | __u16 vlen; |
1997 | int i; | 1982 | int i; |
1998 | 1983 | ||
@@ -2000,9 +1985,9 @@ static bool btf_compat_fnproto(struct btf_type *t1, struct btf_type *t2) | |||
2000 | if (t1->name_off != t2->name_off || t1->info != t2->info) | 1985 | if (t1->name_off != t2->name_off || t1->info != t2->info) |
2001 | return false; | 1986 | return false; |
2002 | 1987 | ||
2003 | vlen = BTF_INFO_VLEN(t1->info); | 1988 | vlen = btf_vlen(t1); |
2004 | m1 = (struct btf_param *)(t1 + 1); | 1989 | m1 = btf_params(t1); |
2005 | m2 = (struct btf_param *)(t2 + 1); | 1990 | m2 = btf_params(t2); |
2006 | for (i = 0; i < vlen; i++) { | 1991 | for (i = 0; i < vlen; i++) { |
2007 | if (m1->name_off != m2->name_off) | 1992 | if (m1->name_off != m2->name_off) |
2008 | return false; | 1993 | return false; |
@@ -2028,7 +2013,7 @@ static int btf_dedup_prim_type(struct btf_dedup *d, __u32 type_id) | |||
2028 | __u32 cand_id; | 2013 | __u32 cand_id; |
2029 | long h; | 2014 | long h; |
2030 | 2015 | ||
2031 | switch (BTF_INFO_KIND(t->info)) { | 2016 | switch (btf_kind(t)) { |
2032 | case BTF_KIND_CONST: | 2017 | case BTF_KIND_CONST: |
2033 | case BTF_KIND_VOLATILE: | 2018 | case BTF_KIND_VOLATILE: |
2034 | case BTF_KIND_RESTRICT: | 2019 | case BTF_KIND_RESTRICT: |
@@ -2141,13 +2126,13 @@ static uint32_t resolve_fwd_id(struct btf_dedup *d, uint32_t type_id) | |||
2141 | { | 2126 | { |
2142 | __u32 orig_type_id = type_id; | 2127 | __u32 orig_type_id = type_id; |
2143 | 2128 | ||
2144 | if (BTF_INFO_KIND(d->btf->types[type_id]->info) != BTF_KIND_FWD) | 2129 | if (!btf_is_fwd(d->btf->types[type_id])) |
2145 | return type_id; | 2130 | return type_id; |
2146 | 2131 | ||
2147 | while (is_type_mapped(d, type_id) && d->map[type_id] != type_id) | 2132 | while (is_type_mapped(d, type_id) && d->map[type_id] != type_id) |
2148 | type_id = d->map[type_id]; | 2133 | type_id = d->map[type_id]; |
2149 | 2134 | ||
2150 | if (BTF_INFO_KIND(d->btf->types[type_id]->info) != BTF_KIND_FWD) | 2135 | if (!btf_is_fwd(d->btf->types[type_id])) |
2151 | return type_id; | 2136 | return type_id; |
2152 | 2137 | ||
2153 | return orig_type_id; | 2138 | return orig_type_id; |
@@ -2156,7 +2141,7 @@ static uint32_t resolve_fwd_id(struct btf_dedup *d, uint32_t type_id) | |||
2156 | 2141 | ||
2157 | static inline __u16 btf_fwd_kind(struct btf_type *t) | 2142 | static inline __u16 btf_fwd_kind(struct btf_type *t) |
2158 | { | 2143 | { |
2159 | return BTF_INFO_KFLAG(t->info) ? BTF_KIND_UNION : BTF_KIND_STRUCT; | 2144 | return btf_kflag(t) ? BTF_KIND_UNION : BTF_KIND_STRUCT; |
2160 | } | 2145 | } |
2161 | 2146 | ||
2162 | /* | 2147 | /* |
@@ -2277,8 +2262,8 @@ static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id, | |||
2277 | 2262 | ||
2278 | cand_type = d->btf->types[cand_id]; | 2263 | cand_type = d->btf->types[cand_id]; |
2279 | canon_type = d->btf->types[canon_id]; | 2264 | canon_type = d->btf->types[canon_id]; |
2280 | cand_kind = BTF_INFO_KIND(cand_type->info); | 2265 | cand_kind = btf_kind(cand_type); |
2281 | canon_kind = BTF_INFO_KIND(canon_type->info); | 2266 | canon_kind = btf_kind(canon_type); |
2282 | 2267 | ||
2283 | if (cand_type->name_off != canon_type->name_off) | 2268 | if (cand_type->name_off != canon_type->name_off) |
2284 | return 0; | 2269 | return 0; |
@@ -2327,12 +2312,12 @@ static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id, | |||
2327 | return btf_dedup_is_equiv(d, cand_type->type, canon_type->type); | 2312 | return btf_dedup_is_equiv(d, cand_type->type, canon_type->type); |
2328 | 2313 | ||
2329 | case BTF_KIND_ARRAY: { | 2314 | case BTF_KIND_ARRAY: { |
2330 | struct btf_array *cand_arr, *canon_arr; | 2315 | const struct btf_array *cand_arr, *canon_arr; |
2331 | 2316 | ||
2332 | if (!btf_compat_array(cand_type, canon_type)) | 2317 | if (!btf_compat_array(cand_type, canon_type)) |
2333 | return 0; | 2318 | return 0; |
2334 | cand_arr = (struct btf_array *)(cand_type + 1); | 2319 | cand_arr = btf_array(cand_type); |
2335 | canon_arr = (struct btf_array *)(canon_type + 1); | 2320 | canon_arr = btf_array(canon_type); |
2336 | eq = btf_dedup_is_equiv(d, | 2321 | eq = btf_dedup_is_equiv(d, |
2337 | cand_arr->index_type, canon_arr->index_type); | 2322 | cand_arr->index_type, canon_arr->index_type); |
2338 | if (eq <= 0) | 2323 | if (eq <= 0) |
@@ -2342,14 +2327,14 @@ static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id, | |||
2342 | 2327 | ||
2343 | case BTF_KIND_STRUCT: | 2328 | case BTF_KIND_STRUCT: |
2344 | case BTF_KIND_UNION: { | 2329 | case BTF_KIND_UNION: { |
2345 | struct btf_member *cand_m, *canon_m; | 2330 | const struct btf_member *cand_m, *canon_m; |
2346 | __u16 vlen; | 2331 | __u16 vlen; |
2347 | 2332 | ||
2348 | if (!btf_shallow_equal_struct(cand_type, canon_type)) | 2333 | if (!btf_shallow_equal_struct(cand_type, canon_type)) |
2349 | return 0; | 2334 | return 0; |
2350 | vlen = BTF_INFO_VLEN(cand_type->info); | 2335 | vlen = btf_vlen(cand_type); |
2351 | cand_m = (struct btf_member *)(cand_type + 1); | 2336 | cand_m = btf_members(cand_type); |
2352 | canon_m = (struct btf_member *)(canon_type + 1); | 2337 | canon_m = btf_members(canon_type); |
2353 | for (i = 0; i < vlen; i++) { | 2338 | for (i = 0; i < vlen; i++) { |
2354 | eq = btf_dedup_is_equiv(d, cand_m->type, canon_m->type); | 2339 | eq = btf_dedup_is_equiv(d, cand_m->type, canon_m->type); |
2355 | if (eq <= 0) | 2340 | if (eq <= 0) |
@@ -2362,7 +2347,7 @@ static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id, | |||
2362 | } | 2347 | } |
2363 | 2348 | ||
2364 | case BTF_KIND_FUNC_PROTO: { | 2349 | case BTF_KIND_FUNC_PROTO: { |
2365 | struct btf_param *cand_p, *canon_p; | 2350 | const struct btf_param *cand_p, *canon_p; |
2366 | __u16 vlen; | 2351 | __u16 vlen; |
2367 | 2352 | ||
2368 | if (!btf_compat_fnproto(cand_type, canon_type)) | 2353 | if (!btf_compat_fnproto(cand_type, canon_type)) |
@@ -2370,9 +2355,9 @@ static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id, | |||
2370 | eq = btf_dedup_is_equiv(d, cand_type->type, canon_type->type); | 2355 | eq = btf_dedup_is_equiv(d, cand_type->type, canon_type->type); |
2371 | if (eq <= 0) | 2356 | if (eq <= 0) |
2372 | return eq; | 2357 | return eq; |
2373 | vlen = BTF_INFO_VLEN(cand_type->info); | 2358 | vlen = btf_vlen(cand_type); |
2374 | cand_p = (struct btf_param *)(cand_type + 1); | 2359 | cand_p = btf_params(cand_type); |
2375 | canon_p = (struct btf_param *)(canon_type + 1); | 2360 | canon_p = btf_params(canon_type); |
2376 | for (i = 0; i < vlen; i++) { | 2361 | for (i = 0; i < vlen; i++) { |
2377 | eq = btf_dedup_is_equiv(d, cand_p->type, canon_p->type); | 2362 | eq = btf_dedup_is_equiv(d, cand_p->type, canon_p->type); |
2378 | if (eq <= 0) | 2363 | if (eq <= 0) |
@@ -2427,8 +2412,8 @@ static void btf_dedup_merge_hypot_map(struct btf_dedup *d) | |||
2427 | targ_type_id = d->hypot_map[cand_type_id]; | 2412 | targ_type_id = d->hypot_map[cand_type_id]; |
2428 | t_id = resolve_type_id(d, targ_type_id); | 2413 | t_id = resolve_type_id(d, targ_type_id); |
2429 | c_id = resolve_type_id(d, cand_type_id); | 2414 | c_id = resolve_type_id(d, cand_type_id); |
2430 | t_kind = BTF_INFO_KIND(d->btf->types[t_id]->info); | 2415 | t_kind = btf_kind(d->btf->types[t_id]); |
2431 | c_kind = BTF_INFO_KIND(d->btf->types[c_id]->info); | 2416 | c_kind = btf_kind(d->btf->types[c_id]); |
2432 | /* | 2417 | /* |
2433 | * Resolve FWD into STRUCT/UNION. | 2418 | * Resolve FWD into STRUCT/UNION. |
2434 | * It's ok to resolve FWD into STRUCT/UNION that's not yet | 2419 | * It's ok to resolve FWD into STRUCT/UNION that's not yet |
@@ -2497,7 +2482,7 @@ static int btf_dedup_struct_type(struct btf_dedup *d, __u32 type_id) | |||
2497 | return 0; | 2482 | return 0; |
2498 | 2483 | ||
2499 | t = d->btf->types[type_id]; | 2484 | t = d->btf->types[type_id]; |
2500 | kind = BTF_INFO_KIND(t->info); | 2485 | kind = btf_kind(t); |
2501 | 2486 | ||
2502 | if (kind != BTF_KIND_STRUCT && kind != BTF_KIND_UNION) | 2487 | if (kind != BTF_KIND_STRUCT && kind != BTF_KIND_UNION) |
2503 | return 0; | 2488 | return 0; |
@@ -2592,7 +2577,7 @@ static int btf_dedup_ref_type(struct btf_dedup *d, __u32 type_id) | |||
2592 | t = d->btf->types[type_id]; | 2577 | t = d->btf->types[type_id]; |
2593 | d->map[type_id] = BTF_IN_PROGRESS_ID; | 2578 | d->map[type_id] = BTF_IN_PROGRESS_ID; |
2594 | 2579 | ||
2595 | switch (BTF_INFO_KIND(t->info)) { | 2580 | switch (btf_kind(t)) { |
2596 | case BTF_KIND_CONST: | 2581 | case BTF_KIND_CONST: |
2597 | case BTF_KIND_VOLATILE: | 2582 | case BTF_KIND_VOLATILE: |
2598 | case BTF_KIND_RESTRICT: | 2583 | case BTF_KIND_RESTRICT: |
@@ -2616,7 +2601,7 @@ static int btf_dedup_ref_type(struct btf_dedup *d, __u32 type_id) | |||
2616 | break; | 2601 | break; |
2617 | 2602 | ||
2618 | case BTF_KIND_ARRAY: { | 2603 | case BTF_KIND_ARRAY: { |
2619 | struct btf_array *info = (struct btf_array *)(t + 1); | 2604 | struct btf_array *info = btf_array(t); |
2620 | 2605 | ||
2621 | ref_type_id = btf_dedup_ref_type(d, info->type); | 2606 | ref_type_id = btf_dedup_ref_type(d, info->type); |
2622 | if (ref_type_id < 0) | 2607 | if (ref_type_id < 0) |
@@ -2650,8 +2635,8 @@ static int btf_dedup_ref_type(struct btf_dedup *d, __u32 type_id) | |||
2650 | return ref_type_id; | 2635 | return ref_type_id; |
2651 | t->type = ref_type_id; | 2636 | t->type = ref_type_id; |
2652 | 2637 | ||
2653 | vlen = BTF_INFO_VLEN(t->info); | 2638 | vlen = btf_vlen(t); |
2654 | param = (struct btf_param *)(t + 1); | 2639 | param = btf_params(t); |
2655 | for (i = 0; i < vlen; i++) { | 2640 | for (i = 0; i < vlen; i++) { |
2656 | ref_type_id = btf_dedup_ref_type(d, param->type); | 2641 | ref_type_id = btf_dedup_ref_type(d, param->type); |
2657 | if (ref_type_id < 0) | 2642 | if (ref_type_id < 0) |
@@ -2791,7 +2776,7 @@ static int btf_dedup_remap_type(struct btf_dedup *d, __u32 type_id) | |||
2791 | struct btf_type *t = d->btf->types[type_id]; | 2776 | struct btf_type *t = d->btf->types[type_id]; |
2792 | int i, r; | 2777 | int i, r; |
2793 | 2778 | ||
2794 | switch (BTF_INFO_KIND(t->info)) { | 2779 | switch (btf_kind(t)) { |
2795 | case BTF_KIND_INT: | 2780 | case BTF_KIND_INT: |
2796 | case BTF_KIND_ENUM: | 2781 | case BTF_KIND_ENUM: |
2797 | break; | 2782 | break; |
@@ -2811,7 +2796,7 @@ static int btf_dedup_remap_type(struct btf_dedup *d, __u32 type_id) | |||
2811 | break; | 2796 | break; |
2812 | 2797 | ||
2813 | case BTF_KIND_ARRAY: { | 2798 | case BTF_KIND_ARRAY: { |
2814 | struct btf_array *arr_info = (struct btf_array *)(t + 1); | 2799 | struct btf_array *arr_info = btf_array(t); |
2815 | 2800 | ||
2816 | r = btf_dedup_remap_type_id(d, arr_info->type); | 2801 | r = btf_dedup_remap_type_id(d, arr_info->type); |
2817 | if (r < 0) | 2802 | if (r < 0) |
@@ -2826,8 +2811,8 @@ static int btf_dedup_remap_type(struct btf_dedup *d, __u32 type_id) | |||
2826 | 2811 | ||
2827 | case BTF_KIND_STRUCT: | 2812 | case BTF_KIND_STRUCT: |
2828 | case BTF_KIND_UNION: { | 2813 | case BTF_KIND_UNION: { |
2829 | struct btf_member *member = (struct btf_member *)(t + 1); | 2814 | struct btf_member *member = btf_members(t); |
2830 | __u16 vlen = BTF_INFO_VLEN(t->info); | 2815 | __u16 vlen = btf_vlen(t); |
2831 | 2816 | ||
2832 | for (i = 0; i < vlen; i++) { | 2817 | for (i = 0; i < vlen; i++) { |
2833 | r = btf_dedup_remap_type_id(d, member->type); | 2818 | r = btf_dedup_remap_type_id(d, member->type); |
@@ -2840,8 +2825,8 @@ static int btf_dedup_remap_type(struct btf_dedup *d, __u32 type_id) | |||
2840 | } | 2825 | } |
2841 | 2826 | ||
2842 | case BTF_KIND_FUNC_PROTO: { | 2827 | case BTF_KIND_FUNC_PROTO: { |
2843 | struct btf_param *param = (struct btf_param *)(t + 1); | 2828 | struct btf_param *param = btf_params(t); |
2844 | __u16 vlen = BTF_INFO_VLEN(t->info); | 2829 | __u16 vlen = btf_vlen(t); |
2845 | 2830 | ||
2846 | r = btf_dedup_remap_type_id(d, t->type); | 2831 | r = btf_dedup_remap_type_id(d, t->type); |
2847 | if (r < 0) | 2832 | if (r < 0) |
@@ -2859,8 +2844,8 @@ static int btf_dedup_remap_type(struct btf_dedup *d, __u32 type_id) | |||
2859 | } | 2844 | } |
2860 | 2845 | ||
2861 | case BTF_KIND_DATASEC: { | 2846 | case BTF_KIND_DATASEC: { |
2862 | struct btf_var_secinfo *var = (struct btf_var_secinfo *)(t + 1); | 2847 | struct btf_var_secinfo *var = btf_var_secinfos(t); |
2863 | __u16 vlen = BTF_INFO_VLEN(t->info); | 2848 | __u16 vlen = btf_vlen(t); |
2864 | 2849 | ||
2865 | for (i = 0; i < vlen; i++) { | 2850 | for (i = 0; i < vlen; i++) { |
2866 | r = btf_dedup_remap_type_id(d, var->type); | 2851 | r = btf_dedup_remap_type_id(d, var->type); |
diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c index 7065bb5b2752..715967762312 100644 --- a/tools/lib/bpf/btf_dump.c +++ b/tools/lib/bpf/btf_dump.c | |||
@@ -100,21 +100,6 @@ static bool str_equal_fn(const void *a, const void *b, void *ctx) | |||
100 | return strcmp(a, b) == 0; | 100 | return strcmp(a, b) == 0; |
101 | } | 101 | } |
102 | 102 | ||
103 | static __u16 btf_kind_of(const struct btf_type *t) | ||
104 | { | ||
105 | return BTF_INFO_KIND(t->info); | ||
106 | } | ||
107 | |||
108 | static __u16 btf_vlen_of(const struct btf_type *t) | ||
109 | { | ||
110 | return BTF_INFO_VLEN(t->info); | ||
111 | } | ||
112 | |||
113 | static bool btf_kflag_of(const struct btf_type *t) | ||
114 | { | ||
115 | return BTF_INFO_KFLAG(t->info); | ||
116 | } | ||
117 | |||
118 | static const char *btf_name_of(const struct btf_dump *d, __u32 name_off) | 103 | static const char *btf_name_of(const struct btf_dump *d, __u32 name_off) |
119 | { | 104 | { |
120 | return btf__name_by_offset(d->btf, name_off); | 105 | return btf__name_by_offset(d->btf, name_off); |
@@ -349,7 +334,7 @@ static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr) | |||
349 | */ | 334 | */ |
350 | struct btf_dump_type_aux_state *tstate = &d->type_states[id]; | 335 | struct btf_dump_type_aux_state *tstate = &d->type_states[id]; |
351 | const struct btf_type *t; | 336 | const struct btf_type *t; |
352 | __u16 kind, vlen; | 337 | __u16 vlen; |
353 | int err, i; | 338 | int err, i; |
354 | 339 | ||
355 | /* return true, letting typedefs know that it's ok to be emitted */ | 340 | /* return true, letting typedefs know that it's ok to be emitted */ |
@@ -357,18 +342,16 @@ static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr) | |||
357 | return 1; | 342 | return 1; |
358 | 343 | ||
359 | t = btf__type_by_id(d->btf, id); | 344 | t = btf__type_by_id(d->btf, id); |
360 | kind = btf_kind_of(t); | ||
361 | 345 | ||
362 | if (tstate->order_state == ORDERING) { | 346 | if (tstate->order_state == ORDERING) { |
363 | /* type loop, but resolvable through fwd declaration */ | 347 | /* type loop, but resolvable through fwd declaration */ |
364 | if ((kind == BTF_KIND_STRUCT || kind == BTF_KIND_UNION) && | 348 | if (btf_is_composite(t) && through_ptr && t->name_off != 0) |
365 | through_ptr && t->name_off != 0) | ||
366 | return 0; | 349 | return 0; |
367 | pr_warning("unsatisfiable type cycle, id:[%u]\n", id); | 350 | pr_warning("unsatisfiable type cycle, id:[%u]\n", id); |
368 | return -ELOOP; | 351 | return -ELOOP; |
369 | } | 352 | } |
370 | 353 | ||
371 | switch (kind) { | 354 | switch (btf_kind(t)) { |
372 | case BTF_KIND_INT: | 355 | case BTF_KIND_INT: |
373 | tstate->order_state = ORDERED; | 356 | tstate->order_state = ORDERED; |
374 | return 0; | 357 | return 0; |
@@ -378,14 +361,12 @@ static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr) | |||
378 | tstate->order_state = ORDERED; | 361 | tstate->order_state = ORDERED; |
379 | return err; | 362 | return err; |
380 | 363 | ||
381 | case BTF_KIND_ARRAY: { | 364 | case BTF_KIND_ARRAY: |
382 | const struct btf_array *a = (void *)(t + 1); | 365 | return btf_dump_order_type(d, btf_array(t)->type, through_ptr); |
383 | 366 | ||
384 | return btf_dump_order_type(d, a->type, through_ptr); | ||
385 | } | ||
386 | case BTF_KIND_STRUCT: | 367 | case BTF_KIND_STRUCT: |
387 | case BTF_KIND_UNION: { | 368 | case BTF_KIND_UNION: { |
388 | const struct btf_member *m = (void *)(t + 1); | 369 | const struct btf_member *m = btf_members(t); |
389 | /* | 370 | /* |
390 | * struct/union is part of strong link, only if it's embedded | 371 | * struct/union is part of strong link, only if it's embedded |
391 | * (so no ptr in a path) or it's anonymous (so has to be | 372 | * (so no ptr in a path) or it's anonymous (so has to be |
@@ -396,7 +377,7 @@ static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr) | |||
396 | 377 | ||
397 | tstate->order_state = ORDERING; | 378 | tstate->order_state = ORDERING; |
398 | 379 | ||
399 | vlen = btf_vlen_of(t); | 380 | vlen = btf_vlen(t); |
400 | for (i = 0; i < vlen; i++, m++) { | 381 | for (i = 0; i < vlen; i++, m++) { |
401 | err = btf_dump_order_type(d, m->type, false); | 382 | err = btf_dump_order_type(d, m->type, false); |
402 | if (err < 0) | 383 | if (err < 0) |
@@ -447,7 +428,7 @@ static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr) | |||
447 | return btf_dump_order_type(d, t->type, through_ptr); | 428 | return btf_dump_order_type(d, t->type, through_ptr); |
448 | 429 | ||
449 | case BTF_KIND_FUNC_PROTO: { | 430 | case BTF_KIND_FUNC_PROTO: { |
450 | const struct btf_param *p = (void *)(t + 1); | 431 | const struct btf_param *p = btf_params(t); |
451 | bool is_strong; | 432 | bool is_strong; |
452 | 433 | ||
453 | err = btf_dump_order_type(d, t->type, through_ptr); | 434 | err = btf_dump_order_type(d, t->type, through_ptr); |
@@ -455,7 +436,7 @@ static int btf_dump_order_type(struct btf_dump *d, __u32 id, bool through_ptr) | |||
455 | return err; | 436 | return err; |
456 | is_strong = err > 0; | 437 | is_strong = err > 0; |
457 | 438 | ||
458 | vlen = btf_vlen_of(t); | 439 | vlen = btf_vlen(t); |
459 | for (i = 0; i < vlen; i++, p++) { | 440 | for (i = 0; i < vlen; i++, p++) { |
460 | err = btf_dump_order_type(d, p->type, through_ptr); | 441 | err = btf_dump_order_type(d, p->type, through_ptr); |
461 | if (err < 0) | 442 | if (err < 0) |
@@ -553,7 +534,7 @@ static void btf_dump_emit_type(struct btf_dump *d, __u32 id, __u32 cont_id) | |||
553 | return; | 534 | return; |
554 | 535 | ||
555 | t = btf__type_by_id(d->btf, id); | 536 | t = btf__type_by_id(d->btf, id); |
556 | kind = btf_kind_of(t); | 537 | kind = btf_kind(t); |
557 | 538 | ||
558 | if (top_level_def && t->name_off == 0) { | 539 | if (top_level_def && t->name_off == 0) { |
559 | pr_warning("unexpected nameless definition, id:[%u]\n", id); | 540 | pr_warning("unexpected nameless definition, id:[%u]\n", id); |
@@ -618,12 +599,9 @@ static void btf_dump_emit_type(struct btf_dump *d, __u32 id, __u32 cont_id) | |||
618 | case BTF_KIND_RESTRICT: | 599 | case BTF_KIND_RESTRICT: |
619 | btf_dump_emit_type(d, t->type, cont_id); | 600 | btf_dump_emit_type(d, t->type, cont_id); |
620 | break; | 601 | break; |
621 | case BTF_KIND_ARRAY: { | 602 | case BTF_KIND_ARRAY: |
622 | const struct btf_array *a = (void *)(t + 1); | 603 | btf_dump_emit_type(d, btf_array(t)->type, cont_id); |
623 | |||
624 | btf_dump_emit_type(d, a->type, cont_id); | ||
625 | break; | 604 | break; |
626 | } | ||
627 | case BTF_KIND_FWD: | 605 | case BTF_KIND_FWD: |
628 | btf_dump_emit_fwd_def(d, id, t); | 606 | btf_dump_emit_fwd_def(d, id, t); |
629 | btf_dump_printf(d, ";\n\n"); | 607 | btf_dump_printf(d, ";\n\n"); |
@@ -656,8 +634,8 @@ static void btf_dump_emit_type(struct btf_dump *d, __u32 id, __u32 cont_id) | |||
656 | * applicable | 634 | * applicable |
657 | */ | 635 | */ |
658 | if (top_level_def || t->name_off == 0) { | 636 | if (top_level_def || t->name_off == 0) { |
659 | const struct btf_member *m = (void *)(t + 1); | 637 | const struct btf_member *m = btf_members(t); |
660 | __u16 vlen = btf_vlen_of(t); | 638 | __u16 vlen = btf_vlen(t); |
661 | int i, new_cont_id; | 639 | int i, new_cont_id; |
662 | 640 | ||
663 | new_cont_id = t->name_off == 0 ? cont_id : id; | 641 | new_cont_id = t->name_off == 0 ? cont_id : id; |
@@ -678,8 +656,8 @@ static void btf_dump_emit_type(struct btf_dump *d, __u32 id, __u32 cont_id) | |||
678 | } | 656 | } |
679 | break; | 657 | break; |
680 | case BTF_KIND_FUNC_PROTO: { | 658 | case BTF_KIND_FUNC_PROTO: { |
681 | const struct btf_param *p = (void *)(t + 1); | 659 | const struct btf_param *p = btf_params(t); |
682 | __u16 vlen = btf_vlen_of(t); | 660 | __u16 vlen = btf_vlen(t); |
683 | int i; | 661 | int i; |
684 | 662 | ||
685 | btf_dump_emit_type(d, t->type, cont_id); | 663 | btf_dump_emit_type(d, t->type, cont_id); |
@@ -696,7 +674,7 @@ static void btf_dump_emit_type(struct btf_dump *d, __u32 id, __u32 cont_id) | |||
696 | static int btf_align_of(const struct btf *btf, __u32 id) | 674 | static int btf_align_of(const struct btf *btf, __u32 id) |
697 | { | 675 | { |
698 | const struct btf_type *t = btf__type_by_id(btf, id); | 676 | const struct btf_type *t = btf__type_by_id(btf, id); |
699 | __u16 kind = btf_kind_of(t); | 677 | __u16 kind = btf_kind(t); |
700 | 678 | ||
701 | switch (kind) { | 679 | switch (kind) { |
702 | case BTF_KIND_INT: | 680 | case BTF_KIND_INT: |
@@ -709,15 +687,12 @@ static int btf_align_of(const struct btf *btf, __u32 id) | |||
709 | case BTF_KIND_CONST: | 687 | case BTF_KIND_CONST: |
710 | case BTF_KIND_RESTRICT: | 688 | case BTF_KIND_RESTRICT: |
711 | return btf_align_of(btf, t->type); | 689 | return btf_align_of(btf, t->type); |
712 | case BTF_KIND_ARRAY: { | 690 | case BTF_KIND_ARRAY: |
713 | const struct btf_array *a = (void *)(t + 1); | 691 | return btf_align_of(btf, btf_array(t)->type); |
714 | |||
715 | return btf_align_of(btf, a->type); | ||
716 | } | ||
717 | case BTF_KIND_STRUCT: | 692 | case BTF_KIND_STRUCT: |
718 | case BTF_KIND_UNION: { | 693 | case BTF_KIND_UNION: { |
719 | const struct btf_member *m = (void *)(t + 1); | 694 | const struct btf_member *m = btf_members(t); |
720 | __u16 vlen = btf_vlen_of(t); | 695 | __u16 vlen = btf_vlen(t); |
721 | int i, align = 1; | 696 | int i, align = 1; |
722 | 697 | ||
723 | for (i = 0; i < vlen; i++, m++) | 698 | for (i = 0; i < vlen; i++, m++) |
@@ -726,7 +701,7 @@ static int btf_align_of(const struct btf *btf, __u32 id) | |||
726 | return align; | 701 | return align; |
727 | } | 702 | } |
728 | default: | 703 | default: |
729 | pr_warning("unsupported BTF_KIND:%u\n", btf_kind_of(t)); | 704 | pr_warning("unsupported BTF_KIND:%u\n", btf_kind(t)); |
730 | return 1; | 705 | return 1; |
731 | } | 706 | } |
732 | } | 707 | } |
@@ -737,20 +712,18 @@ static bool btf_is_struct_packed(const struct btf *btf, __u32 id, | |||
737 | const struct btf_member *m; | 712 | const struct btf_member *m; |
738 | int align, i, bit_sz; | 713 | int align, i, bit_sz; |
739 | __u16 vlen; | 714 | __u16 vlen; |
740 | bool kflag; | ||
741 | 715 | ||
742 | align = btf_align_of(btf, id); | 716 | align = btf_align_of(btf, id); |
743 | /* size of a non-packed struct has to be a multiple of its alignment*/ | 717 | /* size of a non-packed struct has to be a multiple of its alignment*/ |
744 | if (t->size % align) | 718 | if (t->size % align) |
745 | return true; | 719 | return true; |
746 | 720 | ||
747 | m = (void *)(t + 1); | 721 | m = btf_members(t); |
748 | kflag = btf_kflag_of(t); | 722 | vlen = btf_vlen(t); |
749 | vlen = btf_vlen_of(t); | ||
750 | /* all non-bitfield fields have to be naturally aligned */ | 723 | /* all non-bitfield fields have to be naturally aligned */ |
751 | for (i = 0; i < vlen; i++, m++) { | 724 | for (i = 0; i < vlen; i++, m++) { |
752 | align = btf_align_of(btf, m->type); | 725 | align = btf_align_of(btf, m->type); |
753 | bit_sz = kflag ? BTF_MEMBER_BITFIELD_SIZE(m->offset) : 0; | 726 | bit_sz = btf_member_bitfield_size(t, i); |
754 | if (bit_sz == 0 && m->offset % (8 * align) != 0) | 727 | if (bit_sz == 0 && m->offset % (8 * align) != 0) |
755 | return true; | 728 | return true; |
756 | } | 729 | } |
@@ -807,7 +780,7 @@ static void btf_dump_emit_struct_fwd(struct btf_dump *d, __u32 id, | |||
807 | const struct btf_type *t) | 780 | const struct btf_type *t) |
808 | { | 781 | { |
809 | btf_dump_printf(d, "%s %s", | 782 | btf_dump_printf(d, "%s %s", |
810 | btf_kind_of(t) == BTF_KIND_STRUCT ? "struct" : "union", | 783 | btf_is_struct(t) ? "struct" : "union", |
811 | btf_dump_type_name(d, id)); | 784 | btf_dump_type_name(d, id)); |
812 | } | 785 | } |
813 | 786 | ||
@@ -816,12 +789,11 @@ static void btf_dump_emit_struct_def(struct btf_dump *d, | |||
816 | const struct btf_type *t, | 789 | const struct btf_type *t, |
817 | int lvl) | 790 | int lvl) |
818 | { | 791 | { |
819 | const struct btf_member *m = (void *)(t + 1); | 792 | const struct btf_member *m = btf_members(t); |
820 | bool kflag = btf_kflag_of(t), is_struct; | 793 | bool is_struct = btf_is_struct(t); |
821 | int align, i, packed, off = 0; | 794 | int align, i, packed, off = 0; |
822 | __u16 vlen = btf_vlen_of(t); | 795 | __u16 vlen = btf_vlen(t); |
823 | 796 | ||
824 | is_struct = btf_kind_of(t) == BTF_KIND_STRUCT; | ||
825 | packed = is_struct ? btf_is_struct_packed(d->btf, id, t) : 0; | 797 | packed = is_struct ? btf_is_struct_packed(d->btf, id, t) : 0; |
826 | align = packed ? 1 : btf_align_of(d->btf, id); | 798 | align = packed ? 1 : btf_align_of(d->btf, id); |
827 | 799 | ||
@@ -835,8 +807,8 @@ static void btf_dump_emit_struct_def(struct btf_dump *d, | |||
835 | int m_off, m_sz; | 807 | int m_off, m_sz; |
836 | 808 | ||
837 | fname = btf_name_of(d, m->name_off); | 809 | fname = btf_name_of(d, m->name_off); |
838 | m_sz = kflag ? BTF_MEMBER_BITFIELD_SIZE(m->offset) : 0; | 810 | m_sz = btf_member_bitfield_size(t, i); |
839 | m_off = kflag ? BTF_MEMBER_BIT_OFFSET(m->offset) : m->offset; | 811 | m_off = btf_member_bit_offset(t, i); |
840 | align = packed ? 1 : btf_align_of(d->btf, m->type); | 812 | align = packed ? 1 : btf_align_of(d->btf, m->type); |
841 | 813 | ||
842 | btf_dump_emit_bit_padding(d, off, m_off, m_sz, align, lvl + 1); | 814 | btf_dump_emit_bit_padding(d, off, m_off, m_sz, align, lvl + 1); |
@@ -870,8 +842,8 @@ static void btf_dump_emit_enum_def(struct btf_dump *d, __u32 id, | |||
870 | const struct btf_type *t, | 842 | const struct btf_type *t, |
871 | int lvl) | 843 | int lvl) |
872 | { | 844 | { |
873 | const struct btf_enum *v = (void *)(t+1); | 845 | const struct btf_enum *v = btf_enum(t); |
874 | __u16 vlen = btf_vlen_of(t); | 846 | __u16 vlen = btf_vlen(t); |
875 | const char *name; | 847 | const char *name; |
876 | size_t dup_cnt; | 848 | size_t dup_cnt; |
877 | int i; | 849 | int i; |
@@ -905,7 +877,7 @@ static void btf_dump_emit_fwd_def(struct btf_dump *d, __u32 id, | |||
905 | { | 877 | { |
906 | const char *name = btf_dump_type_name(d, id); | 878 | const char *name = btf_dump_type_name(d, id); |
907 | 879 | ||
908 | if (btf_kflag_of(t)) | 880 | if (btf_kflag(t)) |
909 | btf_dump_printf(d, "union %s", name); | 881 | btf_dump_printf(d, "union %s", name); |
910 | else | 882 | else |
911 | btf_dump_printf(d, "struct %s", name); | 883 | btf_dump_printf(d, "struct %s", name); |
@@ -987,7 +959,6 @@ static void btf_dump_emit_type_decl(struct btf_dump *d, __u32 id, | |||
987 | struct id_stack decl_stack; | 959 | struct id_stack decl_stack; |
988 | const struct btf_type *t; | 960 | const struct btf_type *t; |
989 | int err, stack_start; | 961 | int err, stack_start; |
990 | __u16 kind; | ||
991 | 962 | ||
992 | stack_start = d->decl_stack_cnt; | 963 | stack_start = d->decl_stack_cnt; |
993 | for (;;) { | 964 | for (;;) { |
@@ -1008,8 +979,7 @@ static void btf_dump_emit_type_decl(struct btf_dump *d, __u32 id, | |||
1008 | break; | 979 | break; |
1009 | 980 | ||
1010 | t = btf__type_by_id(d->btf, id); | 981 | t = btf__type_by_id(d->btf, id); |
1011 | kind = btf_kind_of(t); | 982 | switch (btf_kind(t)) { |
1012 | switch (kind) { | ||
1013 | case BTF_KIND_PTR: | 983 | case BTF_KIND_PTR: |
1014 | case BTF_KIND_VOLATILE: | 984 | case BTF_KIND_VOLATILE: |
1015 | case BTF_KIND_CONST: | 985 | case BTF_KIND_CONST: |
@@ -1017,12 +987,9 @@ static void btf_dump_emit_type_decl(struct btf_dump *d, __u32 id, | |||
1017 | case BTF_KIND_FUNC_PROTO: | 987 | case BTF_KIND_FUNC_PROTO: |
1018 | id = t->type; | 988 | id = t->type; |
1019 | break; | 989 | break; |
1020 | case BTF_KIND_ARRAY: { | 990 | case BTF_KIND_ARRAY: |
1021 | const struct btf_array *a = (void *)(t + 1); | 991 | id = btf_array(t)->type; |
1022 | |||
1023 | id = a->type; | ||
1024 | break; | 992 | break; |
1025 | } | ||
1026 | case BTF_KIND_INT: | 993 | case BTF_KIND_INT: |
1027 | case BTF_KIND_ENUM: | 994 | case BTF_KIND_ENUM: |
1028 | case BTF_KIND_FWD: | 995 | case BTF_KIND_FWD: |
@@ -1032,7 +999,7 @@ static void btf_dump_emit_type_decl(struct btf_dump *d, __u32 id, | |||
1032 | goto done; | 999 | goto done; |
1033 | default: | 1000 | default: |
1034 | pr_warning("unexpected type in decl chain, kind:%u, id:[%u]\n", | 1001 | pr_warning("unexpected type in decl chain, kind:%u, id:[%u]\n", |
1035 | kind, id); | 1002 | btf_kind(t), id); |
1036 | goto done; | 1003 | goto done; |
1037 | } | 1004 | } |
1038 | } | 1005 | } |
@@ -1070,7 +1037,7 @@ static void btf_dump_emit_mods(struct btf_dump *d, struct id_stack *decl_stack) | |||
1070 | id = decl_stack->ids[decl_stack->cnt - 1]; | 1037 | id = decl_stack->ids[decl_stack->cnt - 1]; |
1071 | t = btf__type_by_id(d->btf, id); | 1038 | t = btf__type_by_id(d->btf, id); |
1072 | 1039 | ||
1073 | switch (btf_kind_of(t)) { | 1040 | switch (btf_kind(t)) { |
1074 | case BTF_KIND_VOLATILE: | 1041 | case BTF_KIND_VOLATILE: |
1075 | btf_dump_printf(d, "volatile "); | 1042 | btf_dump_printf(d, "volatile "); |
1076 | break; | 1043 | break; |
@@ -1087,20 +1054,6 @@ static void btf_dump_emit_mods(struct btf_dump *d, struct id_stack *decl_stack) | |||
1087 | } | 1054 | } |
1088 | } | 1055 | } |
1089 | 1056 | ||
1090 | static bool btf_is_mod_kind(const struct btf *btf, __u32 id) | ||
1091 | { | ||
1092 | const struct btf_type *t = btf__type_by_id(btf, id); | ||
1093 | |||
1094 | switch (btf_kind_of(t)) { | ||
1095 | case BTF_KIND_VOLATILE: | ||
1096 | case BTF_KIND_CONST: | ||
1097 | case BTF_KIND_RESTRICT: | ||
1098 | return true; | ||
1099 | default: | ||
1100 | return false; | ||
1101 | } | ||
1102 | } | ||
1103 | |||
1104 | static void btf_dump_emit_name(const struct btf_dump *d, | 1057 | static void btf_dump_emit_name(const struct btf_dump *d, |
1105 | const char *name, bool last_was_ptr) | 1058 | const char *name, bool last_was_ptr) |
1106 | { | 1059 | { |
@@ -1139,7 +1092,7 @@ static void btf_dump_emit_type_chain(struct btf_dump *d, | |||
1139 | } | 1092 | } |
1140 | 1093 | ||
1141 | t = btf__type_by_id(d->btf, id); | 1094 | t = btf__type_by_id(d->btf, id); |
1142 | kind = btf_kind_of(t); | 1095 | kind = btf_kind(t); |
1143 | 1096 | ||
1144 | switch (kind) { | 1097 | switch (kind) { |
1145 | case BTF_KIND_INT: | 1098 | case BTF_KIND_INT: |
@@ -1185,7 +1138,7 @@ static void btf_dump_emit_type_chain(struct btf_dump *d, | |||
1185 | btf_dump_printf(d, " restrict"); | 1138 | btf_dump_printf(d, " restrict"); |
1186 | break; | 1139 | break; |
1187 | case BTF_KIND_ARRAY: { | 1140 | case BTF_KIND_ARRAY: { |
1188 | const struct btf_array *a = (void *)(t + 1); | 1141 | const struct btf_array *a = btf_array(t); |
1189 | const struct btf_type *next_t; | 1142 | const struct btf_type *next_t; |
1190 | __u32 next_id; | 1143 | __u32 next_id; |
1191 | bool multidim; | 1144 | bool multidim; |
@@ -1201,7 +1154,8 @@ static void btf_dump_emit_type_chain(struct btf_dump *d, | |||
1201 | */ | 1154 | */ |
1202 | while (decls->cnt) { | 1155 | while (decls->cnt) { |
1203 | next_id = decls->ids[decls->cnt - 1]; | 1156 | next_id = decls->ids[decls->cnt - 1]; |
1204 | if (btf_is_mod_kind(d->btf, next_id)) | 1157 | next_t = btf__type_by_id(d->btf, next_id); |
1158 | if (btf_is_mod(next_t)) | ||
1205 | decls->cnt--; | 1159 | decls->cnt--; |
1206 | else | 1160 | else |
1207 | break; | 1161 | break; |
@@ -1214,7 +1168,7 @@ static void btf_dump_emit_type_chain(struct btf_dump *d, | |||
1214 | } | 1168 | } |
1215 | 1169 | ||
1216 | next_t = btf__type_by_id(d->btf, next_id); | 1170 | next_t = btf__type_by_id(d->btf, next_id); |
1217 | multidim = btf_kind_of(next_t) == BTF_KIND_ARRAY; | 1171 | multidim = btf_is_array(next_t); |
1218 | /* we need space if we have named non-pointer */ | 1172 | /* we need space if we have named non-pointer */ |
1219 | if (fname[0] && !last_was_ptr) | 1173 | if (fname[0] && !last_was_ptr) |
1220 | btf_dump_printf(d, " "); | 1174 | btf_dump_printf(d, " "); |
@@ -1228,8 +1182,8 @@ static void btf_dump_emit_type_chain(struct btf_dump *d, | |||
1228 | return; | 1182 | return; |
1229 | } | 1183 | } |
1230 | case BTF_KIND_FUNC_PROTO: { | 1184 | case BTF_KIND_FUNC_PROTO: { |
1231 | const struct btf_param *p = (void *)(t + 1); | 1185 | const struct btf_param *p = btf_params(t); |
1232 | __u16 vlen = btf_vlen_of(t); | 1186 | __u16 vlen = btf_vlen(t); |
1233 | int i; | 1187 | int i; |
1234 | 1188 | ||
1235 | btf_dump_emit_mods(d, decls); | 1189 | btf_dump_emit_mods(d, decls); |
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index ead915aec349..8fc62b6b1cd6 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c | |||
@@ -1049,9 +1049,9 @@ static bool get_map_field_int(const char *map_name, const struct btf *btf, | |||
1049 | const struct btf_array *arr_info; | 1049 | const struct btf_array *arr_info; |
1050 | const struct btf_type *arr_t; | 1050 | const struct btf_type *arr_t; |
1051 | 1051 | ||
1052 | if (BTF_INFO_KIND(t->info) != BTF_KIND_PTR) { | 1052 | if (!btf_is_ptr(t)) { |
1053 | pr_warning("map '%s': attr '%s': expected PTR, got %u.\n", | 1053 | pr_warning("map '%s': attr '%s': expected PTR, got %u.\n", |
1054 | map_name, name, BTF_INFO_KIND(t->info)); | 1054 | map_name, name, btf_kind(t)); |
1055 | return false; | 1055 | return false; |
1056 | } | 1056 | } |
1057 | 1057 | ||
@@ -1061,12 +1061,12 @@ static bool get_map_field_int(const char *map_name, const struct btf *btf, | |||
1061 | map_name, name, t->type); | 1061 | map_name, name, t->type); |
1062 | return false; | 1062 | return false; |
1063 | } | 1063 | } |
1064 | if (BTF_INFO_KIND(arr_t->info) != BTF_KIND_ARRAY) { | 1064 | if (!btf_is_array(arr_t)) { |
1065 | pr_warning("map '%s': attr '%s': expected ARRAY, got %u.\n", | 1065 | pr_warning("map '%s': attr '%s': expected ARRAY, got %u.\n", |
1066 | map_name, name, BTF_INFO_KIND(arr_t->info)); | 1066 | map_name, name, btf_kind(arr_t)); |
1067 | return false; | 1067 | return false; |
1068 | } | 1068 | } |
1069 | arr_info = (const void *)(arr_t + 1); | 1069 | arr_info = btf_array(arr_t); |
1070 | *res = arr_info->nelems; | 1070 | *res = arr_info->nelems; |
1071 | return true; | 1071 | return true; |
1072 | } | 1072 | } |
@@ -1084,11 +1084,11 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj, | |||
1084 | struct bpf_map *map; | 1084 | struct bpf_map *map; |
1085 | int vlen, i; | 1085 | int vlen, i; |
1086 | 1086 | ||
1087 | vi = (const struct btf_var_secinfo *)(const void *)(sec + 1) + var_idx; | 1087 | vi = btf_var_secinfos(sec) + var_idx; |
1088 | var = btf__type_by_id(obj->btf, vi->type); | 1088 | var = btf__type_by_id(obj->btf, vi->type); |
1089 | var_extra = (const void *)(var + 1); | 1089 | var_extra = btf_var(var); |
1090 | map_name = btf__name_by_offset(obj->btf, var->name_off); | 1090 | map_name = btf__name_by_offset(obj->btf, var->name_off); |
1091 | vlen = BTF_INFO_VLEN(var->info); | 1091 | vlen = btf_vlen(var); |
1092 | 1092 | ||
1093 | if (map_name == NULL || map_name[0] == '\0') { | 1093 | if (map_name == NULL || map_name[0] == '\0') { |
1094 | pr_warning("map #%d: empty name.\n", var_idx); | 1094 | pr_warning("map #%d: empty name.\n", var_idx); |
@@ -1098,9 +1098,9 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj, | |||
1098 | pr_warning("map '%s' BTF data is corrupted.\n", map_name); | 1098 | pr_warning("map '%s' BTF data is corrupted.\n", map_name); |
1099 | return -EINVAL; | 1099 | return -EINVAL; |
1100 | } | 1100 | } |
1101 | if (BTF_INFO_KIND(var->info) != BTF_KIND_VAR) { | 1101 | if (!btf_is_var(var)) { |
1102 | pr_warning("map '%s': unexpected var kind %u.\n", | 1102 | pr_warning("map '%s': unexpected var kind %u.\n", |
1103 | map_name, BTF_INFO_KIND(var->info)); | 1103 | map_name, btf_kind(var)); |
1104 | return -EINVAL; | 1104 | return -EINVAL; |
1105 | } | 1105 | } |
1106 | if (var_extra->linkage != BTF_VAR_GLOBAL_ALLOCATED && | 1106 | if (var_extra->linkage != BTF_VAR_GLOBAL_ALLOCATED && |
@@ -1111,9 +1111,9 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj, | |||
1111 | } | 1111 | } |
1112 | 1112 | ||
1113 | def = skip_mods_and_typedefs(obj->btf, var->type); | 1113 | def = skip_mods_and_typedefs(obj->btf, var->type); |
1114 | if (BTF_INFO_KIND(def->info) != BTF_KIND_STRUCT) { | 1114 | if (!btf_is_struct(def)) { |
1115 | pr_warning("map '%s': unexpected def kind %u.\n", | 1115 | pr_warning("map '%s': unexpected def kind %u.\n", |
1116 | map_name, BTF_INFO_KIND(var->info)); | 1116 | map_name, btf_kind(var)); |
1117 | return -EINVAL; | 1117 | return -EINVAL; |
1118 | } | 1118 | } |
1119 | if (def->size > vi->size) { | 1119 | if (def->size > vi->size) { |
@@ -1136,8 +1136,8 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj, | |||
1136 | pr_debug("map '%s': at sec_idx %d, offset %zu.\n", | 1136 | pr_debug("map '%s': at sec_idx %d, offset %zu.\n", |
1137 | map_name, map->sec_idx, map->sec_offset); | 1137 | map_name, map->sec_idx, map->sec_offset); |
1138 | 1138 | ||
1139 | vlen = BTF_INFO_VLEN(def->info); | 1139 | vlen = btf_vlen(def); |
1140 | m = (const void *)(def + 1); | 1140 | m = btf_members(def); |
1141 | for (i = 0; i < vlen; i++, m++) { | 1141 | for (i = 0; i < vlen; i++, m++) { |
1142 | const char *name = btf__name_by_offset(obj->btf, m->name_off); | 1142 | const char *name = btf__name_by_offset(obj->btf, m->name_off); |
1143 | 1143 | ||
@@ -1187,9 +1187,9 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj, | |||
1187 | map_name, m->type); | 1187 | map_name, m->type); |
1188 | return -EINVAL; | 1188 | return -EINVAL; |
1189 | } | 1189 | } |
1190 | if (BTF_INFO_KIND(t->info) != BTF_KIND_PTR) { | 1190 | if (!btf_is_ptr(t)) { |
1191 | pr_warning("map '%s': key spec is not PTR: %u.\n", | 1191 | pr_warning("map '%s': key spec is not PTR: %u.\n", |
1192 | map_name, BTF_INFO_KIND(t->info)); | 1192 | map_name, btf_kind(t)); |
1193 | return -EINVAL; | 1193 | return -EINVAL; |
1194 | } | 1194 | } |
1195 | sz = btf__resolve_size(obj->btf, t->type); | 1195 | sz = btf__resolve_size(obj->btf, t->type); |
@@ -1230,9 +1230,9 @@ static int bpf_object__init_user_btf_map(struct bpf_object *obj, | |||
1230 | map_name, m->type); | 1230 | map_name, m->type); |
1231 | return -EINVAL; | 1231 | return -EINVAL; |
1232 | } | 1232 | } |
1233 | if (BTF_INFO_KIND(t->info) != BTF_KIND_PTR) { | 1233 | if (!btf_is_ptr(t)) { |
1234 | pr_warning("map '%s': value spec is not PTR: %u.\n", | 1234 | pr_warning("map '%s': value spec is not PTR: %u.\n", |
1235 | map_name, BTF_INFO_KIND(t->info)); | 1235 | map_name, btf_kind(t)); |
1236 | return -EINVAL; | 1236 | return -EINVAL; |
1237 | } | 1237 | } |
1238 | sz = btf__resolve_size(obj->btf, t->type); | 1238 | sz = btf__resolve_size(obj->btf, t->type); |
@@ -1293,7 +1293,7 @@ static int bpf_object__init_user_btf_maps(struct bpf_object *obj, bool strict) | |||
1293 | nr_types = btf__get_nr_types(obj->btf); | 1293 | nr_types = btf__get_nr_types(obj->btf); |
1294 | for (i = 1; i <= nr_types; i++) { | 1294 | for (i = 1; i <= nr_types; i++) { |
1295 | t = btf__type_by_id(obj->btf, i); | 1295 | t = btf__type_by_id(obj->btf, i); |
1296 | if (BTF_INFO_KIND(t->info) != BTF_KIND_DATASEC) | 1296 | if (!btf_is_datasec(t)) |
1297 | continue; | 1297 | continue; |
1298 | name = btf__name_by_offset(obj->btf, t->name_off); | 1298 | name = btf__name_by_offset(obj->btf, t->name_off); |
1299 | if (strcmp(name, MAPS_ELF_SEC) == 0) { | 1299 | if (strcmp(name, MAPS_ELF_SEC) == 0) { |
@@ -1307,7 +1307,7 @@ static int bpf_object__init_user_btf_maps(struct bpf_object *obj, bool strict) | |||
1307 | return -ENOENT; | 1307 | return -ENOENT; |
1308 | } | 1308 | } |
1309 | 1309 | ||
1310 | vlen = BTF_INFO_VLEN(sec->info); | 1310 | vlen = btf_vlen(sec); |
1311 | for (i = 0; i < vlen; i++) { | 1311 | for (i = 0; i < vlen; i++) { |
1312 | err = bpf_object__init_user_btf_map(obj, sec, i, | 1312 | err = bpf_object__init_user_btf_map(obj, sec, i, |
1313 | obj->efile.btf_maps_shndx, | 1313 | obj->efile.btf_maps_shndx, |
@@ -1368,24 +1368,22 @@ static void bpf_object__sanitize_btf(struct bpf_object *obj) | |||
1368 | struct btf *btf = obj->btf; | 1368 | struct btf *btf = obj->btf; |
1369 | struct btf_type *t; | 1369 | struct btf_type *t; |
1370 | int i, j, vlen; | 1370 | int i, j, vlen; |
1371 | __u16 kind; | ||
1372 | 1371 | ||
1373 | if (!obj->btf || (has_func && has_datasec)) | 1372 | if (!obj->btf || (has_func && has_datasec)) |
1374 | return; | 1373 | return; |
1375 | 1374 | ||
1376 | for (i = 1; i <= btf__get_nr_types(btf); i++) { | 1375 | for (i = 1; i <= btf__get_nr_types(btf); i++) { |
1377 | t = (struct btf_type *)btf__type_by_id(btf, i); | 1376 | t = (struct btf_type *)btf__type_by_id(btf, i); |
1378 | kind = BTF_INFO_KIND(t->info); | ||
1379 | 1377 | ||
1380 | if (!has_datasec && kind == BTF_KIND_VAR) { | 1378 | if (!has_datasec && btf_is_var(t)) { |
1381 | /* replace VAR with INT */ | 1379 | /* replace VAR with INT */ |
1382 | t->info = BTF_INFO_ENC(BTF_KIND_INT, 0, 0); | 1380 | t->info = BTF_INFO_ENC(BTF_KIND_INT, 0, 0); |
1383 | t->size = sizeof(int); | 1381 | t->size = sizeof(int); |
1384 | *(int *)(t+1) = BTF_INT_ENC(0, 0, 32); | 1382 | *(int *)(t + 1) = BTF_INT_ENC(0, 0, 32); |
1385 | } else if (!has_datasec && kind == BTF_KIND_DATASEC) { | 1383 | } else if (!has_datasec && btf_is_datasec(t)) { |
1386 | /* replace DATASEC with STRUCT */ | 1384 | /* replace DATASEC with STRUCT */ |
1387 | struct btf_var_secinfo *v = (void *)(t + 1); | 1385 | const struct btf_var_secinfo *v = btf_var_secinfos(t); |
1388 | struct btf_member *m = (void *)(t + 1); | 1386 | struct btf_member *m = btf_members(t); |
1389 | struct btf_type *vt; | 1387 | struct btf_type *vt; |
1390 | char *name; | 1388 | char *name; |
1391 | 1389 | ||
@@ -1396,7 +1394,7 @@ static void bpf_object__sanitize_btf(struct bpf_object *obj) | |||
1396 | name++; | 1394 | name++; |
1397 | } | 1395 | } |
1398 | 1396 | ||
1399 | vlen = BTF_INFO_VLEN(t->info); | 1397 | vlen = btf_vlen(t); |
1400 | t->info = BTF_INFO_ENC(BTF_KIND_STRUCT, 0, vlen); | 1398 | t->info = BTF_INFO_ENC(BTF_KIND_STRUCT, 0, vlen); |
1401 | for (j = 0; j < vlen; j++, v++, m++) { | 1399 | for (j = 0; j < vlen; j++, v++, m++) { |
1402 | /* order of field assignments is important */ | 1400 | /* order of field assignments is important */ |
@@ -1406,12 +1404,12 @@ static void bpf_object__sanitize_btf(struct bpf_object *obj) | |||
1406 | vt = (void *)btf__type_by_id(btf, v->type); | 1404 | vt = (void *)btf__type_by_id(btf, v->type); |
1407 | m->name_off = vt->name_off; | 1405 | m->name_off = vt->name_off; |
1408 | } | 1406 | } |
1409 | } else if (!has_func && kind == BTF_KIND_FUNC_PROTO) { | 1407 | } else if (!has_func && btf_is_func_proto(t)) { |
1410 | /* replace FUNC_PROTO with ENUM */ | 1408 | /* replace FUNC_PROTO with ENUM */ |
1411 | vlen = BTF_INFO_VLEN(t->info); | 1409 | vlen = btf_vlen(t); |
1412 | t->info = BTF_INFO_ENC(BTF_KIND_ENUM, 0, vlen); | 1410 | t->info = BTF_INFO_ENC(BTF_KIND_ENUM, 0, vlen); |
1413 | t->size = sizeof(__u32); /* kernel enforced */ | 1411 | t->size = sizeof(__u32); /* kernel enforced */ |
1414 | } else if (!has_func && kind == BTF_KIND_FUNC) { | 1412 | } else if (!has_func && btf_is_func(t)) { |
1415 | /* replace FUNC with TYPEDEF */ | 1413 | /* replace FUNC with TYPEDEF */ |
1416 | t->info = BTF_INFO_ENC(BTF_KIND_TYPEDEF, 0, 0); | 1414 | t->info = BTF_INFO_ENC(BTF_KIND_TYPEDEF, 0, 0); |
1417 | } | 1415 | } |