diff mbox series

[v6,07/20] modpost: replace r->r_offset, r->r_addend with faddr, taddr

Message ID 20230521160426.1881124-8-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 21, 2023, 4:04 p.m. UTC
r_offset/r_addend holds the offset address from/to which a symbol is
referenced. It is unclear unless you are familiar with ELF.

Rename them to faddr, taddr, respectively. The prefix 'f' means 'from',
't' means 'to'.

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

 scripts/mod/modpost.c | 34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

Comments

Nick Desaulniers May 22, 2023, 6:31 p.m. UTC | #1
On Sun, May 21, 2023 at 9:05 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> r_offset/r_addend holds the offset address from/to which a symbol is
> referenced. It is unclear unless you are familiar with ELF.
>
> Rename them to faddr, taddr, respectively. The prefix 'f' means 'from',
> 't' means 'to'.
>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>


Do you care to rewrap the parameter lists?
```
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 4da96746a03b..8a787521963d 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1115,8 +1115,8 @@ static bool is_executable_section(struct
elf_info *elf, unsigned int secndx)

 static void default_mismatch_handler(const char *modname, struct elf_info *elf,
                                     const struct sectioncheck* const mismatch,
-                                    Elf_Sym *tsym,
-                                    unsigned int fsecndx, const char
*fromsec, Elf_Addr faddr,
+                                    Elf_Sym *tsym, unsigned int fsecndx,
+                                    const char *fromsec, Elf_Addr faddr,
                                     const char *tosec, Elf_Addr taddr)
 {
        Elf_Sym *from;
@@ -1217,9 +1217,9 @@ static void check_export_symbol(struct module
*mod, struct elf_info *elf,
 }

 static void check_section_mismatch(struct module *mod, struct elf_info *elf,
-                                  Elf_Sym *sym,
-                                  unsigned int fsecndx, const char *fromsec,
-                                  Elf_Addr faddr, Elf_Addr taddr)
+                                  Elf_Sym *sym, unsigned int fsecndx,
+                                  const char *fromsec, Elf_Addr faddr,
+                                  Elf_Addr taddr)
 {
        const char *tosec = sec_name(elf, get_secindex(elf, sym));
        const struct sectioncheck *mismatch;
```
Either way:
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>


> ---
>
>  scripts/mod/modpost.c | 34 +++++++++++++++++++---------------
>  1 file changed, 19 insertions(+), 15 deletions(-)
>
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 7848bacd4b42..f364738a236e 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -1166,18 +1166,18 @@ static bool is_executable_section(struct elf_info *elf, unsigned int secndx)
>
>  static void default_mismatch_handler(const char *modname, struct elf_info *elf,
>                                      const struct sectioncheck* const mismatch,
> -                                    Elf_Rela *r, Elf_Sym *tsym,
> -                                    unsigned int fsecndx, const char *fromsec,
> -                                    const char *tosec)
> +                                    Elf_Sym *tsym,
> +                                    unsigned int fsecndx, const char *fromsec, Elf_Addr faddr,
> +                                    const char *tosec, Elf_Addr taddr)
>  {
>         Elf_Sym *from;
>         const char *tosym;
>         const char *fromsym;
>
> -       from = find_fromsym(elf, r->r_offset, fsecndx);
> +       from = find_fromsym(elf, faddr, fsecndx);
>         fromsym = sym_name(elf, from);
>
> -       tsym = find_tosym(elf, r->r_addend, tsym);
> +       tsym = find_tosym(elf, taddr, tsym);
>         tosym = sym_name(elf, tsym);
>
>         /* check whitelist - we may ignore it */
> @@ -1204,7 +1204,7 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf,
>                 break;
>         case EXTABLE_TO_NON_TEXT:
>                 warn("%s(%s+0x%lx): Section mismatch in reference to the %s:%s\n",
> -                    modname, fromsec, (long)r->r_offset, tosec, tosym);
> +                    modname, fromsec, (long)faddr, tosec, tosym);
>
>                 if (match(tosec, mismatch->bad_tosec))
>                         fatal("The relocation at %s+0x%lx references\n"
> @@ -1212,7 +1212,7 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf,
>                               "Something is seriously wrong and should be fixed.\n"
>                               "You might get more information about where this is\n"
>                               "coming from by using scripts/check_extable.sh %s\n",
> -                             fromsec, (long)r->r_offset, tosec, modname);
> +                             fromsec, (long)faddr, tosec, modname);
>                 else if (is_executable_section(elf, get_secindex(elf, tsym)))
>                         warn("The relocation at %s+0x%lx references\n"
>                              "section \"%s\" which is not in the list of\n"
> @@ -1221,17 +1221,18 @@ static void default_mismatch_handler(const char *modname, struct elf_info *elf,
>                              "list of authorized sections to jump to on fault.\n"
>                              "This can be achieved by adding \"%s\" to\n"
>                              "OTHER_TEXT_SECTIONS in scripts/mod/modpost.c.\n",
> -                            fromsec, (long)r->r_offset, tosec, tosec, tosec);
> +                            fromsec, (long)faddr, tosec, tosec, tosec);
>                 else
>                         error("%s+0x%lx references non-executable section '%s'\n",
> -                             fromsec, (long)r->r_offset, tosec);
> +                             fromsec, (long)faddr, tosec);
>                 break;
>         }
>  }
>
>  static void check_section_mismatch(const char *modname, struct elf_info *elf,
> -                                  Elf_Rela *r, Elf_Sym *sym,
> -                                  unsigned int fsecndx, const char *fromsec)
> +                                  Elf_Sym *sym,
> +                                  unsigned int fsecndx, const char *fromsec,
> +                                  Elf_Addr faddr, Elf_Addr taddr)
>  {
>         const char *tosec = sec_name(elf, get_secindex(elf, sym));
>         const struct sectioncheck *mismatch = section_mismatch(fromsec, tosec);
> @@ -1239,8 +1240,9 @@ static void check_section_mismatch(const char *modname, struct elf_info *elf,
>         if (!mismatch)
>                 return;
>
> -       default_mismatch_handler(modname, elf, mismatch, r, sym, fsecndx, fromsec,
> -                                tosec);
> +       default_mismatch_handler(modname, elf, mismatch, sym,
> +                                fsecndx, fromsec, faddr,
> +                                tosec, taddr);
>  }
>
>  static unsigned int *reloc_location(struct elf_info *elf,
> @@ -1406,7 +1408,8 @@ static void section_rela(const char *modname, struct elf_info *elf,
>                 /* Skip special sections */
>                 if (is_shndx_special(sym->st_shndx))
>                         continue;
> -               check_section_mismatch(modname, elf, &r, sym, fsecndx, fromsec);
> +               check_section_mismatch(modname, elf, sym,
> +                                      fsecndx, fromsec, r.r_offset, r.r_addend);
>         }
>  }
>
> @@ -1464,7 +1467,8 @@ static void section_rel(const char *modname, struct elf_info *elf,
>                 /* Skip special sections */
>                 if (is_shndx_special(sym->st_shndx))
>                         continue;
> -               check_section_mismatch(modname, elf, &r, sym, fsecndx, fromsec);
> +               check_section_mismatch(modname, elf, sym,
> +                                      fsecndx, fromsec, r.r_offset, r.r_addend);
>         }
>  }
>
> --
> 2.39.2
>
diff mbox series

Patch

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 7848bacd4b42..f364738a236e 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1166,18 +1166,18 @@  static bool is_executable_section(struct elf_info *elf, unsigned int secndx)
 
 static void default_mismatch_handler(const char *modname, struct elf_info *elf,
 				     const struct sectioncheck* const mismatch,
-				     Elf_Rela *r, Elf_Sym *tsym,
-				     unsigned int fsecndx, const char *fromsec,
-				     const char *tosec)
+				     Elf_Sym *tsym,
+				     unsigned int fsecndx, const char *fromsec, Elf_Addr faddr,
+				     const char *tosec, Elf_Addr taddr)
 {
 	Elf_Sym *from;
 	const char *tosym;
 	const char *fromsym;
 
-	from = find_fromsym(elf, r->r_offset, fsecndx);
+	from = find_fromsym(elf, faddr, fsecndx);
 	fromsym = sym_name(elf, from);
 
-	tsym = find_tosym(elf, r->r_addend, tsym);
+	tsym = find_tosym(elf, taddr, tsym);
 	tosym = sym_name(elf, tsym);
 
 	/* check whitelist - we may ignore it */
@@ -1204,7 +1204,7 @@  static void default_mismatch_handler(const char *modname, struct elf_info *elf,
 		break;
 	case EXTABLE_TO_NON_TEXT:
 		warn("%s(%s+0x%lx): Section mismatch in reference to the %s:%s\n",
-		     modname, fromsec, (long)r->r_offset, tosec, tosym);
+		     modname, fromsec, (long)faddr, tosec, tosym);
 
 		if (match(tosec, mismatch->bad_tosec))
 			fatal("The relocation at %s+0x%lx references\n"
@@ -1212,7 +1212,7 @@  static void default_mismatch_handler(const char *modname, struct elf_info *elf,
 			      "Something is seriously wrong and should be fixed.\n"
 			      "You might get more information about where this is\n"
 			      "coming from by using scripts/check_extable.sh %s\n",
-			      fromsec, (long)r->r_offset, tosec, modname);
+			      fromsec, (long)faddr, tosec, modname);
 		else if (is_executable_section(elf, get_secindex(elf, tsym)))
 			warn("The relocation at %s+0x%lx references\n"
 			     "section \"%s\" which is not in the list of\n"
@@ -1221,17 +1221,18 @@  static void default_mismatch_handler(const char *modname, struct elf_info *elf,
 			     "list of authorized sections to jump to on fault.\n"
 			     "This can be achieved by adding \"%s\" to\n"
 			     "OTHER_TEXT_SECTIONS in scripts/mod/modpost.c.\n",
-			     fromsec, (long)r->r_offset, tosec, tosec, tosec);
+			     fromsec, (long)faddr, tosec, tosec, tosec);
 		else
 			error("%s+0x%lx references non-executable section '%s'\n",
-			      fromsec, (long)r->r_offset, tosec);
+			      fromsec, (long)faddr, tosec);
 		break;
 	}
 }
 
 static void check_section_mismatch(const char *modname, struct elf_info *elf,
-				   Elf_Rela *r, Elf_Sym *sym,
-				   unsigned int fsecndx, const char *fromsec)
+				   Elf_Sym *sym,
+				   unsigned int fsecndx, const char *fromsec,
+				   Elf_Addr faddr, Elf_Addr taddr)
 {
 	const char *tosec = sec_name(elf, get_secindex(elf, sym));
 	const struct sectioncheck *mismatch = section_mismatch(fromsec, tosec);
@@ -1239,8 +1240,9 @@  static void check_section_mismatch(const char *modname, struct elf_info *elf,
 	if (!mismatch)
 		return;
 
-	default_mismatch_handler(modname, elf, mismatch, r, sym, fsecndx, fromsec,
-				 tosec);
+	default_mismatch_handler(modname, elf, mismatch, sym,
+				 fsecndx, fromsec, faddr,
+				 tosec, taddr);
 }
 
 static unsigned int *reloc_location(struct elf_info *elf,
@@ -1406,7 +1408,8 @@  static void section_rela(const char *modname, struct elf_info *elf,
 		/* Skip special sections */
 		if (is_shndx_special(sym->st_shndx))
 			continue;
-		check_section_mismatch(modname, elf, &r, sym, fsecndx, fromsec);
+		check_section_mismatch(modname, elf, sym,
+				       fsecndx, fromsec, r.r_offset, r.r_addend);
 	}
 }
 
@@ -1464,7 +1467,8 @@  static void section_rel(const char *modname, struct elf_info *elf,
 		/* Skip special sections */
 		if (is_shndx_special(sym->st_shndx))
 			continue;
-		check_section_mismatch(modname, elf, &r, sym, fsecndx, fromsec);
+		check_section_mismatch(modname, elf, sym,
+				       fsecndx, fromsec, r.r_offset, r.r_addend);
 	}
 }