public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: libc-alpha@sourceware.org
Subject: [PATCH 3/4] elf: Generalize name-based DSO recognition in ldconfig
Date: Thu, 10 Jun 2021 10:23:11 +0200	[thread overview]
Message-ID: <f1b7632ac80967bc23998c05f5a7c4d76c6e779c.1623312996.git.fweimer@redhat.com> (raw)
In-Reply-To: <cover.1623312996.git.fweimer@redhat.com>

This introduces <dl-is_dso.h> and the _dl_is_dso function.  A
test ensures that the official names of libc.so, ld.so, and their
versioned names are recognized.
---
 elf/Makefile        |  2 +-
 elf/dl-is_dso.h     | 33 +++++++++++++++++++++++++++++++++
 elf/ldconfig.c      |  5 ++---
 elf/tst-dl-is_dso.c | 35 +++++++++++++++++++++++++++++++++++
 4 files changed, 71 insertions(+), 4 deletions(-)
 create mode 100644 elf/dl-is_dso.h
 create mode 100644 elf/tst-dl-is_dso.c

diff --git a/elf/Makefile b/elf/Makefile
index 5c47daee12..1751f5ec67 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -223,7 +223,7 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \
 	 tst-single_threaded tst-single_threaded-pthread \
 	 tst-tls-ie tst-tls-ie-dlmopen argv0test \
 	 tst-glibc-hwcaps tst-glibc-hwcaps-prepend tst-glibc-hwcaps-mask \
-	 tst-tls20 tst-tls21 tst-dlmopen-dlerror
+	 tst-tls20 tst-tls21 tst-dlmopen-dlerror tst-dl-is_dso
 #	 reldep9
 tests-internal += loadtest unload unload2 circleload1 \
 	 neededtest neededtest2 neededtest3 neededtest4 \
diff --git a/elf/dl-is_dso.h b/elf/dl-is_dso.h
new file mode 100644
index 0000000000..94e00966a1
--- /dev/null
+++ b/elf/dl-is_dso.h
@@ -0,0 +1,33 @@
+/* Heuristic for recognizing DSO file names.
+   Copyright (C) 2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <stdbool.h>
+#include <string.h>
+
+/* Returns true if the file name looks like a DSO name.  */
+static bool
+_dl_is_dso (const char *name)
+{
+  /* Recognize lib*.so*, ld-*.so*, ld.so.*, ld64.so.*.  ld-*.so*
+     matches both platform dynamic linker names like ld-linux.so.2,
+     and versioned dynamic loader names like ld-2.12.so.  */
+  return (((strncmp (name, "lib", 3) == 0 || strncmp (name, "ld-", 3) == 0)
+           && strstr (name, ".so") != NULL)
+          || strncmp (name, "ld.so.", 6) == 0
+          || strncmp (name, "ld64.so.", 8) == 0);
+}
diff --git a/elf/ldconfig.c b/elf/ldconfig.c
index 96bf7700b2..1037e8d0cf 100644
--- a/elf/ldconfig.c
+++ b/elf/ldconfig.c
@@ -43,6 +43,7 @@
 #include <ldconfig.h>
 #include <dl-cache.h>
 #include <dl-hwcaps.h>
+#include <dl-is_dso.h>
 
 #include <dl-procinfo.h>
 
@@ -842,9 +843,7 @@ search_dir (const struct dir_entry *entry)
 	 subdirectory (if not already processing a glibc-hwcaps
 	 subdirectory)?  The dynamic linker is also considered as
 	 shared library.  */
-      if (((strncmp (direntry->d_name, "lib", 3) != 0
-	    && strncmp (direntry->d_name, "ld-", 3) != 0)
-	   || strstr (direntry->d_name, ".so") == NULL)
+      if (!_dl_is_dso (direntry->d_name)
 	  && (direntry->d_type == DT_REG
 	      || (entry->hwcaps == NULL
 		  && !is_hwcap_platform (direntry->d_name))))
diff --git a/elf/tst-dl-is_dso.c b/elf/tst-dl-is_dso.c
new file mode 100644
index 0000000000..48d2cc9fbe
--- /dev/null
+++ b/elf/tst-dl-is_dso.c
@@ -0,0 +1,35 @@
+/* Test heuristic for recognizing DSO file names.
+   Copyright (C) 2021 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <dl-is_dso.h>
+#include <gnu/lib-names.h>
+#include <support/check.h>
+
+static int
+do_test (void)
+{
+  /* Official ABI names.  */
+  TEST_VERIFY (_dl_is_dso (LIBC_SO));
+  TEST_VERIFY (_dl_is_dso (LD_SO));
+  /* Version-based names.  The version number does not matter.  */
+  TEST_VERIFY (_dl_is_dso ("libc-2.12.so"));
+  TEST_VERIFY (_dl_is_dso ("ld-2.12.so"));
+  return 0;
+}
+
+#include <support/test-driver.c>
-- 
2.31.1



  parent reply	other threads:[~2021-06-10  8:23 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-10  8:22 [PATCH 0/4] Do not install shared objects under versioned names Florian Weimer
2021-06-10  8:23 ` [PATCH 1/4] nptl_db: Install libthread_db under a regular implementation name Florian Weimer
2021-06-27 21:32   ` Carlos O'Donell
2021-06-10  8:23 ` [PATCH 2/4] Makerules: Remove lib-version, $(subdir-version) Florian Weimer
2021-06-27 21:32   ` Carlos O'Donell
2021-06-10  8:23 ` Florian Weimer [this message]
2021-06-27 21:32   ` [PATCH 3/4] elf: Generalize name-based DSO recognition in ldconfig Carlos O'Donell
2021-06-10  8:23 ` [PATCH 4/4] Install shared objects under their ABI names Florian Weimer
2021-06-27 21:32   ` Carlos O'Donell
2021-06-14 11:04 ` [PATCH 0/4] Do not install shared objects under versioned names Florian Weimer
2021-06-14 14:49 ` Siddhesh Poyarekar
2021-06-27 20:43   ` Carlos O'Donell
2021-06-28  3:42     ` Siddhesh Poyarekar
2021-06-27 21:31 ` Carlos O'Donell
  -- strict thread matches above, loose matches on Subject: below --
2021-06-09 11:15 [PATCH 0/4] Add --disable-major-minor-libraries configure option Florian Weimer
2021-06-09 11:16 ` [PATCH 3/4] elf: Generalize name-based DSO recognition in ldconfig Florian Weimer

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=f1b7632ac80967bc23998c05f5a7c4d76c6e779c.1623312996.git.fweimer@redhat.com \
    --to=fweimer@redhat.com \
    --cc=libc-alpha@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).