* [PATCH 1/2] modpost: drop executable ELF support
@ 2022-07-19 16:52 Masahiro Yamada
2022-07-19 16:53 ` [PATCH 2/2] modpost: use sym_get_data() to get module device_table data Masahiro Yamada
2022-07-25 16:49 ` [PATCH 1/2] modpost: drop executable ELF support Nick Desaulniers
0 siblings, 2 replies; 4+ messages in thread
From: Masahiro Yamada @ 2022-07-19 16:52 UTC (permalink / raw)
To: linux-kbuild
Cc: Masahiro Yamada, Michal Marek, Nick Desaulniers, linux-kernel
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(-)
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
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] modpost: use sym_get_data() to get module device_table data
2022-07-19 16:52 [PATCH 1/2] modpost: drop executable ELF support Masahiro Yamada
@ 2022-07-19 16:53 ` Masahiro Yamada
2022-07-25 16:53 ` Nick Desaulniers
2022-07-25 16:49 ` [PATCH 1/2] modpost: drop executable ELF support Nick Desaulniers
1 sibling, 1 reply; 4+ messages in thread
From: Masahiro Yamada @ 2022-07-19 16:53 UTC (permalink / raw)
To: linux-kbuild
Cc: Masahiro Yamada, Michal Marek, Nick Desaulniers, linux-kernel
Use sym_get_data() to replace the long code.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
scripts/mod/file2alias.c | 4 +---
scripts/mod/modpost.c | 2 +-
scripts/mod/modpost.h | 1 +
3 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index cbd6b0f48b4e..80d973144fde 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -1571,9 +1571,7 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
zeros = calloc(1, sym->st_size);
symval = zeros;
} else {
- symval = (void *)info->hdr
- + info->sechdrs[get_secindex(info, sym)].sh_offset
- + sym->st_value;
+ symval = sym_get_data(info, sym);
}
/* First handle the "special" cases */
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 6370f9accb8e..26254e96c300 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -324,7 +324,7 @@ static void *sym_get_data_by_offset(const struct elf_info *info,
return (void *)info->hdr + sechdr->sh_offset + offset;
}
-static void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym)
+void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym)
{
return sym_get_data_by_offset(info, get_secindex(info, sym),
sym->st_value);
diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
index 044bdfb894b7..4d8a1ae1d1e3 100644
--- a/scripts/mod/modpost.h
+++ b/scripts/mod/modpost.h
@@ -187,6 +187,7 @@ void get_src_version(const char *modname, char sum[], unsigned sumlen);
/* from modpost.c */
char *read_text_file(const char *filename);
char *get_line(char **stringp);
+void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym);
enum loglevel {
LOG_WARN,
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] modpost: drop executable ELF support
2022-07-19 16:52 [PATCH 1/2] modpost: drop executable ELF support Masahiro Yamada
2022-07-19 16:53 ` [PATCH 2/2] modpost: use sym_get_data() to get module device_table data Masahiro Yamada
@ 2022-07-25 16:49 ` Nick Desaulniers
1 sibling, 0 replies; 4+ messages in thread
From: Nick Desaulniers @ 2022-07-25 16:49 UTC (permalink / raw)
To: Masahiro Yamada; +Cc: linux-kbuild, Michal Marek, linux-kernel
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
>
--
Thanks,
~Nick Desaulniers
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] modpost: use sym_get_data() to get module device_table data
2022-07-19 16:53 ` [PATCH 2/2] modpost: use sym_get_data() to get module device_table data Masahiro Yamada
@ 2022-07-25 16:53 ` Nick Desaulniers
0 siblings, 0 replies; 4+ messages in thread
From: Nick Desaulniers @ 2022-07-25 16:53 UTC (permalink / raw)
To: Masahiro Yamada; +Cc: linux-kbuild, Michal Marek, linux-kernel
On Tue, Jul 19, 2022 at 9:53 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> Use sym_get_data() to replace the long code.
>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Thanks for the patch!
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
> ---
>
> scripts/mod/file2alias.c | 4 +---
> scripts/mod/modpost.c | 2 +-
> scripts/mod/modpost.h | 1 +
> 3 files changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
> index cbd6b0f48b4e..80d973144fde 100644
> --- a/scripts/mod/file2alias.c
> +++ b/scripts/mod/file2alias.c
> @@ -1571,9 +1571,7 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
> zeros = calloc(1, sym->st_size);
> symval = zeros;
> } else {
> - symval = (void *)info->hdr
> - + info->sechdrs[get_secindex(info, sym)].sh_offset
> - + sym->st_value;
> + symval = sym_get_data(info, sym);
> }
>
> /* First handle the "special" cases */
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 6370f9accb8e..26254e96c300 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -324,7 +324,7 @@ static void *sym_get_data_by_offset(const struct elf_info *info,
> return (void *)info->hdr + sechdr->sh_offset + offset;
> }
>
> -static void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym)
> +void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym)
> {
> return sym_get_data_by_offset(info, get_secindex(info, sym),
> sym->st_value);
> diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
> index 044bdfb894b7..4d8a1ae1d1e3 100644
> --- a/scripts/mod/modpost.h
> +++ b/scripts/mod/modpost.h
> @@ -187,6 +187,7 @@ void get_src_version(const char *modname, char sum[], unsigned sumlen);
> /* from modpost.c */
> char *read_text_file(const char *filename);
> char *get_line(char **stringp);
> +void *sym_get_data(const struct elf_info *info, const Elf_Sym *sym);
>
> enum loglevel {
> LOG_WARN,
> --
> 2.34.1
>
--
Thanks,
~Nick Desaulniers
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-07-25 16:53 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-19 16:52 [PATCH 1/2] modpost: drop executable ELF support Masahiro Yamada
2022-07-19 16:53 ` [PATCH 2/2] modpost: use sym_get_data() to get module device_table data Masahiro Yamada
2022-07-25 16:53 ` Nick Desaulniers
2022-07-25 16:49 ` [PATCH 1/2] modpost: drop executable ELF support Nick Desaulniers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).