mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-24 22:10:13 +00:00
elf: Generalize name-based DSO recognition in ldconfig
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. Reviewed-by: Carlos O'Donell <carlos@redhat.com> Tested-by: Carlos O'Donell <carlos@redhat.com>
This commit is contained in:
parent
b89d5de250
commit
6bf789d69e
@ -223,7 +223,8 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \
|
|||||||
tst-single_threaded tst-single_threaded-pthread \
|
tst-single_threaded tst-single_threaded-pthread \
|
||||||
tst-tls-ie tst-tls-ie-dlmopen argv0test \
|
tst-tls-ie tst-tls-ie-dlmopen argv0test \
|
||||||
tst-glibc-hwcaps tst-glibc-hwcaps-prepend tst-glibc-hwcaps-mask \
|
tst-glibc-hwcaps tst-glibc-hwcaps-prepend tst-glibc-hwcaps-mask \
|
||||||
tst-tls20 tst-tls21 tst-dlmopen-dlerror tst-dlmopen-gethostbyname
|
tst-tls20 tst-tls21 tst-dlmopen-dlerror tst-dlmopen-gethostbyname \
|
||||||
|
tst-dl-is_dso
|
||||||
# reldep9
|
# reldep9
|
||||||
tests-internal += loadtest unload unload2 circleload1 \
|
tests-internal += loadtest unload unload2 circleload1 \
|
||||||
neededtest neededtest2 neededtest3 neededtest4 \
|
neededtest neededtest2 neededtest3 neededtest4 \
|
||||||
|
33
elf/dl-is_dso.h
Normal file
33
elf/dl-is_dso.h
Normal file
@ -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);
|
||||||
|
}
|
@ -43,6 +43,7 @@
|
|||||||
#include <ldconfig.h>
|
#include <ldconfig.h>
|
||||||
#include <dl-cache.h>
|
#include <dl-cache.h>
|
||||||
#include <dl-hwcaps.h>
|
#include <dl-hwcaps.h>
|
||||||
|
#include <dl-is_dso.h>
|
||||||
|
|
||||||
#include <dl-procinfo.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 (if not already processing a glibc-hwcaps
|
||||||
subdirectory)? The dynamic linker is also considered as
|
subdirectory)? The dynamic linker is also considered as
|
||||||
shared library. */
|
shared library. */
|
||||||
if (((strncmp (direntry->d_name, "lib", 3) != 0
|
if (!_dl_is_dso (direntry->d_name)
|
||||||
&& strncmp (direntry->d_name, "ld-", 3) != 0)
|
|
||||||
|| strstr (direntry->d_name, ".so") == NULL)
|
|
||||||
&& (direntry->d_type == DT_REG
|
&& (direntry->d_type == DT_REG
|
||||||
|| (entry->hwcaps == NULL
|
|| (entry->hwcaps == NULL
|
||||||
&& !is_hwcap_platform (direntry->d_name))))
|
&& !is_hwcap_platform (direntry->d_name))))
|
||||||
|
35
elf/tst-dl-is_dso.c
Normal file
35
elf/tst-dl-is_dso.c
Normal file
@ -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>
|
Loading…
Reference in New Issue
Block a user