public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* The definition of ELF64_MIPS_R_TYPE is ambiguous
@ 2023-07-23  4:52 YunQiang Su
  2023-07-23  6:51 ` Andreas Schwab
  0 siblings, 1 reply; 5+ messages in thread
From: YunQiang Su @ 2023-07-23  4:52 UTC (permalink / raw)
  To: binutils, Libc-alpha

With some search of the definition of ELF64_MIPS_R_TYPE macro, we find
that they are defined differently between projects.
http://codesearch.debian.net/search?q=ELF64_MIPS_R_TYPE

1. In binutils-gdb/include/elf/mips.h, it is defined as:
    #define ELF64_MIPS_R_TYPE(i) ((i) & 0xff)

    newlib/include/elf/elf.h, linux/scripts/mod/modpost.h, libiberty,
are using a similar definition.

2. In glibc/sysdeps/mips/ldsodefs.h, it is defined as:
    #define ELF64_MIPS_R_TYPE(i) \
  (((_Elf64_Mips_R_Info_union)(i)).r_info_fields.r_type1 \
   | ((Elf32_Word)(__extension__ (_Elf64_Mips_R_Info_union)(i) \
                   ).r_info_fields.r_type2 << 8) \
   | ((Elf32_Word)(__extension__ (_Elf64_Mips_R_Info_union)(i) \
                   ).r_info_fields.r_type3 << 16) \
   | ((Elf32_Word)(__extension__ (_Elf64_Mips_R_Info_union)(i) \
                  ).r_info_fields.r_ssym << 24))

   uclibc/ldso/ldso/mips/dl-sysdep.h is using a similar definition.


I think that we should sync all of them to protect people from confusion.
We are lucky enough that ELF64_MIPS_R_TYPE is not used widely by normal APPs.
So it gives us the chance to make it sync between projects.
Any suggestions?

For myself, I prefer the way of glibc/uclibc:
1. Define ELF64_MIPS_R_TYPE1 for the lowest byte of r_info.
2. Define ELF64_MIPS_R_TYPE for full r_info.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: The definition of ELF64_MIPS_R_TYPE is ambiguous
  2023-07-23  4:52 The definition of ELF64_MIPS_R_TYPE is ambiguous YunQiang Su
@ 2023-07-23  6:51 ` Andreas Schwab
  2023-07-23  7:11   ` YunQiang Su
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2023-07-23  6:51 UTC (permalink / raw)
  To: YunQiang Su via Libc-alpha; +Cc: binutils, YunQiang Su

On Jul 23 2023, YunQiang Su via Libc-alpha wrote:

> I think that we should sync all of them to protect people from confusion.
> We are lucky enough that ELF64_MIPS_R_TYPE is not used widely by normal APPs.
> So it gives us the chance to make it sync between projects.

Is the macro defined by the ELF psABI?

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: The definition of ELF64_MIPS_R_TYPE is ambiguous
  2023-07-23  6:51 ` Andreas Schwab
@ 2023-07-23  7:11   ` YunQiang Su
  2023-07-23  7:18     ` Andreas Schwab
  0 siblings, 1 reply; 5+ messages in thread
From: YunQiang Su @ 2023-07-23  7:11 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: YunQiang Su via Libc-alpha, binutils

Andreas Schwab <schwab@linux-m68k.org> 于2023年7月23日周日 14:51写道:
>
> On Jul 23 2023, YunQiang Su via Libc-alpha wrote:
>
> > I think that we should sync all of them to protect people from confusion.
> > We are lucky enough that ELF64_MIPS_R_TYPE is not used widely by normal APPs.
> > So it gives us the chance to make it sync between projects.
>
> Is the macro defined by the ELF psABI?
>

As best as I know, the answer is no. (Correct me if anybody know about it.)

> --
> Andreas Schwab, schwab@linux-m68k.org
> GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
> "And now for something completely different."



-- 
YunQiang Su

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: The definition of ELF64_MIPS_R_TYPE is ambiguous
  2023-07-23  7:11   ` YunQiang Su
@ 2023-07-23  7:18     ` Andreas Schwab
  2023-08-07 11:09       ` Maciej W. Rozycki
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2023-07-23  7:18 UTC (permalink / raw)
  To: YunQiang Su; +Cc: YunQiang Su via Libc-alpha, binutils

On Jul 23 2023, YunQiang Su wrote:

> Andreas Schwab <schwab@linux-m68k.org> 于2023年7月23日周日 14:51写道:
>>
>> On Jul 23 2023, YunQiang Su via Libc-alpha wrote:
>>
>> > I think that we should sync all of them to protect people from confusion.
>> > We are lucky enough that ELF64_MIPS_R_TYPE is not used widely by normal APPs.
>> > So it gives us the chance to make it sync between projects.
>>
>> Is the macro defined by the ELF psABI?
>>
>
> As best as I know, the answer is no. (Correct me if anybody know about it.)

Then it should not be defined in any shared header related to ELF ABI
definitions, especially not in glibc's elf.h.  It should remain private
to each project.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: The definition of ELF64_MIPS_R_TYPE is ambiguous
  2023-07-23  7:18     ` Andreas Schwab
@ 2023-08-07 11:09       ` Maciej W. Rozycki
  0 siblings, 0 replies; 5+ messages in thread
From: Maciej W. Rozycki @ 2023-08-07 11:09 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: YunQiang Su, YunQiang Su via Libc-alpha, binutils

On Sun, 23 Jul 2023, Andreas Schwab wrote:

> >> > I think that we should sync all of them to protect people from confusion.
> >> > We are lucky enough that ELF64_MIPS_R_TYPE is not used widely by normal APPs.
> >> > So it gives us the chance to make it sync between projects.
> >>
> >> Is the macro defined by the ELF psABI?
> >>
> >
> > As best as I know, the answer is no. (Correct me if anybody know about it.)
> 
> Then it should not be defined in any shared header related to ELF ABI
> definitions, especially not in glibc's elf.h.  It should remain private
> to each project.

 FWIW the 64-bit MIPS psABI[1] has instead redefined Elf64_Rela and 
Elf64_Rel structures (previously supplied by SPARC International with 
their 64-bit extensions to the original 32-bit ELF gABI):

typedef struct
{
  Elf64_Addr	r_offset;
  Elf64_Word	r_sym;
  Elf64_Byte	r_ssym;
  Elf64_Byte	r_type3;
  Elf64_Byte	r_type2;
  Elf64_Byte	r_type;
} Elf64_Rel;

typedef struct
{
  Elf64_Addr	r_offset;
  Elf64_Word	r_sym;
  Elf64_Byte	r_ssym;
  Elf64_Byte	r_type3;
  Elf64_Byte	r_type2;
  Elf64_Byte	r_type;
  Elf64_Sxword	r_addend;
} Elf64_Rela;

(transcribed from a language-agnostic representation).  I'm not sure if it 
can be factored in anyhow in <elf.h>.

 Observe the endianness-independent layout of the five fields following 
`r_offset', which makes macros such as ELF64_MIPS_R_TYPE unsuitable for 
use in the little-endian case with unprocessed `r_info' field as defined 
by 64-bit ELF gABI.

[1] "64-bit ELF Object File Specification", Draft Version 2.5, MIPS 
    Technologies / Silicon Graphics Computer Systems, Document Number 
    007-4658-001, Table 29 "Relocation Operation (Elf64_Rel, Elf64_Rela)", 
    p. 40

  Maciej

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-08-07 11:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-23  4:52 The definition of ELF64_MIPS_R_TYPE is ambiguous YunQiang Su
2023-07-23  6:51 ` Andreas Schwab
2023-07-23  7:11   ` YunQiang Su
2023-07-23  7:18     ` Andreas Schwab
2023-08-07 11:09       ` Maciej W. Rozycki

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 read-only IMAP folder(s) and NNTP newsgroup(s).