Re: [PATCH 2/5] readelf: Adapt src/readelf -h/-S/-r/-w/-l/-d/-a on mips

2023-08-01 Thread Mark Wielaard
Hi Ying,

On Mon, 2023-07-24 at 16:35 +0800, Ying Huang wrote:
> Hi Mark,
> 
> > > diff --git a/libebl/eblreloctypecheck.c b/libebl/eblreloctypecheck.c
> > > index 80e67ef7..e3c43944 100644
> > > --- a/libebl/eblreloctypecheck.c
> > > +++ b/libebl/eblreloctypecheck.c
> > > @@ -32,10 +32,14 @@
> > > #endif
> > > 
> > >  #include 
> 
> > > -
> > > +#include 
> 
> > > 
> > > bool
> > > ebl_reloc_type_check (Ebl *ebl, int reloc)
> > > {
> > > - return ebl != NULL ? ebl->reloc_type_check (reloc) : false;
> > > + int relocNew = reloc;
> > > + GElf_Ehdr ehdr;
> > > + if(ebl->elf->class == ELFCLASS64 && gelf_getehdr(ebl->elf, &ehdr) != 
> > > NULL && ehdr.e_machine == EM_MIPS)
> > > + relocNew = ELF64_MIPS_R_TYPE(reloc);
> > > + return ebl != NULL ? ebl->reloc_type_check (relocNew) : false;
> > > }
> > This should not go into the generic ebl_reloc_type_check but has to be
> > hooked so it uses a mips_reloc_type_check.
> > 
> > > diff --git a/libebl/eblreloctypename.c b/libebl/eblreloctypename.c
> > > index e53ec0c0..4276d8e3 100644
> > > --- a/libebl/eblreloctypename.c
> > > +++ b/libebl/eblreloctypename.c
> > > @@ -33,14 +33,18 @@
> > > 
> > >  #include 
> 
> > >  #include 
> 
> > > -
> > > +#include 
> 
> > > 
> > > const char *
> > > ebl_reloc_type_name (Ebl *ebl, int reloc, char *buf, size_t len)
> > > {
> > > const char *res;
> > > + int relocNew = reloc;
> > > + GElf_Ehdr ehdr;
> > > + if(ebl->elf->class == ELFCLASS64 && gelf_getehdr(ebl->elf, &ehdr) != 
> > > NULL && ehdr.e_machine == EM_MIPS)
> > > + relocNew = ELF64_MIPS_R_TYPE(reloc);
> > > 
> > > - res = ebl != NULL ? ebl->reloc_type_name (reloc, buf, len) : NULL;
> > > + res = ebl != NULL ? ebl->reloc_type_name (relocNew, buf, len) : NULL;
> > > if (res == NULL)
> > > /* There are no generic relocation type names. */
> > >  res = "";
> > Likewise for hooking reloc_type_name.
> > 
> The function reloc_type_check and reloc_type_name were common hooks in file 
> backends/common-reloc.c, so if we also need a new hook for mips and copy the 
> check codes from common-reloc.c?

There are no other arches which use those hooks at the moment. But you
should be able to simply define them as mips_reloc_type_xxx and then
HOOK them in your mips.c init function.

Cheers,

Mark


Re: [PATCH 2/5] readelf: Adapt src/readelf -h/-S/-r/-w/-l/-d/-a on mips

2023-08-01 Thread Mark Wielaard
Hi Ying,

On Tue, 2023-07-25 at 16:15 +0800, Ying Huang wrote:
> In file common-reloc.c, hook functions 
> reloc_type_check/reloc_type_use/reloc_type_name have these codes:
> 
> #ifdef RELOC_TYPE_ID
>   reloc = RELOC_TYPE_ID (reloc);
> #endif
> 
> And the macro RELOC_TYPE_ID was defined in file backends/sparc_init.c:
> 
> /* In SPARC some relocations use the most significative 24 bits of the
>    r_type field to encode a secondary addend.  Make sure the routines
>    in common-reloc.c acknowledge this.  */
> #define RELOC_TYPE_ID(type) ((type) & 0xff)
> 
> The contents of macro RELOC_TYPE_ID were same as ELF64_MIPS_R_TYPE(new 
> added), so my view is did not add new hook for mips, if we can do like sparc?

Sorry, hadn't seen this message before. But yes, if you can do like
sparc and define RELOC_TYPE_ID then that would be simpler than creating
a full new HOOK for reloc_type_check.

Cheers,

Mark


Re: [PATCH 2/5] readelf: Adapt src/readelf -h/-S/-r/-w/-l/-d/-a on mips

2023-08-01 Thread Mark Wielaard
Hi Ying,

On Thu, Jul 27, 2023 at 02:08:52PM +0800, Ying Huang wrote:
>
> Can we add a new file mips.h in backends, and move defines of
> ELF64_MIPS_R_TYPE/ELF64_MIPS_R_TYPE2/ELF64_MIPS_R_TYPE3 from elf.h
> to mips.h?
>
> And rename the macro name ELF64_MIPS_R_TYPE to ELF64_MIPS_R_TYPE1 in
> mips.h? Or rename it directly in elf.h of glibc?

I would prefer the macros to get defined in elf.h if they are
generally useful to get at the relocation type. But if that isn't
possible we can certainly define them in some internal header file.

Is there a specific mips elf specification we are following?

Cheers,

Mark