aboutsummaryrefslogtreecommitdiff
path: root/elf/rtld.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2025-02-02 20:10:09 +0100
committerFlorian Weimer <fweimer@redhat.com>2025-02-02 20:10:09 +0100
commit749310c61b66aa2af0422db25686440b64a14800 (patch)
tree4e03db64b2ef074947e9e5b9556739f99567145a /elf/rtld.c
parentaa1bf8903992cc0d26cacb9e5930a9fed8f50548 (diff)
downloadglibc-749310c61b66aa2af0422db25686440b64a14800.tar.xz
glibc-749310c61b66aa2af0422db25686440b64a14800.zip
elf: Add l_soname accessor function for DT_SONAME values
It's not necessary to introduce temporaries because the compiler is able to evaluate l_soname just once in constracts like: l_soname (l) != NULL && strcmp (l_soname (l), LIBC_SO) != 0
Diffstat (limited to 'elf/rtld.c')
-rw-r--r--elf/rtld.c44
1 files changed, 19 insertions, 25 deletions
diff --git a/elf/rtld.c b/elf/rtld.c
index 00bec15316..115f1da37f 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -1055,13 +1055,9 @@ static void
rtld_chain_load (struct link_map *main_map, char *argv0)
{
/* The dynamic loader run against itself. */
- const char *rtld_soname
- = ((const char *) D_PTR (&_dl_rtld_map, l_info[DT_STRTAB])
- + _dl_rtld_map.l_info[DT_SONAME]->d_un.d_val);
- if (main_map->l_info[DT_SONAME] != NULL
- && strcmp (rtld_soname,
- ((const char *) D_PTR (main_map, l_info[DT_STRTAB])
- + main_map->l_info[DT_SONAME]->d_un.d_val)) == 0)
+ const char *rtld_soname = l_soname (&_dl_rtld_map);
+ if (l_soname (main_map) != NULL
+ && strcmp (rtld_soname, l_soname (main_map)) == 0)
_dl_fatal_printf ("%s: loader cannot load itself\n", rtld_soname);
/* With DT_NEEDED dependencies, the executable is dynamically
@@ -1632,20 +1628,20 @@ dl_main (const ElfW(Phdr) *phdr,
/* If the current libname is different from the SONAME, add the
latter as well. */
- if (_dl_rtld_map.l_info[DT_SONAME] != NULL
- && strcmp (_dl_rtld_map.l_libname->name,
- (const char *) D_PTR (&_dl_rtld_map, l_info[DT_STRTAB])
- + _dl_rtld_map.l_info[DT_SONAME]->d_un.d_val) != 0)
- {
- static struct libname_list newname;
- newname.name = ((char *) D_PTR (&_dl_rtld_map, l_info[DT_STRTAB])
- + _dl_rtld_map.l_info[DT_SONAME]->d_un.d_ptr);
- newname.next = NULL;
- newname.dont_free = 1;
-
- assert (_dl_rtld_map.l_libname->next == NULL);
- _dl_rtld_map.l_libname->next = &newname;
- }
+ {
+ const char *soname = l_soname (&_dl_rtld_map);
+ if (soname != NULL
+ && strcmp (_dl_rtld_map.l_libname->name, soname) != 0)
+ {
+ static struct libname_list newname;
+ newname.name = soname;
+ newname.next = NULL;
+ newname.dont_free = 1;
+
+ assert (_dl_rtld_map.l_libname->next == NULL);
+ _dl_rtld_map.l_libname->next = &newname;
+ }
+ }
/* The ld.so must be relocated since otherwise loading audit modules
will fail since they reuse the very same ld.so. */
assert (_dl_rtld_map.l_relocated);
@@ -1658,10 +1654,8 @@ dl_main (const ElfW(Phdr) *phdr,
/* If the main map is libc.so, update the base namespace to
refer to this map. If libc.so is loaded later, this happens
in _dl_map_object_from_fd. */
- if (main_map->l_info[DT_SONAME] != NULL
- && (strcmp (((const char *) D_PTR (main_map, l_info[DT_STRTAB])
- + main_map->l_info[DT_SONAME]->d_un.d_val), LIBC_SO)
- == 0))
+ if (l_soname (main_map) != NULL
+ && strcmp (l_soname (main_map), LIBC_SO) == 0)
GL(dl_ns)[LM_ID_BASE].libc_map = main_map;
/* Set up our cache of pointers into the hash table. */