Re: [PAHOLE v5 1/5] btf_loader: Handle decl tag component_idx for parameters

Arnaldo Carvalho de Melo <[email protected]> Thu, 18 Jun 2026 10:27:14 -0300
Newsgroups org.kernel.vger.dwarves,org.kernel.vger.bpf
Message-ID <ajPyMp4sz8-sms76@x1>
On Thu, Jun 18, 2026 at 12:46:50AM -0400, Emil Tsalapatis wrote:
> On Wed Jun 17, 2026 at 8:57 PM EDT, Vineet Gupta wrote:
> > From: Alan Maguire <[email protected]>
> >
> > A BTF_KIND_DECL_TAG with a non-negative component_idx applies to a
> > specific function parameter (or struct/union member), not to the
> > function itself. btf_loader.c however attached every decl tag to the
> > type named by btf_type->type, so parameter decl tags were recorded on
> > the function rather than on the parameter, and pfunct never printed
> > them with the parameter.
> >
> > Resolve a non-negative component_idx to the corresponding parameter via
> > new helpers ftype__parameter()/function__parameter(), and attach the
> > tag there. Teach the pretty printer to emit a parameter's attributes by
> > factoring the function-level attribute loop into tag__attributes_fprintf()
> > and calling it from ftype__fprintf_parms() for each parameter.
> >
> > Signed-off-by: Alan Maguire <[email protected]>
> > Signed-off-by: Vineet Gupta <[email protected]>
> 
> With one nit:
> 
> Reviewed-by: Emil Tsalapatis <[email protected]>
> 
> (Also feel free to keep the tags for the other 3 patches since the 
> changes are minimal).
> 
> </SNIP>
> 
> > +	if (component_idx >= 0) {
> > +		struct tag *func_tag = cu__function(cu, tp->type);
> > +
> > +		if (func_tag != NULL) {
> > +			tag = function__parameter(tag__function(func_tag), cu,
> > +						  component_idx);
> > +			if (tag == NULL) {
> > +				fprintf(stderr, "WARNING: BTF_KIND_DECL_TAG for unknown parameter %d in BTF id %d\n",
> > +					component_idx, tp->type);
> > +				return 0;
> > +			}
> > +		}
> > +	}
> > +
> > +	if (tag == NULL && component_idx < 0)
> >  		tag = cu__function(cu, tp->type);
> 
> Nit, I think this can be simplified as follows:
> 
> tag = cu__function(cu, tp->type);
> if (component_idx >= 0 && tag != NULL) {
> 	tag = function__parameter(tag__function(tag), cu, component_idx);
> 	if (tag == NULL) {
> 		fprintf(stderr, "WARNING: BTF_KIND_DECL_TAG for unknown parameter %d in BTF id %d\n",
> 			component_idx, tp->type);
> 		return 0;
> 	}
> }

Agreed, and with that:

Acked-by: Arnaldo Carvalho de Melo <[email protected]>

- Arnaldo