Message ID | 20190416120716.26269-2-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 |
On 4/16/19 1:07 PM, Pawel Wieczorkiewicz wrote: > 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> > --- > common.c | 22 +++++++++++++++++++++- > common.h | 1 + > 2 files changed, 22 insertions(+), 1 deletion(-) > > diff --git a/common.c b/common.c > index 1fb07cb..c968299 100644 > --- 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,26 @@ int is_standard_section(struct section *sec) > } > } > > +int is_referenced_section(const struct section *sec, const struct kpatch_elf *kelf) Let's keep to 80 chars where practical (and throughout the rest of the patches). > +{ > + 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; You can simplify this check to `sym->sec == sec` like the rest of the code does.
> On 29. Apr 2019, at 17:14, Ross Lagerwall <ross.lagerwall@citrix.com> wrote: > > On 4/16/19 1:07 PM, Pawel Wieczorkiewicz wrote: >> 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> >> --- >> common.c | 22 +++++++++++++++++++++- >> common.h | 1 + >> 2 files changed, 22 insertions(+), 1 deletion(-) >> diff --git a/common.c b/common.c >> index 1fb07cb..c968299 100644 >> --- 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,26 @@ int is_standard_section(struct section *sec) >> } >> } >> +int is_referenced_section(const struct section *sec, const struct kpatch_elf *kelf) > > Let's keep to 80 chars where practical (and throughout the rest of the patches). ACK. Will fix. Although, sometimes it makes the code pretty unreadable. > >> +{ >> + 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; > > You can simplify this check to `sym->sec == sec` like the rest of the code does. Might be my paranoia again (or I am simply missing some obvious assumptions/invariants), but I explicitly wanted to check whether given section/symbol is referenced using other means than addresses. > > -- > 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 --git a/common.c b/common.c index 1fb07cb..c968299 100644 --- 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,26 @@ 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) { diff --git a/common.h b/common.h index cda690d..affe16b 100644 --- a/common.h +++ b/common.h @@ -151,6 +151,7 @@ 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);