From: "H.J. Lu" <hjl.tools@gmail.com>
To: Alan Modra <amodra@gmail.com>
Cc: binutils@sourceware.org
Subject: Re: [PATCH v3] elf: Always honor the first definition in shared object and archive
Date: Thu, 4 Apr 2024 18:50:27 -0700 [thread overview]
Message-ID: <CAMe9rOoW9=CfCGtU_s20Ns+yLSuiA4QbRutmD4X4cH=AzJKgdw@mail.gmail.com> (raw)
In-Reply-To: <Zg89xSvOL/J8FyRO@squeak.grove.modra.org>
On Thu, Apr 4, 2024 at 4:54 PM Alan Modra <amodra@gmail.com> wrote:
>
> On Fri, Mar 15, 2024 at 12:43:50PM -0700, H.J. Lu wrote:
> > GCC doesn't put builtin function symbol references, which are defined in
> > the shared C library, in the IR symbol table.
>
> Should we be covering for what looks like a gcc bug? At the expense
> of yet another hash table.
I think we should. The built function references may be inlined by GCC.
It is reasonable for them not to show up in IR symbol tables.
> > + /* Hash table of symbols which are first defined in archives or shared
> > + objects when there are any IR inputs. */
> > + struct bfd_link_hash_table *first_hash;
> > +
>
> It looks to me that you just need a hash table that maps a symbol name
> to a bfd. Maybe use libiberty/hashtab.c hash instead, to cut down
> memory for entries?
I prefer not to deal with libiberty/hashtab.c.
> > + if (e->type == bfd_link_hash_new)
> > + {
> > + /* Change the type to bfd_link_hash_defined and
> > + store ABFD in u.undef->abfd. */
> > + e->type = bfd_link_hash_defined;
> > + e->u.undef.abfd = abfd;
> > + }
>
> That's a bit rude, using bfd_link_hash_defined and a union field that
> belongs to bfd_link_hash_undefined.
I changed it to bfd_link_hash_undefined.
> > @@ -5963,7 +6017,30 @@ _bfd_elf_archive_symbol_lookup (bfd *abfd,
> >
> > p = strchr (name, ELF_VER_CHR);
> > if (p == NULL || p[1] != ELF_VER_CHR)
> > - return h;
> > + {
> > + struct elf_link_hash_table *htab = elf_hash_table (info);
> > + if (htab->first_hash != NULL)
> > + {
> > + /* Add this symbol to first hash if this archive has the
> > + first definition. */
> > + struct bfd_link_hash_entry *e
> > + = bfd_link_hash_lookup (htab->first_hash, name, true,
> > + false, true);
> > + if (e == NULL)
> > + info->callbacks->einfo
> > + (_("%F%P: %pB: failed to add %s to first hash\n"),
> > + abfd, name);
> > +
> > + if (e->type == bfd_link_hash_new)
> > + {
> > + /* Change the type to bfd_link_hash_defined and store
> > + ABFD in u.undef->abfd. */
> > + e->type = bfd_link_hash_defined;
> > + e->u.undef.abfd = abfd;
> > + }
> > + }
> > + return h;
> > + }
>
> At first glance this looks like a duplicate of the code in
> elf_link_add_object_symbols adding an entry to first_hash, and
> therefore could be extracted to a common function.
>
I added elf_link_add_to_first_hash in the v2 patch:
https://sourceware.org/pipermail/binutils/2024-April/133395.html
Thanks.
--
H.J.
prev parent reply other threads:[~2024-04-05 1:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-15 19:43 H.J. Lu
2024-03-28 13:30 ` PING: " H.J. Lu
2024-04-04 13:29 ` PING^2: " H.J. Lu
2024-04-05 10:15 ` Nick Clifton
2024-04-05 12:00 ` H.J. Lu
2024-04-05 22:16 ` Alan Modra
2024-04-05 23:37 ` H.J. Lu
2024-04-05 23:45 ` Alan Modra
2024-04-05 23:48 ` H.J. Lu
2024-04-04 23:54 ` Alan Modra
2024-04-05 1:50 ` H.J. Lu [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAMe9rOoW9=CfCGtU_s20Ns+yLSuiA4QbRutmD4X4cH=AzJKgdw@mail.gmail.com' \
--to=hjl.tools@gmail.com \
--cc=amodra@gmail.com \
--cc=binutils@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).