diff mbox series

[v5,06/21] modpost: clean up is_executable_section()

Message ID 20230514152739.962109-7-masahiroy@kernel.org (mailing list archive)
State New, archived
Headers show
Series Unify <linux/export.h> and <asm/export.h>, remove EXPORT_DATA_SYMBOL(), faster TRIM_UNUSED_KSYMS | expand

Commit Message

Masahiro Yamada May 14, 2023, 3:27 p.m. UTC
SHF_EXECINSTR is a bit flag (#define SHF_EXECINSTR 0x4).
Compare the masked flag to '!= 0'.

There is no good reason to stop modpost immediately even if a special
section index is given. You will get a section mismatch error anyway.

Also, change the return type to bool.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mod/modpost.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

Comments

Nick Desaulniers May 17, 2023, 9:10 p.m. UTC | #1
On Sun, May 14, 2023 at 8:28 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> SHF_EXECINSTR is a bit flag (#define SHF_EXECINSTR 0x4).
> Compare the masked flag to '!= 0'.
>
> There is no good reason to stop modpost immediately even if a special
> section index is given. You will get a section mismatch error anyway.
>
> Also, change the return type to bool.
>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

Moving the definition and renaming the parameter seems very
unnecessary, but whatever. Thanks for the patch!
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

> ---
>
>  scripts/mod/modpost.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index bb7d1d87bae7..0bda2f22c985 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -1207,6 +1207,14 @@ static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr,
>         return near;
>  }
>
> +static bool is_executable_section(struct elf_info *elf, unsigned int secndx)
> +{
> +       if (secndx > elf->num_sections)
> +               return false;
> +
> +       return (elf->sechdrs[secndx].sh_flags & SHF_EXECINSTR) != 0;
> +}
> +
>  static void default_mismatch_handler(const char *modname, struct elf_info *elf,
>                                      const struct sectioncheck* const mismatch,
>                                      Elf_Rela *r, Elf_Sym *sym, const char *fromsec)
> @@ -1252,14 +1260,6 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf,
>         }
>  }
>
> -static int is_executable_section(struct elf_info* elf, unsigned int section_index)
> -{
> -       if (section_index > elf->num_sections)
> -               fatal("section_index is outside elf->num_sections!\n");
> -
> -       return ((elf->sechdrs[section_index].sh_flags & SHF_EXECINSTR) == SHF_EXECINSTR);
> -}
> -
>  static void extable_mismatch_handler(const char* modname, struct elf_info *elf,
>                                      const struct sectioncheck* const mismatch,
>                                      Elf_Rela* r, Elf_Sym* sym,
> --
> 2.39.2
>
Masahiro Yamada May 20, 2023, 1:19 p.m. UTC | #2
On Thu, May 18, 2023 at 6:10 AM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> On Sun, May 14, 2023 at 8:28 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
> >
> > SHF_EXECINSTR is a bit flag (#define SHF_EXECINSTR 0x4).
> > Compare the masked flag to '!= 0'.
> >
> > There is no good reason to stop modpost immediately even if a special
> > section index is given. You will get a section mismatch error anyway.
> >
> > Also, change the return type to bool.
> >
> > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
>
> Moving the definition and renaming the parameter seems very
> unnecessary, but whatever. Thanks for the patch!


Moving the definition _is_ necessary.

See the next patch, which moves the call-site of
is_executable_section().

The definition must come before the caller.



The current code exceeds 80-cols per line.

I renamed the parameters so that the lines
fit within 80-cols without wrapping.





> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
>
> > ---
> >
> >  scripts/mod/modpost.c | 16 ++++++++--------
> >  1 file changed, 8 insertions(+), 8 deletions(-)
> >
> > diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> > index bb7d1d87bae7..0bda2f22c985 100644
> > --- a/scripts/mod/modpost.c
> > +++ b/scripts/mod/modpost.c
> > @@ -1207,6 +1207,14 @@ static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr,
> >         return near;
> >  }
> >
> > +static bool is_executable_section(struct elf_info *elf, unsigned int secndx)
> > +{
> > +       if (secndx > elf->num_sections)
> > +               return false;
> > +
> > +       return (elf->sechdrs[secndx].sh_flags & SHF_EXECINSTR) != 0;
> > +}
> > +
> >  static void default_mismatch_handler(const char *modname, struct elf_info *elf,
> >                                      const struct sectioncheck* const mismatch,
> >                                      Elf_Rela *r, Elf_Sym *sym, const char *fromsec)
> > @@ -1252,14 +1260,6 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf,
> >         }
> >  }
> >
> > -static int is_executable_section(struct elf_info* elf, unsigned int section_index)
> > -{
> > -       if (section_index > elf->num_sections)
> > -               fatal("section_index is outside elf->num_sections!\n");
> > -
> > -       return ((elf->sechdrs[section_index].sh_flags & SHF_EXECINSTR) == SHF_EXECINSTR);
> > -}
> > -
> >  static void extable_mismatch_handler(const char* modname, struct elf_info *elf,
> >                                      const struct sectioncheck* const mismatch,
> >                                      Elf_Rela* r, Elf_Sym* sym,
> > --
> > 2.39.2
> >
>
>
> --
> Thanks,
> ~Nick Desaulniers
diff mbox series

Patch

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index bb7d1d87bae7..0bda2f22c985 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1207,6 +1207,14 @@  static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr,
 	return near;
 }
 
+static bool is_executable_section(struct elf_info *elf, unsigned int secndx)
+{
+	if (secndx > elf->num_sections)
+		return false;
+
+	return (elf->sechdrs[secndx].sh_flags & SHF_EXECINSTR) != 0;
+}
+
 static void default_mismatch_handler(const char *modname, struct elf_info *elf,
 				     const struct sectioncheck* const mismatch,
 				     Elf_Rela *r, Elf_Sym *sym, const char *fromsec)
@@ -1252,14 +1260,6 @@  static void default_mismatch_handler(const char *modname, struct elf_info *elf,
 	}
 }
 
-static int is_executable_section(struct elf_info* elf, unsigned int section_index)
-{
-	if (section_index > elf->num_sections)
-		fatal("section_index is outside elf->num_sections!\n");
-
-	return ((elf->sechdrs[section_index].sh_flags & SHF_EXECINSTR) == SHF_EXECINSTR);
-}
-
 static void extable_mismatch_handler(const char* modname, struct elf_info *elf,
 				     const struct sectioncheck* const mismatch,
 				     Elf_Rela* r, Elf_Sym* sym,