diff mbox series

[1/2] modpost: drop executable ELF support

Message ID 20220719165300.3000580-1-masahiroy@kernel.org (mailing list archive)
State New, archived
Headers show
Series [1/2] modpost: drop executable ELF support | expand

Commit Message

Masahiro Yamada July 19, 2022, 4:52 p.m. UTC
Since commit 269a535ca931 ("modpost: generate vmlinux.symvers and
reuse it for the second modpost"), modpost only parses relocatable
files (ET_REL).

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

 scripts/mod/modpost.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

Comments

Nick Desaulniers July 25, 2022, 4:49 p.m. UTC | #1
On Tue, Jul 19, 2022 at 9:53 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> Since commit 269a535ca931 ("modpost: generate vmlinux.symvers and
> reuse it for the second modpost"), modpost only parses relocatable
> files (ET_REL).
>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

Thanks for the patch!
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

> ---
>
>  scripts/mod/modpost.c | 10 ++++------
>  1 file changed, 4 insertions(+), 6 deletions(-)
>
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 7735d095338c..6370f9accb8e 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -321,9 +321,6 @@ static void *sym_get_data_by_offset(const struct elf_info *info,
>  {
>         Elf_Shdr *sechdr = &info->sechdrs[secindex];
>
> -       if (info->hdr->e_type != ET_REL)
> -               offset -= sechdr->sh_addr;
> -
>         return (void *)info->hdr + sechdr->sh_offset + offset;
>  }
>
> @@ -477,6 +474,10 @@ static int parse_elf(struct elf_info *info, const char *filename)
>         sechdrs = (void *)hdr + hdr->e_shoff;
>         info->sechdrs = sechdrs;
>
> +       /* modpost only works for relocatable objects */
> +       if (hdr->e_type != ET_REL)
> +               fatal("%s: not relocatable object.", filename);
> +
>         /* Check if file offset is correct */
>         if (hdr->e_shoff > info->size) {
>                 fatal("section header offset=%lu in file '%s' is bigger than filesize=%zu\n",
> @@ -1633,9 +1634,6 @@ static int addend_386_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
>                 break;
>         case R_386_PC32:
>                 r->r_addend = TO_NATIVE(*location) + 4;
> -               /* For CONFIG_RELOCATABLE=y */
> -               if (elf->hdr->e_type == ET_EXEC)
> -                       r->r_addend += r->r_offset;
>                 break;
>         }
>         return 0;
> --
> 2.34.1
>
diff mbox series

Patch

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 7735d095338c..6370f9accb8e 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -321,9 +321,6 @@  static void *sym_get_data_by_offset(const struct elf_info *info,
 {
 	Elf_Shdr *sechdr = &info->sechdrs[secindex];
 
-	if (info->hdr->e_type != ET_REL)
-		offset -= sechdr->sh_addr;
-
 	return (void *)info->hdr + sechdr->sh_offset + offset;
 }
 
@@ -477,6 +474,10 @@  static int parse_elf(struct elf_info *info, const char *filename)
 	sechdrs = (void *)hdr + hdr->e_shoff;
 	info->sechdrs = sechdrs;
 
+	/* modpost only works for relocatable objects */
+	if (hdr->e_type != ET_REL)
+		fatal("%s: not relocatable object.", filename);
+
 	/* Check if file offset is correct */
 	if (hdr->e_shoff > info->size) {
 		fatal("section header offset=%lu in file '%s' is bigger than filesize=%zu\n",
@@ -1633,9 +1634,6 @@  static int addend_386_rel(struct elf_info *elf, Elf_Shdr *sechdr, Elf_Rela *r)
 		break;
 	case R_386_PC32:
 		r->r_addend = TO_NATIVE(*location) + 4;
-		/* For CONFIG_RELOCATABLE=y */
-		if (elf->hdr->e_type == ET_EXEC)
-			r->r_addend += r->r_offset;
 		break;
 	}
 	return 0;