From: "H.J. Lu" <hjl.tools@gmail.com>
To: binutils@sourceware.org
Subject: [PATCH] elf: Add glibc version dependency only if needed
Date: Tue, 9 Jul 2024 01:48:54 -0700 [thread overview]
Message-ID: <20240709084854.3446407-1-hjl.tools@gmail.com> (raw)
There is no need to add a needed glibc version if the glibc base version
includes the needed glibc version.
PR ld/31966
* elflink.c (elf_link_add_glibc_verneed): Add glibc_minor_base.
Skip if the glibc base version includes the needed glibc version.
(_bfd_elf_link_add_glibc_version_dependency): Initialize
glibc_minor_base to INT_MAX and pass it to
elf_link_add_glibc_verneed.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
bfd/elflink.c | 32 +++++++++++++++++++++++---------
1 file changed, 23 insertions(+), 9 deletions(-)
diff --git a/bfd/elflink.c b/bfd/elflink.c
index cca0c67f960..a180e59e8ca 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -2247,16 +2247,19 @@ _bfd_elf_export_symbol (struct elf_link_hash_entry *h, void *data)
\f
/* Return the glibc version reference if VERSION_DEP is added to the
list of glibc version dependencies successfully. VERSION_DEP will
- be put into the .gnu.version_r section. */
+ be put into the .gnu.version_r section. GLIBC_MINOR_BASE is the
+ pointer to the glibc minor base version. */
static Elf_Internal_Verneed *
elf_link_add_glibc_verneed (struct elf_find_verdep_info *rinfo,
Elf_Internal_Verneed *glibc_verref,
- const char *version_dep)
+ const char *version_dep,
+ int *glibc_minor_base)
{
Elf_Internal_Verneed *t;
Elf_Internal_Vernaux *a;
size_t amt;
+ int minor_version = -1;
if (glibc_verref != NULL)
{
@@ -2272,8 +2275,6 @@ elf_link_add_glibc_verneed (struct elf_find_verdep_info *rinfo,
}
else
{
- bool is_glibc;
-
for (t = elf_tdata (rinfo->info->output_bfd)->verref;
t != NULL;
t = t->vn_nextref)
@@ -2287,7 +2288,6 @@ elf_link_add_glibc_verneed (struct elf_find_verdep_info *rinfo,
if (t == NULL)
return t;
- is_glibc = false;
for (a = t->vn_auxptr; a != NULL; a = a->vna_nextptr)
{
/* Return if VERSION_DEP dependency has been added. */
@@ -2296,12 +2296,24 @@ elf_link_add_glibc_verneed (struct elf_find_verdep_info *rinfo,
return t;
/* Check if libc.so provides GLIBC_2.XX version. */
- if (!is_glibc && startswith (a->vna_nodename, "GLIBC_2."))
- is_glibc = true;
+ if (startswith (a->vna_nodename, "GLIBC_2."))
+ {
+ minor_version = strtol (a->vna_nodename + 8, NULL, 10);
+ if (minor_version < *glibc_minor_base)
+ *glibc_minor_base = minor_version;
+ }
}
/* Skip if it isn't linked against glibc. */
- if (!is_glibc)
+ if (minor_version < 0)
+ return NULL;
+ }
+
+ /* Skip if 2.GLIBC_MINOR_BASE includes VERSION_DEP. */
+ if (startswith (version_dep, "GLIBC_2."))
+ {
+ minor_version = strtol (version_dep + 8, NULL, 10);
+ if (minor_version <= *glibc_minor_base)
return NULL;
}
@@ -2333,10 +2345,12 @@ _bfd_elf_link_add_glibc_version_dependency
const char *version_dep[])
{
Elf_Internal_Verneed *t = NULL;
+ int glibc_minor_base = INT_MAX;
do
{
- t = elf_link_add_glibc_verneed (rinfo, t, *version_dep);
+ t = elf_link_add_glibc_verneed (rinfo, t, *version_dep,
+ &glibc_minor_base);
/* Return if there is no glibc version reference. */
if (t == NULL)
return;
--
2.45.2
next reply other threads:[~2024-07-09 8:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-09 8:48 H.J. Lu [this message]
2024-07-09 9:30 ` Andreas Schwab
2024-07-09 11:06 ` H.J. Lu
2024-07-09 21:40 ` 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=20240709084854.3446407-1-hjl.tools@gmail.com \
--to=hjl.tools@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).