@@ -102,16 +102,7 @@ elf_dynamic_do_Rel (struct link_map_private *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
@@ -190,7 +190,7 @@ elf_machine_lazy_rel (struct link_map_private *map,
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); \
@@ -354,16 +354,7 @@ elf_machine_rel (struct link_map_private *map, struct r_scope_elem *scope[],
Elf32_Addr x;
} __attribute__ ((packed, may_alias));
# 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
@@ -406,8 +406,10 @@ struct rtld_global
/* List of search directories. */
EXTERN struct r_search_path_elem *_dl_all_dirs;
+#ifdef SHARED
/* Structure describing the dynamic linker itself. */
EXTERN struct link_map_private _dl_rtld_map;
+#endif
#if !PTHREAD_IN_LIBC && defined SHARED \
&& defined __rtld_lock_default_lock_recursive
@@ -1326,6 +1328,18 @@ dl_init_static_tls (struct link_map_private *map)
void __rtld_static_init (struct link_map_private *map) attribute_hidden;
#endif
+/* Returns true if MAP is the dynamic loader itself. Statically
+ linked binaries do not have a dynamic loader, so return false. */
+static inline bool
+is_rtld_link_map (const struct link_map_private *map)
+{
+#ifdef SHARED
+ return map == &GL (dl_rtld_map);
+#else
+ return false;
+#endif
+}
+
/* Return true if the ld.so copy in this namespace is actually active
and working. If false, the dl_open/dlfcn hooks have to be used to
call into the outer dynamic linker (which happens after static
@@ -436,16 +436,6 @@ elf_machine_reloc (struct link_map_private *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_private *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_private *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_public.l_addr;
@@ -752,7 +742,7 @@ elf_machine_got_rel (struct link_map_private *map,
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. */
@@ -515,7 +515,7 @@ elf_machine_fixup_plt (struct link_map_private *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_public.l_addr;
@@ -641,7 +641,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 (sym_map)
# endif
&& !sym_map->l_relocated)
{
@@ -283,7 +283,7 @@ elf_machine_rela (struct link_map_private *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)
@@ -386,10 +386,7 @@ elf_machine_rela (struct link_map_private *map, struct r_scope_elem *scope[],
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