]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
elf: Introduce is_rtld_link_map
authorFlorian Weimer <fweimer@redhat.com>
Fri, 20 Dec 2024 14:52:57 +0000 (15:52 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Fri, 20 Dec 2024 14:52:57 +0000 (15:52 +0100)
Unconditionally define it to false for static builds.

This avoids the awkward use of weak_extern for _dl_rtld_map
in checks that cannot be possibly true on static builds.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
elf/dl-dst.h
elf/do-rel.h
elf/dynamic-link.h
elf/rtld.c
sysdeps/arm/dl-machine.h
sysdeps/generic/ldsodefs.h
sysdeps/mips/dl-machine.h
sysdeps/powerpc/powerpc64/dl-machine.h
sysdeps/sh/dl-machine.h
sysdeps/x86/dl-prop.h

index 07100e5ff962c7582baa0157a73f1602bda04fa6..bff3685b833b1b4f76e0668e05003a3ad6e51319 100644 (file)
 
 #include "trusted-dirs.h"
 
-#ifdef SHARED
-# define IS_RTLD(l) (l) == &GL(dl_rtld_map)
-#else
-# define IS_RTLD(l) 0
-#endif
 /* Guess from the number of DSTs the length of the result string.  */
 #define DL_DST_REQUIRED(l, name, len, cnt) \
   ({                                                                         \
@@ -44,7 +39,7 @@
           auditing, in ld.so.  */                                            \
        if ((l)->l_origin == NULL)                                            \
          {                                                                   \
-           assert ((l)->l_name[0] == '\0' || IS_RTLD (l));                   \
+           assert ((l)->l_name[0] == '\0' || is_rtld_link_map (l));          \
            (l)->l_origin = _dl_get_origin ();                                \
            dst_len = ((l)->l_origin && (l)->l_origin != (char *) -1          \
                          ? strlen ((l)->l_origin) : 0);                      \
index afea61cfd25093a1a20e08f7389e1a9efed48b80..f9841966d51d7fed7e23a84985bac753d5cec869 100644 (file)
@@ -102,16 +102,7 @@ elf_dynamic_do_Rel (struct link_map *map, struct r_scope_elem *scope[],
   else
 #endif
     {
-      /* This is defined in rtld.c, but nowhere in the static libc.a; make
-        the reference weak so static programs can still link.  This
-        declaration cannot be done when compiling rtld.c (i.e. #ifdef
-        RTLD_BOOTSTRAP) because rtld.c contains the common defn for
-        _dl_rtld_map, which is incompatible with a weak decl in the same
-        file.  */
-# ifndef SHARED
-      weak_extern (GL(dl_rtld_map));
-# endif
-      if (map != &GL(dl_rtld_map)) /* Already done in rtld itself.  */
+      if (!is_rtld_link_map (map)) /* Already done in rtld itself.  */
 # if !defined DO_RELA || defined ELF_MACHINE_REL_RELATIVE
        /* Rela platforms get the offset from r_addend and this must
           be copied in the relocation address.  Therefore we can skip
index 370b0e872e4a191fcbef7cb11550fffbb6aa06bb..7649ea89e533644b52848b1179f5d04f874aa20e 100644 (file)
@@ -192,7 +192,7 @@ elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[],
   do {                                                                       \
     int edr_lazy = elf_machine_runtime_setup ((map), (scope), (lazy),        \
                                              (consider_profile));            \
-    if (((map) != &GL(dl_rtld_map) || DO_RTLD_BOOTSTRAP))                    \
+    if (!is_rtld_link_map (map) || DO_RTLD_BOOTSTRAP)                        \
       ELF_DYNAMIC_DO_RELR (map);                                             \
     ELF_DYNAMIC_DO_REL ((map), (scope), edr_lazy, skip_ifunc);               \
     ELF_DYNAMIC_DO_RELA ((map), (scope), edr_lazy, skip_ifunc);                      \
index b8cc3f605f9e053c2f05739166a9867e0cd4f17a..44bcf29ff634ddf74d2655ef48393c4d9fe3c611 100644 (file)
@@ -1960,7 +1960,7 @@ dl_main (const ElfW(Phdr) *phdr,
     GL(dl_rtld_map).l_next->l_prev = GL(dl_rtld_map).l_prev;
 
   for (i = 1; i < main_map->l_searchlist.r_nlist; ++i)
-    if (main_map->l_searchlist.r_list[i] == &GL(dl_rtld_map))
+    if (is_rtld_link_map (main_map->l_searchlist.r_list[i]))
       break;
 
   /* Insert the link map for the dynamic loader into the chain in
index 9186831be3a62661bee2e5af92001d34a7ea70b0..b328287a18fb4ef786de4497c77c99a042fc6071 100644 (file)
@@ -351,16 +351,7 @@ elf_machine_rel (struct link_map *map, struct r_scope_elem *scope[],
          {
            ElfW(Addr) tmp;
 # ifndef RTLD_BOOTSTRAP
-          /* This is defined in rtld.c, but nowhere in the static
-             libc.a; make the reference weak so static programs can
-             still link.  This declaration cannot be done when
-             compiling rtld.c (i.e.  #ifdef RTLD_BOOTSTRAP) because
-             rtld.c contains the common defn for _dl_rtld_map, which
-             is incompatible with a weak decl in the same file.  */
-#  ifndef SHARED
-           weak_extern (_dl_rtld_map);
-#  endif
-           if (map == &GL(dl_rtld_map))
+           if (is_rtld_link_map (map))
              /* Undo the relocation done here during bootstrapping.
                 Now we will relocate it anew, possibly using a
                 binding found in the user program or a loaded library
index 384640b7344d2b00829748bf64590a5884a54cde..2c25c8db4643bbb83d6a8de4b16401ef5c93f8fc 100644 (file)
@@ -1323,10 +1323,17 @@ rtld_active (void)
   return GLRO(dl_init_all_dirs) != NULL;
 }
 
+/* Returns true of L is the link map of the dynamic linker itself.  */
+static inline bool
+is_rtld_link_map (const struct link_map *l)
+{
+  return l == &GL(dl_rtld_map);
+}
+
 static inline struct auditstate *
 link_map_audit_state (struct link_map *l, size_t index)
 {
-  if (l == &GL (dl_rtld_map))
+  if (is_rtld_link_map (l))
     /* The auditstate array is stored separately.  */
     return &GL (dl_rtld_auditstate) [index];
   else
@@ -1389,6 +1396,13 @@ void DL_ARCH_FIXUP_ATTRIBUTE _dl_audit_pltexit (struct link_map *l,
   attribute_hidden;
 
 #else  /* !SHARED */
+/* No special dynamic linker link map in static builds.  */
+static inline bool
+is_rtld_link_map (const struct link_map *l)
+{
+  return false;
+}
+
 static inline void
 _dl_audit_objclose (struct link_map *l)
 {
index 10e30f1e90f28f1213661cfa6756847bba5277d7..7a361edd4d4649b52e02711fa3eb5bd386e95dcb 100644 (file)
@@ -436,16 +436,6 @@ elf_machine_reloc (struct link_map *map, struct r_scope_elem *scope[],
   const unsigned long int r_type = ELFW(R_TYPE) (r_info);
   ElfW(Addr) *addr_field = (ElfW(Addr) *) reloc_addr;
 
-#if !defined RTLD_BOOTSTRAP && !defined SHARED
-  /* This is defined in rtld.c, but nowhere in the static libc.a;
-     make the reference weak so static programs can still link.  This
-     declaration cannot be done when compiling rtld.c (i.e.  #ifdef
-     RTLD_BOOTSTRAP) because rtld.c contains the common defn for
-     _dl_rtld_map, which is incompatible with a weak decl in the same
-     file.  */
-  weak_extern (GL(dl_rtld_map));
-#endif
-
   switch (r_type)
     {
 #if !defined (RTLD_BOOTSTRAP)
@@ -534,7 +524,7 @@ elf_machine_reloc (struct link_map *map, struct r_scope_elem *scope[],
                   though it's not ABI compliant.  Some day we should
                   bite the bullet and stop doing this.  */
 #ifndef RTLD_BOOTSTRAP
-               if (map != &GL(dl_rtld_map))
+               if (!is_rtld_link_map (map))
 #endif
                  reloc_value += SYMBOL_ADDRESS (map, sym, true);
              }
@@ -553,7 +543,7 @@ elf_machine_reloc (struct link_map *map, struct r_scope_elem *scope[],
          }
        else
 #ifndef RTLD_BOOTSTRAP
-         if (map != &GL(dl_rtld_map))
+         if (!is_rtld_link_map (map))
 #endif
            reloc_value += map->l_addr;
 
@@ -749,7 +739,7 @@ elf_machine_got_rel (struct link_map *map, struct r_scope_elem *scope[], int laz
 
   n = map->l_info[DT_MIPS (LOCAL_GOTNO)]->d_un.d_val;
   /* The dynamic linker's local got entries have already been relocated.  */
-  if (map != &GL(dl_rtld_map))
+  if (!is_rtld_link_map (map))
     {
       /* got[0] is reserved. got[1] is also reserved for the dynamic object
         generated by gnu ld. Skip these reserved entries from relocation.  */
index 2b6f5d2b08cb10b8d4a059abd3baff82633d9d70..5855393b2bcfa0abb696668d98faaf145d44cf1c 100644 (file)
@@ -537,7 +537,7 @@ elf_machine_fixup_plt (struct link_map *map, lookup_t sym_map,
   if (finaladdr != 0 && map != sym_map && !sym_map->l_relocated
 #if !defined RTLD_BOOTSTRAP && defined SHARED
       /* Bootstrap map doesn't have l_relocated set for it.  */
-      && sym_map != &GL(dl_rtld_map)
+      && !is_rtld_link_map (sym_map)
 #endif
       )
     offset = sym_map->l_addr;
@@ -662,7 +662,7 @@ resolve_ifunc (Elf64_Addr value,
   if (map != sym_map
 # if !defined RTLD_BOOTSTRAP && defined SHARED
       /* Bootstrap map doesn't have l_relocated set for it.  */
-      && sym_map != &GL(dl_rtld_map)
+      && !is_rtld_link_map (map)
 # endif
       && !sym_map->l_relocated)
     {
index c2c970d0c4f3e04034c1d069a66909bf049c65a5..01cd5114c4550be37aca1447383fb2adcb7f23fb 100644 (file)
@@ -284,7 +284,7 @@ elf_machine_rela (struct link_map *map, struct r_scope_elem *scope[],
   if (__glibc_unlikely (r_type == R_SH_RELATIVE))
     {
 #ifndef RTLD_BOOTSTRAP
-      if (map != &GL(dl_rtld_map)) /* Already done in rtld itself.      */
+      if (is_rtld_link_map (map)) /* Already done in rtld itself.  */
 #endif
        {
          if (reloc->r_addend)
@@ -380,16 +380,7 @@ elf_machine_rela (struct link_map *map, struct r_scope_elem *scope[],
        case R_SH_DIR32:
          {
 #if !defined RTLD_BOOTSTRAP
-          /* This is defined in rtld.c, but nowhere in the static
-             libc.a; make the reference weak so static programs can
-             still link.  This declaration cannot be done when
-             compiling rtld.c (i.e. #ifdef RTLD_BOOTSTRAP) because
-             rtld.c contains the common defn for _dl_rtld_map, which
-             is incompatible with a weak decl in the same file.  */
-# ifndef SHARED
-           weak_extern (_dl_rtld_map);
-# endif
-           if (map == &GL(dl_rtld_map))
+           if (is_rtld_link_map (map))
              /* Undo the relocation done here during bootstrapping.
                 Now we will relocate it anew, possibly using a
                 binding found in the user program or a loaded library
index 08387dfaff289e03946377bc44bd3b19be39192d..62619d7dbe27af47be0eb4ac3657d5bd394e58f5 100644 (file)
@@ -46,7 +46,7 @@ dl_isa_level_check (struct link_map *m, const char *program)
 #ifdef SHARED
       /* Skip ISA level check for ld.so since ld.so won't run if its ISA
         level is higher than CPU.  */
-      if (l == &GL(dl_rtld_map) || l->l_real == &GL(dl_rtld_map))
+      if (is_rtld_link_map (l) || is_rtld_link_map (l->l_real))
        continue;
 #endif