diff mbox series

[dwarves,v9,1/3] pahole: Save input filename separate from output

Message ID 1728b8d941d2658b310457b6c59d97f102aaf66d.1714430735.git.dxu@dxuuu.xyz (mailing list archive)
State Not Applicable
Delegated to: BPF
Headers show
Series pahole: Inject kfunc decl tags into BTF | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Daniel Xu April 29, 2024, 10:45 p.m. UTC
During detached BTF encoding, the input file is not necessarily the same
as the output file. So save them separately. This matters when we need
to look at the input file again, such as for kfunc tagging.

Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
---
 btf_encoder.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Arnaldo Carvalho de Melo April 30, 2024, 6:41 p.m. UTC | #1
On Mon, Apr 29, 2024 at 04:45:58PM -0600, Daniel Xu wrote:
> During detached BTF encoding, the input file is not necessarily the same
> as the output file. So save them separately. This matters when we need
> to look at the input file again, such as for kfunc tagging.

You forgot to check a strdup(), I added this on top of this patch:


diff --git a/btf_encoder.c b/btf_encoder.c
index 5ffaf5d969c9bc49..8aa2a7709dc1555f 100644
--- a/btf_encoder.c
+++ b/btf_encoder.c
@@ -1651,7 +1651,7 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam
 		encoder->raw_output = detached_filename != NULL;
 		encoder->source_filename = strdup(cu->filename);
 		encoder->filename = strdup(encoder->raw_output ? detached_filename : cu->filename);
-		if (encoder->filename == NULL)
+		if (encoder->source_filename == NULL || encoder->filename == NULL)
 			goto out_delete;
 
 		encoder->btf = btf__new_empty_split(base_btf);
 
> Signed-off-by: Daniel Xu <dxu@dxuuu.xyz>
> ---
>  btf_encoder.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/btf_encoder.c b/btf_encoder.c
> index 19e9d90..5ffaf5d 100644
> --- a/btf_encoder.c
> +++ b/btf_encoder.c
> @@ -64,6 +64,7 @@ struct btf_encoder {
>  	struct btf        *btf;
>  	struct cu         *cu;
>  	struct gobuffer   percpu_secinfo;
> +	const char	  *source_filename;
>  	const char	  *filename;
>  	struct elf_symtab *symtab;
>  	uint32_t	  type_id_off;
> @@ -1648,6 +1649,7 @@ struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam
>  
>  	if (encoder) {
>  		encoder->raw_output = detached_filename != NULL;
> +		encoder->source_filename = strdup(cu->filename);
>  		encoder->filename = strdup(encoder->raw_output ? detached_filename : cu->filename);
>  		if (encoder->filename == NULL)
>  			goto out_delete;
> @@ -1730,6 +1732,7 @@ void btf_encoder__delete(struct btf_encoder *encoder)
>  	btf_encoders__delete(encoder);
>  	__gobuffer__delete(&encoder->percpu_secinfo);
>  	zfree(&encoder->filename);
> +	zfree(&encoder->source_filename);
>  	btf__free(encoder->btf);
>  	encoder->btf = NULL;
>  	elf_symtab__delete(encoder->symtab);
> -- 
> 2.44.0
diff mbox series

Patch

diff --git a/btf_encoder.c b/btf_encoder.c
index 19e9d90..5ffaf5d 100644
--- a/btf_encoder.c
+++ b/btf_encoder.c
@@ -64,6 +64,7 @@  struct btf_encoder {
 	struct btf        *btf;
 	struct cu         *cu;
 	struct gobuffer   percpu_secinfo;
+	const char	  *source_filename;
 	const char	  *filename;
 	struct elf_symtab *symtab;
 	uint32_t	  type_id_off;
@@ -1648,6 +1649,7 @@  struct btf_encoder *btf_encoder__new(struct cu *cu, const char *detached_filenam
 
 	if (encoder) {
 		encoder->raw_output = detached_filename != NULL;
+		encoder->source_filename = strdup(cu->filename);
 		encoder->filename = strdup(encoder->raw_output ? detached_filename : cu->filename);
 		if (encoder->filename == NULL)
 			goto out_delete;
@@ -1730,6 +1732,7 @@  void btf_encoder__delete(struct btf_encoder *encoder)
 	btf_encoders__delete(encoder);
 	__gobuffer__delete(&encoder->percpu_secinfo);
 	zfree(&encoder->filename);
+	zfree(&encoder->source_filename);
 	btf__free(encoder->btf);
 	encoder->btf = NULL;
 	elf_symtab__delete(encoder->symtab);