PING^2: [PATCH v3] elf: Always honor the first definition in shared object and archive

Alan Modra amodra@gmail.com
Fri Apr 5 23:45:35 GMT 2024


On Fri, Apr 05, 2024 at 04:37:11PM -0700, H.J. Lu wrote:
> On Fri, Apr 5, 2024 at 3:16 PM Alan Modra <amodra@gmail.com> wrote:
> >
> > On Fri, Apr 05, 2024 at 05:00:28AM -0700, H.J. Lu wrote:
> > > On Fri, Apr 5, 2024 at 3:15 AM Nick Clifton <nickc@redhat.com> wrote:
> > > >
> > > > Hi H.J.
> > > >
> > > > >>> GCC doesn't put builtin function symbol references, which are defined in
> > > > >>> the shared C library, in the IR symbol table.  When linker rescans shared
> > > > >>> objects and archives for newly added symbol references generated from the
> > > > >>> IR inputs, it skips definitions of the builtin functions in shared
> > > > >>> objects and archives.
> > > > >>>
> > > > >>> Add first_hash to elf_link_hash_table to track unreferenced definitions
> > > > >>> defined first in shared objects and archives.  Always use them to resolve
> > > > >>> any references.
> > > >
> > > > Approved - please apply.
> > > >
> > > > Cheers
> > > >    Nick
> > > >
> > >
> > > I am checking in the v2 patch:
> > >
> > > https://sourceware.org/pipermail/binutils/2024-April/133395.html
> >
> > I had some further requests to make.
> > 1) If you are going to use a bfd_hash_table based first_hash, please
> > don't use bfd_link_hash_table.  Instead extend bfd_hash_entry with a
> > single abfd field.  You'll need to write a newfunc, but that's about
> > all that is required.  There are multiple examples of this in the
> > source, eg. bfd/stabs.c stab_link_includes_entry.
> 
> I will add
> 
> /* An entry in the first definition hash table.  */
> 
> struct elf_link_first_hash_entry
> {
>   struct bfd_hash_entry root;
>   /* The object of the first definition.  */
>   bfd *abfd;
> };
> 
> > 2) You are accessing freed memory in _bfd_elf_link_hash_table_free.
> > Free first_hash before freeing the main hash table.  That needs fixing
> > immediately.
> 
> I will change it to
> 
>   if (htab->first_hash != NULL)
>     {
>       bfd_hash_table_free (htab->first_hash);
>       free (htab->first_hash);
>     }
>   _bfd_generic_link_hash_table_free (obfd);

Thanks, that along with the elf_link_first_hast_entry change is
preapproved.

> > 3) Please ensure tests have different names.  This
> >   [list {pr31482a} \
> >    {-Wl,--no-as-needed,-R,tmpdir} {} \
> >    {pr31482a.c} {pr31482a.exe} {pass.out} {-flto} {c} {} \
> >    {tmpdir/pr31482b.a tmpdir/pr31482c.so}] \
> >   [list {pr31482b} \
> >    {-Wl,--no-as-needed,-R,tmpdir} {} \
> >    {pr31482a.c} {pr31482b.exe} {pass1.out} {-flto} {c} {} \
> >    {tmpdir/pr31482c.so tmpdir/pr31482b.a}] \
> >   [list {pr31489a} \
> >    {-Wl,--as-needed,-R,tmpdir} {} \
> >    {pr31482a.c} {pr31489a.exe} {pass.out} {-flto} {c} {} \
> >    {tmpdir/pr31482b.a tmpdir/pr31482c.so}] \
> >   [list {pr31489b} \
> >    {-Wl,--as-needed,-R,tmpdir} {} \
> >    {pr31482a.c} {pr31489b.exe} {pass1.out} {-flto} {c} {} \
> >    {tmpdir/pr31482c.so tmpdir/pr31482b.a}] \
> > has two tests called pr31489a and two called pr31489b.
> > "FAIL: pr31489a" as the output of make check isn't as helpful as it
> > could be.  Better would be to add --no-as-needed and --as-needed to
> > the test names.
> >
> 
> I got
> 
> ld-plugin/lto.exp:  [list {pr31489a} \
> ld-plugin/lto.exp:   {pr31482a.c} {pr31489a.exe} {pass.out} {-flto} {c} {} \
> 
> and
> 
> ld-plugin/lto.exp:  [list {pr31489b} \
> ld-plugin/lto.exp:   {pr31482a.c} {pr31489b.exe} {pass1.out} {-flto} {c} {} \
> 
> I only saw one pr31489a and one pr31489b.  Where are
> the second ones?

Oops.  You chose different pr numbers.  I can't read, sorry.  :-(

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list