From: Alan Modra <amodra@gmail.com>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: binutils@sourceware.org
Subject: Re: [PATCH v3] elf: Always honor the first definition in shared object and archive
Date: Fri, 5 Apr 2024 10:24:45 +1030 [thread overview]
Message-ID: <Zg89xSvOL/J8FyRO@squeak.grove.modra.org> (raw)
In-Reply-To: <20240315194350.2697266-1-hjl.tools@gmail.com>
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.
> + /* 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?
> + 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.
> @@ -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.
--
Alan Modra
Australia Development Lab, IBM
next prev parent reply other threads:[~2024-04-04 23:54 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 [this message]
2024-04-05 1:50 ` H.J. Lu
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=Zg89xSvOL/J8FyRO@squeak.grove.modra.org \
--to=amodra@gmail.com \
--cc=binutils@sourceware.org \
--cc=hjl.tools@gmail.com \
/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).