]> xenbits.xensource.com Git - livepatch-build-tools.git/commitdiff
common: Add is_referenced_section() helper function
authorPawel Wieczorkiewicz <wipawel@amazon.de>
Wed, 21 Aug 2019 08:20:42 +0000 (08:20 +0000)
committerRoss Lagerwall <ross.lagerwall@citrix.com>
Thu, 22 Aug 2019 14:27:25 +0000 (15:27 +0100)
This function checks if given section has an included corresponding
RELA section and/or any of the symbols table symbols references the
section. Section associated symbols are ignored here as there is
always such a symbol for every 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>
Reviewed-by: Ross Lagerwall <ross.lagerwall@citrix.com>
Signed-off-by: Ross Lagerwall <ross.lagerwall@citrix.com>
common.c
common.h

index 1fb07cb848214fc940630f059d554cf494847a7e..0ddc9fafc173f988475dd6c2247702a01512bd60 100644 (file)
--- a/common.c
+++ b/common.c
@@ -15,7 +15,7 @@
 
 int is_rela_section(struct section *sec)
 {
-       return (sec->sh.sh_type == SHT_RELA);
+       return sec && (sec->sh.sh_type == SHT_RELA);
 }
 
 int is_local_sym(struct symbol *sym)
@@ -270,6 +270,27 @@ int is_standard_section(struct section *sec)
        }
 }
 
+int is_referenced_section(const struct section *sec,
+                         const struct kpatch_elf *kelf)
+{
+       struct symbol *sym;
+
+       if (is_rela_section(sec->rela) && sec->rela->include)
+               return true;
+
+       list_for_each_entry(sym, &kelf->symbols, list) {
+               if (!sym->include || !sym->sec)
+                       continue;
+               /* Ignore section associated sections */
+               if (sym->type == STT_SECTION)
+                       continue;
+               if (sym->sec->index == sec->index)
+                       return true;
+       }
+
+       return false;
+}
+
 /* returns the offset of the string in the string table */
 int offset_of_string(struct list_head *list, char *name)
 {
index cda690d5b32bf87e2ce3376b7d637da45c224dab..06e19e76f78a5e23b438cef93bc0ce2116fa5791 100644 (file)
--- a/common.h
+++ b/common.h
@@ -151,6 +151,8 @@ 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_referenced_section(const struct section *sec,
+                         const struct kpatch_elf *kelf);
 int is_local_sym(struct symbol *sym);
 
 void rela_insn(struct section *sec, struct rela *rela, struct insn *insn);