diff mbox series

[livepatch-build-tools,part2,3/6] create-diff-object: Add is_special_section() helper function

Message ID 20190416120716.26269-3-wipawel@amazon.de (mailing list archive)
State New, archived
Headers show
Series [livepatch-build-tools,part2,1/6] common: Add is_standard_section() helper function | expand

Commit Message

Wieczorkiewicz, Pawel April 16, 2019, 12:07 p.m. UTC
This function determines, based on the given section name, if the
sections belongs to the special sections category.
It treats a name from the special_sections array as a prefix. Any
sections whose name starts with special section prefix is considered
a special section.

Signed-off-by: Pawel Wieczorkiewicz <wipawel@amazon.de>
Reviewed-by: Andra-Irina Paraschiv <andraprs@amazon.com>
Reviewed-by: Bjoern Doebel <doebel@amazon.de>
Reviewed-by: Norbert Manthey <nmanthey@amazon.de>
---
 common.c | 23 +++++++++++++++++++++++
 common.h |  1 +
 2 files changed, 24 insertions(+)

Comments

Ross Lagerwall April 29, 2019, 3:25 p.m. UTC | #1
On 4/16/19 1:07 PM, Pawel Wieczorkiewicz wrote:
> This function determines, based on the given section name, if the
> sections belongs to the special sections category.
> It treats a name from the special_sections array as a prefix. Any
> sections whose name starts with special section prefix is considered
> a special section.
> 
> Signed-off-by: Pawel Wieczorkiewicz <wipawel@amazon.de>
> Reviewed-by: Andra-Irina Paraschiv <andraprs@amazon.com>
> Reviewed-by: Bjoern Doebel <doebel@amazon.de>
> Reviewed-by: Norbert Manthey <nmanthey@amazon.de>
> ---
>   common.c | 23 +++++++++++++++++++++++
>   common.h |  1 +
>   2 files changed, 24 insertions(+)
> 
> diff --git a/common.c b/common.c
> index c968299..a2c860b 100644
> --- a/common.c
> +++ b/common.c
> @@ -290,6 +290,29 @@ int is_referenced_section(const struct section *sec, const struct kpatch_elf *ke
>   	return false;
>   }
>   
> +int is_special_section(struct section *sec)

const for the parameter?

> +{
> +	static struct special_section_names {
> +		const char *name;
> +	} names[] = {
> +		{ .name		= ".bug_frames"                 },
> +		{ .name		= ".fixup"                      },
> +		{ .name		= ".ex_table"                   },
> +		{ .name		= ".altinstructions"            },
> +		{ .name		= ".altinstr_replacement"       },
> +		{ .name		= ".livepatch.hooks"            },
> +		{ .name         = NULL                          },
> +	};
> +	struct special_section_names *special;

Wouldn't it be better to reuse the existing special_sections array 
rather than partially duplicating it here?

> +
> +	for (special = names; special->name; special++) {
> +		if (!strncmp(sec->name, special->name, strlen(special->name)))
> +			return true;

This check is not as precise as it could be, since ".altinstructionsfoo" 
would be considered special when it actually means nothing to this tool.
Wieczorkiewicz, Pawel April 30, 2019, 12:18 p.m. UTC | #2
> On 29. Apr 2019, at 17:25, Ross Lagerwall <ross.lagerwall@citrix.com> wrote:
> 
> On 4/16/19 1:07 PM, Pawel Wieczorkiewicz wrote:
>> This function determines, based on the given section name, if the
>> sections belongs to the special sections category.
>> It treats a name from the special_sections array as a prefix. Any
>> sections whose name starts with special section prefix is considered
>> a special section.
>> Signed-off-by: Pawel Wieczorkiewicz <wipawel@amazon.de>
>> Reviewed-by: Andra-Irina Paraschiv <andraprs@amazon.com>
>> Reviewed-by: Bjoern Doebel <doebel@amazon.de>
>> Reviewed-by: Norbert Manthey <nmanthey@amazon.de>
>> ---
>>  common.c | 23 +++++++++++++++++++++++
>>  common.h |  1 +
>>  2 files changed, 24 insertions(+)
>> diff --git a/common.c b/common.c
>> index c968299..a2c860b 100644
>> --- a/common.c
>> +++ b/common.c
>> @@ -290,6 +290,29 @@ int is_referenced_section(const struct section *sec, const struct kpatch_elf *ke
>>  	return false;
>>  }
>>  +int is_special_section(struct section *sec)
> 
> const for the parameter?

ACK. Will add.

> 
>> +{
>> +	static struct special_section_names {
>> +		const char *name;
>> +	} names[] = {
>> +		{ .name		= ".bug_frames"                 },
>> +		{ .name		= ".fixup"                      },
>> +		{ .name		= ".ex_table"                   },
>> +		{ .name		= ".altinstructions"            },
>> +		{ .name		= ".altinstr_replacement"       },
>> +		{ .name		= ".livepatch.hooks"            },
>> +		{ .name         = NULL                          },
>> +	};
>> +	struct special_section_names *special;
> 
> Wouldn't it be better to reuse the existing special_sections array rather than partially duplicating it here?

After looking at this code again, I think you’re right and it would be better.
It would require to explicitly call out all sections to be considered special in
the special_sections array, but this is actually what I need for further changes anyway.

ACK. Will fix. 

> 
>> +
>> +	for (special = names; special->name; special++) {
>> +		if (!strncmp(sec->name, special->name, strlen(special->name)))
>> +			return true;
> 
> This check is not as precise as it could be, since ".altinstructionsfoo" would be considered special when it actually means nothing to this tool.

Given the above reasoning, that’s right.

ACK. Will fix.

> 
> -- 
> Ross Lagerwall


Best Regards,
Pawel Wieczorkiewicz



Amazon Development Center Germany GmbH
Krausenstr. 38
10117 Berlin
Geschaeftsfuehrer: Christian Schlaeger, Ralf Herbrich
Ust-ID: DE 289 237 879
Eingetragen am Amtsgericht Charlottenburg HRB 149173 B
diff mbox series

Patch

diff --git a/common.c b/common.c
index c968299..a2c860b 100644
--- a/common.c
+++ b/common.c
@@ -290,6 +290,29 @@  int is_referenced_section(const struct section *sec, const struct kpatch_elf *ke
 	return false;
 }
 
+int is_special_section(struct section *sec)
+{
+	static struct special_section_names {
+		const char *name;
+	} names[] = {
+		{ .name		= ".bug_frames"                 },
+		{ .name		= ".fixup"                      },
+		{ .name		= ".ex_table"                   },
+		{ .name		= ".altinstructions"            },
+		{ .name		= ".altinstr_replacement"       },
+		{ .name		= ".livepatch.hooks"            },
+		{ .name         = NULL                          },
+	};
+	struct special_section_names *special;
+
+	for (special = names; special->name; special++) {
+		if (!strncmp(sec->name, special->name, strlen(special->name)))
+			return true;
+	}
+
+	return false;
+}
+
 /* returns the offset of the string in the string table */
 int offset_of_string(struct list_head *list, char *name)
 {
diff --git a/common.h b/common.h
index affe16b..6d38e88 100644
--- a/common.h
+++ b/common.h
@@ -152,6 +152,7 @@  int is_debug_section(struct section *sec);
 int is_rela_section(struct section *sec);
 int is_standard_section(struct section *sec);
 int is_referenced_section(const struct section *sec, const struct kpatch_elf *kelf);
+int is_special_section(struct section *sec);
 int is_local_sym(struct symbol *sym);
 
 void rela_insn(struct section *sec, struct rela *rela, struct insn *insn);