diff mbox series

[livepatch-build-tools,part2,v2,1/6] common: Add is_standard_section() helper function

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

Commit Message

Wieczorkiewicz, Pawel Aug. 7, 2019, 11:32 a.m. UTC
Detect standard (always to be included) sections via their section
header type. The standard sections: ".shstrtab", ".symtab", ".strtab"
are either of type SHT_SYMTAB or SHT_STRTAB.

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>
---
v2:
* Keep lines to 80 chars
---
 common.c             | 12 ++++++++++++
 common.h             |  1 +
 create-diff-object.c |  4 +---
 3 files changed, 14 insertions(+), 3 deletions(-)

Comments

Ross Lagerwall Aug. 16, 2019, 9:04 a.m. UTC | #1
On 8/7/19 12:32 PM, Pawel Wieczorkiewicz wrote:
> Detect standard (always to be included) sections via their section
> header type. The standard sections: ".shstrtab", ".symtab", ".strtab"
> are either of type SHT_SYMTAB or SHT_STRTAB.
> 
> 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>
> ---
> v2:
> * Keep lines to 80 chars
> ---
Reviewed-by: Ross Lagerwall <ross.lagerwall@citrix.com>

Thanks
diff mbox series

Patch

diff --git a/common.c b/common.c
index bc63955..1fb07cb 100644
--- a/common.c
+++ b/common.c
@@ -5,6 +5,7 @@ 
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <stdbool.h>
 #include <gelf.h>
 
 #include "list.h"
@@ -258,6 +259,17 @@  int is_debug_section(struct section *sec)
 	return !strncmp(name, ".debug_", 7);
 }
 
+int is_standard_section(struct section *sec)
+{
+	switch (sec->sh.sh_type) {
+	case SHT_STRTAB:
+	case SHT_SYMTAB:
+		return true;
+	default:
+		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 7599fe7..cda690d 100644
--- a/common.h
+++ b/common.h
@@ -150,6 +150,7 @@  struct symbol *find_symbol_by_name(struct list_head *list, const char *name);
 int is_text_section(struct section *sec);
 int is_debug_section(struct section *sec);
 int is_rela_section(struct section *sec);
+int is_standard_section(struct section *sec);
 int is_local_sym(struct symbol *sym);
 
 void rela_insn(struct section *sec, struct rela *rela, struct insn *insn);
diff --git a/create-diff-object.c b/create-diff-object.c
index 82f777e..4699ba0 100644
--- a/create-diff-object.c
+++ b/create-diff-object.c
@@ -1278,9 +1278,7 @@  static void kpatch_include_standard_elements(struct kpatch_elf *kelf)
 
 	list_for_each_entry(sec, &kelf->sections, list) {
 		/* include these sections even if they haven't changed */
-		if (!strcmp(sec->name, ".shstrtab") ||
-		    !strcmp(sec->name, ".strtab") ||
-		    !strcmp(sec->name, ".symtab") ||
+		if (is_standard_section(sec) ||
 		    should_include_str_section(sec->name)) {
 			sec->include = 1;
 			if (sec->secsym)