[2/2] libc-abis: Define ABSOLUTE ABI [BZ #19818][BZ #23307]

Message ID alpine.DEB.2.00.1806280905490.20622@tp.orcam.me.uk
State Not applicable
Headers

Commit Message

Maciej W. Rozycki June 28, 2018, 1:49 p.m. UTC
  On Wed, 27 Jun 2018, Florian Weimer wrote:

> > > Is this really necessary?  It essentially precludes backporting the
> > > fixes.
> >   Thank you for your input.  Of course bumping up the ABI version is not
> > itself required for the change to work, and all existing working binaries
> > will continue to.
> > 
> >   Technically it does not preclude backporting either, although of course
> > it is limited by the previous ABI bump, which is (in the reverse order by
> > version/date):
> 
> Maybe I misunderstood what you were trying to do here.
> 
> Will the EI_ABIVERSION in created binaries increase if the programmer simply
> upgrades binutils?  Or will this happen only when particular features are
> used?

 Only when this particular feature is required, like with the older ABI 
versions defined so far.  I've double-checked with binutils and the MIPS 
target is the only one actively switching EI_ABIVERSION; all the remaining 
targets appear to have the value fixed and I am not going to change that.

 This is how the relevant part of the linker update in question looks 
like:

and then `htab->use_absolute_zero' will be TRUE iff a GOT relocation has 
been calculated to actually refer to a specially-created absolute symbol 
used to address the issue covered by binutils PR ld/21375.

 The flag will be FALSE if code has been relaxed to avoid referring the 
GOT (by using immediate zero instead), in which case no absolute symbol 
will have been specially created.

 Does this explanation clear your concern?

  Maciej
  

Comments

Florian Weimer June 28, 2018, 1:54 p.m. UTC | #1
On 06/28/2018 03:49 PM, Maciej W. Rozycki wrote:
> +  /* Mark that we need support for absolute symbols in the dynamic loader.  */
> +  if (htab != NULL && htab->use_absolute_zero)
> +    i_ehdrp->e_ident[EI_ABIVERSION] = MIPS_LIBC_ABI_ABSOLUTE;
> +
>     _bfd_elf_post_process_headers (abfd, link_info);
>   }
>   
> and then `htab->use_absolute_zero' will be TRUE iff a GOT relocation has
> been calculated to actually refer to a specially-created absolute symbol
> used to address the issue covered by binutils PR ld/21375.
> 
>   The flag will be FALSE if code has been relaxed to avoid referring the
> GOT (by using immediate zero instead), in which case no absolute symbol
> will have been specially created.
> 
>   Does this explanation clear your concern?

Yes, I think this is okay then.

We cannot express this change at the RPM dependency level, but I'm not 
sure how active the Fedora MIPS port is these days, so it probably does 
not matter.

Thanks,
Florian
  
Maciej W. Rozycki June 28, 2018, 2:53 p.m. UTC | #2
On Thu, 28 Jun 2018, Florian Weimer wrote:

> On 06/28/2018 03:49 PM, Maciej W. Rozycki wrote:
> > +  /* Mark that we need support for absolute symbols in the dynamic loader.
> > */
> > +  if (htab != NULL && htab->use_absolute_zero)
> > +    i_ehdrp->e_ident[EI_ABIVERSION] = MIPS_LIBC_ABI_ABSOLUTE;
> > +
> >     _bfd_elf_post_process_headers (abfd, link_info);
> >   }
> >   and then `htab->use_absolute_zero' will be TRUE iff a GOT relocation has
> > been calculated to actually refer to a specially-created absolute symbol
> > used to address the issue covered by binutils PR ld/21375.
> > 
> >   The flag will be FALSE if code has been relaxed to avoid referring the
> > GOT (by using immediate zero instead), in which case no absolute symbol
> > will have been specially created.
> > 
> >   Does this explanation clear your concern?
> 
> Yes, I think this is okay then.

 Great!

> We cannot express this change at the RPM dependency level, but I'm not sure
> how active the Fedora MIPS port is these days, so it probably does not matter.

 The case of MIPS_LIBC_ABI_ABSOLUTE is supposed to be exceedingly rare.  
However I decided to handle it, rather than having the linker fail, be it 
with an assertion failure or gracefully.

 I think RPM could be easily expanded to include EI_ABIVERSION with its 
existing dependency mechanism.  The EI_ABIVERSION field is reported by 
`readelf -h', so the requirement could be easily extracted from binaries 
just like symbol versioning information is.

 The only complication is the package supplying the dynamic loader, where 
the provision of the maximum value of EI_ABIVERSION supported would I 
think have to be entered manually in the package spec.

 Decades ago I modified the RPM dependency extraction scripts (`linux.req' 
and `linux.prov') to use `readelf' rather than a combination of `objdump' 
and `ldd' (although I left the latter as a fallback to keep supporting 
a.out dependencies), so that dependencies were right for cross-compiled 
packages.

 I have never submitted that work back (as I recall it was not exactly 
easy to get through), however experience gained with that makes me think 
expanding the mechanism to include EI_ABIVERSION should be straightforward 
to implement.  Perhaps it would be worth doing anyway, just in case?

 NB I have no idea what RPM uses these days for dependency tracking and 
whether it handles cross-compilation right or not.  Work I did back then 
remains available from `ftp.linux-mips.org', in the form of RPM 3.0.6 RPM 
packages; the GNU GPL applies.

  Maciej
  
Maciej W. Rozycki June 29, 2018, 4:29 p.m. UTC | #3
On Thu, 28 Jun 2018, Maciej W. Rozycki wrote:

> > > +  /* Mark that we need support for absolute symbols in the dynamic loader.
> > > */
> > > +  if (htab != NULL && htab->use_absolute_zero)
> > > +    i_ehdrp->e_ident[EI_ABIVERSION] = MIPS_LIBC_ABI_ABSOLUTE;
> > > +
> > >     _bfd_elf_post_process_headers (abfd, link_info);
> > >   }
> > >   and then `htab->use_absolute_zero' will be TRUE iff a GOT relocation has
> > > been calculated to actually refer to a specially-created absolute symbol
> > > used to address the issue covered by binutils PR ld/21375.
> > > 
> > >   The flag will be FALSE if code has been relaxed to avoid referring the
> > > GOT (by using immediate zero instead), in which case no absolute symbol
> > > will have been specially created.
> > > 
> > >   Does this explanation clear your concern?
> > 
> > Yes, I think this is okay then.
> 
>  Great!

 Any further input?  Have we reached consensus?

 If so, then I think a NEWS entry will be due, such as:

* The maximum libc ABI supported has been increased to reflect absolute
  symbol support.  This can be used by the static linker in the ELF file
  header's EI_ABIVERSION field to indicate such support is required.

which I will include in the actual commit.

  Maciej
  
Carlos O'Donell July 3, 2018, 1:52 p.m. UTC | #4
On 06/29/2018 12:29 PM, Maciej W. Rozycki wrote:
> On Thu, 28 Jun 2018, Maciej W. Rozycki wrote:
> 
>>>> +  /* Mark that we need support for absolute symbols in the dynamic loader.
>>>> */
>>>> +  if (htab != NULL && htab->use_absolute_zero)
>>>> +    i_ehdrp->e_ident[EI_ABIVERSION] = MIPS_LIBC_ABI_ABSOLUTE;
>>>> +
>>>>     _bfd_elf_post_process_headers (abfd, link_info);
>>>>   }
>>>>   and then `htab->use_absolute_zero' will be TRUE iff a GOT relocation has
>>>> been calculated to actually refer to a specially-created absolute symbol
>>>> used to address the issue covered by binutils PR ld/21375.
>>>>
>>>>   The flag will be FALSE if code has been relaxed to avoid referring the
>>>> GOT (by using immediate zero instead), in which case no absolute symbol
>>>> will have been specially created.
>>>>
>>>>   Does this explanation clear your concern?
>>>
>>> Yes, I think this is okay then.
>>
>>  Great!
> 
>  Any further input?  Have we reached consensus?
> 
>  If so, then I think a NEWS entry will be due, such as:
> 
> * The maximum libc ABI supported has been increased to reflect absolute
>   symbol support.  This can be used by the static linker in the ELF file
>   header's EI_ABIVERSION field to indicate such support is required.

Suggest:

* The GNU C Library now has correct support for ABSOLUTE symbols
  (SHN_ABS-relative symbols).  Previously such ABSOLUTE symbols were relocated
  inconsistently or wrongly in some cases.  The GNU linker has been enhanced to
  fix this issue, but it must communicate these newer semantics to the dynamic
  loader by setting the ELF file's identification (EI_ABIVERSION field) to 
  indicate such support is required.
 
> which I will include in the actual commit.

This looks good to me.

I don't see an easy way around this problem.

I think bumping EI_ABIVERSION is the best cost/value solution there.
  

Patch

Index: binutils/bfd/elfxx-mips.c
===================================================================
--- binutils.orig/bfd/elfxx-mips.c	2018-06-28 00:44:35.780943617 +0100
+++ binutils/bfd/elfxx-mips.c	2018-06-28 00:44:35.913406279 +0100
@@ -16305,13 +16449,14 @@  enum
   MIPS_LIBC_ABI_MIPS_PLT,
   MIPS_LIBC_ABI_UNIQUE,
   MIPS_LIBC_ABI_MIPS_O32_FP64,
+  MIPS_LIBC_ABI_ABSOLUTE,
   MIPS_LIBC_ABI_MAX
 };
 
 void
 _bfd_mips_post_process_headers (bfd *abfd, struct bfd_link_info *link_info)
 {
-  struct mips_elf_link_hash_table *htab;
+  struct mips_elf_link_hash_table *htab = NULL;
   Elf_Internal_Ehdr *i_ehdrp;
 
   i_ehdrp = elf_elfheader (abfd);
@@ -16319,15 +16464,19 @@  _bfd_mips_post_process_headers (bfd *abf
     {
       htab = mips_elf_hash_table (link_info);
       BFD_ASSERT (htab != NULL);
-
-      if (htab->use_plts_and_copy_relocs && !htab->is_vxworks)
-	i_ehdrp->e_ident[EI_ABIVERSION] = MIPS_LIBC_ABI_MIPS_PLT;
     }
 
+  if (htab != NULL && htab->use_plts_and_copy_relocs && !htab->is_vxworks)
+    i_ehdrp->e_ident[EI_ABIVERSION] = MIPS_LIBC_ABI_MIPS_PLT;
+
   if (mips_elf_tdata (abfd)->abiflags.fp_abi == Val_GNU_MIPS_ABI_FP_64
       || mips_elf_tdata (abfd)->abiflags.fp_abi == Val_GNU_MIPS_ABI_FP_64A)
     i_ehdrp->e_ident[EI_ABIVERSION] = MIPS_LIBC_ABI_MIPS_O32_FP64;
 
+  /* Mark that we need support for absolute symbols in the dynamic loader.  */
+  if (htab != NULL && htab->use_absolute_zero)
+    i_ehdrp->e_ident[EI_ABIVERSION] = MIPS_LIBC_ABI_ABSOLUTE;
+
   _bfd_elf_post_process_headers (abfd, link_info);
 }