@@ -291,6 +291,7 @@ static int btf_type_size(const struct btf_type *t)
291
291
case BTF_KIND_PTR :
292
292
case BTF_KIND_TYPEDEF :
293
293
case BTF_KIND_FUNC :
294
+ case BTF_KIND_FLOAT :
294
295
return base_size ;
295
296
case BTF_KIND_INT :
296
297
return base_size + sizeof (__u32 );
@@ -338,6 +339,7 @@ static int btf_bswap_type_rest(struct btf_type *t)
338
339
case BTF_KIND_PTR :
339
340
case BTF_KIND_TYPEDEF :
340
341
case BTF_KIND_FUNC :
342
+ case BTF_KIND_FLOAT :
341
343
return 0 ;
342
344
case BTF_KIND_INT :
343
345
* (__u32 * )(t + 1 ) = bswap_32 (* (__u32 * )(t + 1 ));
@@ -578,6 +580,7 @@ __s64 btf__resolve_size(const struct btf *btf, __u32 type_id)
578
580
case BTF_KIND_UNION :
579
581
case BTF_KIND_ENUM :
580
582
case BTF_KIND_DATASEC :
583
+ case BTF_KIND_FLOAT :
581
584
size = t -> size ;
582
585
goto done ;
583
586
case BTF_KIND_PTR :
@@ -621,6 +624,7 @@ int btf__align_of(const struct btf *btf, __u32 id)
621
624
switch (kind ) {
622
625
case BTF_KIND_INT :
623
626
case BTF_KIND_ENUM :
627
+ case BTF_KIND_FLOAT :
624
628
return min (btf_ptr_sz (btf ), (size_t )t -> size );
625
629
case BTF_KIND_PTR :
626
630
return btf_ptr_sz (btf );
@@ -1756,6 +1760,47 @@ int btf__add_int(struct btf *btf, const char *name, size_t byte_sz, int encoding
1756
1760
return btf_commit_type (btf , sz );
1757
1761
}
1758
1762
1763
+ /*
1764
+ * Append new BTF_KIND_FLOAT type with:
1765
+ * - *name* - non-empty, non-NULL type name;
1766
+ * - *sz* - size of the type, in bytes;
1767
+ * Returns:
1768
+ * - >0, type ID of newly added BTF type;
1769
+ * - <0, on error.
1770
+ */
1771
+ int btf__add_float (struct btf * btf , const char * name , size_t byte_sz )
1772
+ {
1773
+ struct btf_type * t ;
1774
+ int sz , name_off ;
1775
+
1776
+ /* non-empty name */
1777
+ if (!name || !name [0 ])
1778
+ return - EINVAL ;
1779
+
1780
+ /* byte_sz must be one of the explicitly allowed values */
1781
+ if (byte_sz != 2 && byte_sz != 4 && byte_sz != 8 && byte_sz != 12 &&
1782
+ byte_sz != 16 )
1783
+ return - EINVAL ;
1784
+
1785
+ if (btf_ensure_modifiable (btf ))
1786
+ return - ENOMEM ;
1787
+
1788
+ sz = sizeof (struct btf_type );
1789
+ t = btf_add_type_mem (btf , sz );
1790
+ if (!t )
1791
+ return - ENOMEM ;
1792
+
1793
+ name_off = btf__add_str (btf , name );
1794
+ if (name_off < 0 )
1795
+ return name_off ;
1796
+
1797
+ t -> name_off = name_off ;
1798
+ t -> info = btf_type_info (BTF_KIND_FLOAT , 0 , 0 );
1799
+ t -> size = byte_sz ;
1800
+
1801
+ return btf_commit_type (btf , sz );
1802
+ }
1803
+
1759
1804
/* it's completely legal to append BTF types with type IDs pointing forward to
1760
1805
* types that haven't been appended yet, so we only make sure that id looks
1761
1806
* sane, we can't guarantee that ID will always be valid
@@ -3626,6 +3671,7 @@ static int btf_dedup_prep(struct btf_dedup *d)
3626
3671
case BTF_KIND_FWD :
3627
3672
case BTF_KIND_TYPEDEF :
3628
3673
case BTF_KIND_FUNC :
3674
+ case BTF_KIND_FLOAT :
3629
3675
h = btf_hash_common (t );
3630
3676
break ;
3631
3677
case BTF_KIND_INT :
@@ -3722,6 +3768,7 @@ static int btf_dedup_prim_type(struct btf_dedup *d, __u32 type_id)
3722
3768
break ;
3723
3769
3724
3770
case BTF_KIND_FWD :
3771
+ case BTF_KIND_FLOAT :
3725
3772
h = btf_hash_common (t );
3726
3773
for_each_dedup_cand (d , hash_entry , h ) {
3727
3774
cand_id = (__u32 )(long )hash_entry -> value ;
@@ -3983,6 +4030,7 @@ static int btf_dedup_is_equiv(struct btf_dedup *d, __u32 cand_id,
3983
4030
return btf_compat_enum (cand_type , canon_type );
3984
4031
3985
4032
case BTF_KIND_FWD :
4033
+ case BTF_KIND_FLOAT :
3986
4034
return btf_equal_common (cand_type , canon_type );
3987
4035
3988
4036
case BTF_KIND_CONST :
@@ -4479,6 +4527,7 @@ static int btf_dedup_remap_type(struct btf_dedup *d, __u32 type_id)
4479
4527
switch (btf_kind (t )) {
4480
4528
case BTF_KIND_INT :
4481
4529
case BTF_KIND_ENUM :
4530
+ case BTF_KIND_FLOAT :
4482
4531
break ;
4483
4532
4484
4533
case BTF_KIND_FWD :
0 commit comments