linux-debuggers.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Stephen Brennan <stephen.s.brennan@oracle.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Alan Maguire <alan.maguire@oracle.com>,
	dwarves@vger.kernel.org,  linux-debuggers@vger.kernel.org
Subject: Re: [PATCH 2/3] btf_encoder: postpone VARs until encoding DATASEC
Date: Wed, 19 Feb 2025 15:51:59 -0800	[thread overview]
Message-ID: <1386be66981c3ff2b6c4e177433056ceae40a181.camel@gmail.com> (raw)
In-Reply-To: <20250212005003.1413091-3-stephen.s.brennan@oracle.com>

On Tue, 2025-02-11 at 16:49 -0800, Stephen Brennan wrote:
> In order to handle duplicate variables in a data section, we'll need to
> compare variables against the others in their data section. To do this,
> we'll need to postpone adding the variables until they have all been
> identified and collected.  Store all the necessary data to encode the
> VARs (and their DECL_TAGs) and then encode them just before the DATASEC
> containing them. No meaningful change in the output is intended, though
> the ordering of type IDs generated will likely differ.
> 
> Signed-off-by: Stephen Brennan <stephen.s.brennan@oracle.com>
> ---

I think this patch looks good,
but annotation index handling needs a small a fix,
see below.

Reviewed-by: Eduard Zingerman <eddyz87@gmail.com>

[...]

> @@ -109,6 +109,20 @@ struct elf_functions {
>  	int suffix_cnt; /* number of .isra, .part etc */
>  };
>  
> +struct saved_annot {
> +	const char *value;
> +	int component_idx;
> +};
> +
> +struct saved_var {
> +	const char *name;
> +	uint32_t type;

Nit: maybe name this 'id' or 'var_id'?

> +	struct saved_annot *annots;
> +	uint32_t linkage;
> +	uint32_t offset;
> +	uint32_t size;
> +};
> +

[...]

> @@ -2359,30 +2428,34 @@ static int btf_encoder__encode_cu_variables(struct btf_encoder *encoder)
>  			       name, cu->name, addr);
>  		}
>  
> -		/* add a BTF_KIND_VAR in encoder->types */
> -		id = btf_encoder__add_var(encoder, type, name, linkage);
> -		if (id < 0) {
> -			fprintf(stderr, "error: failed to encode variable '%s' at addr 0x%" PRIx64 "\n",
> -			        name, addr);
> -			goto out;
> +		/* Save the annotations */
> +		annot_count = 0;
> +		annots = NULL;
> +		list_for_each_entry(annot, &var->annots, node) {
> +			annot_count += 1;
>  		}
> +		if (annot_count) {
> +			int idx = 0;
>  
> -		list_for_each_entry(annot, &var->annots, node) {
> -			int tag_type_id = btf_encoder__add_decl_tag(encoder, annot->value, id, annot->component_idx);
> -			if (tag_type_id < 0) {
> -				fprintf(stderr, "error: failed to encode tag '%s' to variable '%s' with component_idx %d\n",
> -					annot->value, name, annot->component_idx);
> +			annots = calloc(annot_count + 1, sizeof(*annots));
> +			if (!annots) {
> +				fprintf(stderr, "error: allocation failure\n");
> +				err = -ENOMEM;
>  				goto out;
>  			}
> +			list_for_each_entry(annot, &var->annots, node) {
> +				annots[idx].value = annot->value;
> +				annots[idx].component_idx = annot->component_idx;
> +			}

I think 'idx++' is missing here.

>  		}
>  
>  		/*
> -		 * Add the variable to the secinfo for the section it appears in.
> -		 * Later we will generate a BTF_VAR_DATASEC for all any section with
> -		 * an encoded variable.
> +		 * Store all the collected information for the variable. Later,
> +		 * we will deduplicate and output all.
>  		 */
> -		id = btf_encoder__add_var_secinfo(encoder, shndx, id, (uint32_t)addr, (uint32_t)size);
> -		if (id < 0) {
> +		err = btf_encoder__store_var(encoder, shndx, name, type, linkage,
> +					    (uint32_t)addr, (uint32_t)size, annots);
> +		if (err < 0) {
>  			fprintf(stderr, "error: failed to encode section info for variable '%s' at addr 0x%" PRIx64 "\n",
>  				name, addr);

Free 'annots' in case of an error?

>  			goto out;

[...]


  reply	other threads:[~2025-02-19 23:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-12  0:49 [PATCH 0/3] Fix duplicated VAR and secinfo Stephen Brennan
2025-02-12  0:49 ` [PATCH 1/3] btf_encoder: move btf_encoder__add_decl_tag() Stephen Brennan
2025-02-12  0:49 ` [PATCH 2/3] btf_encoder: postpone VARs until encoding DATASEC Stephen Brennan
2025-02-19 23:51   ` Eduard Zingerman [this message]
2025-02-12  0:49 ` [PATCH 3/3] btf_encoder: don't encode duplicate variables Stephen Brennan
2025-02-12 17:57   ` Alan Maguire
2025-02-12 18:21     ` Stephen Brennan
2025-02-18 10:36 ` [PATCH 0/3] Fix duplicated VAR and secinfo Alan Maguire
2025-02-18 16:54   ` Stephen Brennan
2025-02-19  7:48     ` Eduard Zingerman
2025-02-20  2:26 ` Eduard Zingerman
2025-02-21  1:05   ` Stephen Brennan
2025-02-21  1:30     ` Eduard Zingerman
2025-02-25  1:16       ` Stephen Brennan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1386be66981c3ff2b6c4e177433056ceae40a181.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=acme@kernel.org \
    --cc=alan.maguire@oracle.com \
    --cc=dwarves@vger.kernel.org \
    --cc=linux-debuggers@vger.kernel.org \
    --cc=stephen.s.brennan@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).