Re: [PATCH 1/3] modpost: factor out inst location calculation to section_rel()

From: Masahiro Yamada
Date: Sat Jun 24 2023 - 04:56:42 EST


On Sat, Jun 24, 2023 at 2:01 AM Nick Desaulniers
<ndesaulniers@xxxxxxxxxx> wrote:
>
> On Thu, Jun 22, 2023 at 10:38 PM Masahiro Yamada <masahiroy@xxxxxxxxxx> wrote:
> >
> > On Fri, Jun 23, 2023 at 3:25 AM Nick Desaulniers
> > <ndesaulniers@xxxxxxxxxx> wrote:
> > >
> > > On Tue, Jun 20, 2023 at 5:05 AM Masahiro Yamada <masahiroy@xxxxxxxxxx> wrote:
> > > >
> > > > diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> > > > index 6e0b8be32648..2551ac9d5bd3 100644
> > > > --- a/scripts/mod/modpost.c
> > > > +++ b/scripts/mod/modpost.c
> > > > @@ -1519,17 +1512,20 @@ static void section_rel(struct module *mod, struct elf_info *elf,
> > > > r_sym = ELF_R_SYM(r.r_info);
> > > > #endif
> > > > r.r_addend = 0;
> > > > +
> > > > + loc = sym_get_data_by_offset(elf, fsecndx, r.r_offset);
> > >
> > > Can we compute `loc` only for the three machine types?
> >
> >
> >
> > I believe you can compute the location in the same way for any architecture
> > because it is mentioned in ELF spec.
>
> Sure, but perhaps it's wasted work for other machine types?



I guess you missed the following code:


switch (elf->hdr->e_machine) {
case EM_386:
...
break;
case EM_ARM:
...
break;
case EM_MIPS:
...
break;
default:
fatal("Please add code to calculate addend for this architecture\n");
}




I believe other machines never call this function.
If it occurred, fatal() would immediately errors out,
but I have not heard such a breakage for far.

I believe only i386, mips and arm use REL.
The other architectures are RELA.



--
Best Regards
Masahiro Yamada