Re: [PATCH dwarves] btf_loader: Fix warnings due to type permutation

Alan Maguire <[email protected]>
Newsgroups org.kernel.vger.dwarves
Message-ID <[email protected]>
On 26/02/2026 07:58, Alan Maguire wrote:
> The BTF loader implicitly relied on the fact that decl tags appeared
> after the types they refer to, since it looks those references up
> and adds attributes to them.  As a result, when a decl tag appears
> before the type it references, we get a warning of the form:
> 
> WARNING: BTF_KIND_DECL_TAG for unknown BTF id 61909
> 
> We see this since BTF permutation, but regardless BTF order should not
> matter.  Other types do not rely on looking up their tag references,
> so this needs to be fixed for decl tags specifically.
> 
> To solve this, simply create tags for all other types first,
> then handle decl tags.
> 
> Signed-off-by: Alan Maguire <[email protected]>

Given how annoying these messages are, and that they occur for
both pahole and pfunct using the BTF loader, I'm planning on
applying this shortly, so if anyone sees an issue, let me know. 

Thanks

Alan

> ---
>  btf_loader.c | 27 +++++++++++++++++++++++----
>  1 file changed, 23 insertions(+), 4 deletions(-)
> 
> diff --git a/btf_loader.c b/btf_loader.c
> index 64ea680..b591219 100644
> --- a/btf_loader.c
> +++ b/btf_loader.c
> @@ -505,12 +505,13 @@ static int process_decl_tag(struct cu *cu, const struct btf_type *tp)
>  
>  static int btf__load_types(struct btf *btf, struct cu *cu)
>  {
> -	uint32_t type_index;
> +	const struct btf_type *type_ptr;
> +	uint32_t type_index, type;
>  	int err;
>  
>  	for (type_index = 1; type_index < btf__type_cnt(btf); type_index++) {
> -		const struct btf_type *type_ptr = btf__type_by_id(btf, type_index);
> -		uint32_t type = btf_kind(type_ptr);
> +		type_ptr = btf__type_by_id(btf, type_index);
> +		type = btf_kind(type_ptr);
>  
>  		switch (type) {
>  		case BTF_KIND_INT:
> @@ -572,7 +573,9 @@ static int btf__load_types(struct btf *btf, struct cu *cu)
>  			err = create_new_float_type(cu, type_ptr, type_index);
>  			break;
>  		case BTF_KIND_DECL_TAG:
> -			err = process_decl_tag(cu, type_ptr);
> +			/* decl tags will be handled below when other types are
> +			 * loaded.
> +			 */
>  			break;
>  		default:
>  			fprintf(stderr, "BTF: idx: %d, Unknown kind %d\n", type_index, type);
> @@ -584,6 +587,22 @@ static int btf__load_types(struct btf *btf, struct cu *cu)
>  		if (err < 0)
>  			return err;
>  	}
> +	/*
> +	 * For decl tags we add attributes to the tags associated with the types they
> +	 * refer to.  Now that other types have been processed, we can do this.
> +	 */
> +	for (type_index = 1; type_index < btf__type_cnt(btf); type_index++) {
> +		type_ptr = btf__type_by_id(btf, type_index);
> +		type = btf_kind(type_ptr);
> +
> +		if (type != BTF_KIND_DECL_TAG)
> +			continue;
> +
> +		err = process_decl_tag(cu, type_ptr);
> +		if (err < 0)
> +			return err;
> +	}
> +
>  	return 0;
>  }
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.