@@ -733,7 +733,7 @@ _dl_init_paths (const char *llp, const char *source,
l = GL(dl_ns)[LM_ID_BASE]._ns_loaded;
#ifdef SHARED
if (l == NULL)
- l = &_dl_rtld_map;
+ l = &GLPM(dl_rtld_map);
#endif
assert (l->l_type != lt_loaded);
@@ -988,8 +988,8 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
/* When loading into a namespace other than the base one we must
avoid loading ld.so since there can only be one copy. Ever. */
if (__glibc_unlikely (nsid != LM_ID_BASE)
- && (_dl_file_id_match_p (&id, &_dl_rtld_map.l_file_id)
- || _dl_name_match_p (name, &_dl_rtld_map)))
+ && (_dl_file_id_match_p (&id, &GLPM(dl_rtld_map).l_file_id)
+ || _dl_name_match_p (name, &GLPM(dl_rtld_map))))
{
/* This is indeed ld.so. Create a new link_map which refers to
the real one for almost everything. */
@@ -998,7 +998,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
goto fail_new;
/* Refer to the real descriptor. */
- l->l_real = &_dl_rtld_map;
+ l->l_real = &GLPM(dl_rtld_map);
/* Copy l_addr and l_ld to avoid a GDB warning with dlmopen(). */
l->l_addr = l->l_real->l_addr;
@@ -2034,7 +2034,7 @@ _dl_map_new_object (struct link_map *loader, const char *name,
l = (loader
?: GL(dl_ns)[LM_ID_BASE]._ns_loaded
# ifdef SHARED
- ?: &_dl_rtld_map
+ ?: &GLPM(dl_rtld_map)
# endif
);
@@ -345,6 +345,7 @@ struct rtld_global _rtld_global =
extern struct rtld_global _rtld_local
__attribute__ ((alias ("_rtld_global"), visibility ("hidden")));
+struct rtld_protmem _rtld_protmem;
/* This variable is similar to _rtld_local, but all values are
read-only after relocation. */
@@ -466,9 +467,9 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
struct link_map_rw l;
struct auditstate _dl_rtld_auditstate[DL_NNS];
} rtld_map_rw;
- _dl_rtld_map.l_rw = &rtld_map_rw.l;
+ GLPM(dl_rtld_map).l_rw = &rtld_map_rw.l;
#if NO_TLS_OFFSET != 0
- _dl_rtld_map.l_rw->l_tls_offset = NO_TLS_OFFSET;
+ GLPM(dl_rtld_map).l_rw->l_tls_offset = NO_TLS_OFFSET;
#endif
/* If it hasn't happen yet record the startup time. */
@@ -479,21 +480,22 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
/* Transfer data about ourselves to the permanent link_map structure. */
#ifndef DONT_USE_BOOTSTRAP_MAP
- _dl_rtld_map.l_addr = info->l.l_addr;
- _dl_rtld_map.l_ld = info->l.l_ld;
- _dl_rtld_map.l_ld_readonly = info->l.l_ld_readonly;
- memcpy (_dl_rtld_map.l_info, info->l.l_info, sizeof _dl_rtld_map.l_info);
- _dl_rtld_map.l_mach = info->l.l_mach;
- _dl_rtld_map.l_relocated = 1;
+ GLPM(dl_rtld_map).l_addr = info->l.l_addr;
+ GLPM(dl_rtld_map).l_ld = info->l.l_ld;
+ GLPM(dl_rtld_map).l_ld_readonly = info->l.l_ld_readonly;
+ memcpy (GLPM(dl_rtld_map).l_info, info->l.l_info,
+ sizeof GLPM(dl_rtld_map).l_info);
+ GLPM(dl_rtld_map).l_mach = info->l.l_mach;
+ GLPM(dl_rtld_map).l_relocated = 1;
#endif
- _dl_setup_hash (&_dl_rtld_map);
- _dl_rtld_map.l_real = &_dl_rtld_map;
- _dl_rtld_map.l_map_start = (ElfW(Addr)) &__ehdr_start;
- _dl_rtld_map.l_map_end = (ElfW(Addr)) _end;
+ _dl_setup_hash (&GLPM(dl_rtld_map));
+ GLPM(dl_rtld_map).l_real = &GLPM(dl_rtld_map);
+ GLPM(dl_rtld_map).l_map_start = (ElfW(Addr)) &__ehdr_start;
+ GLPM(dl_rtld_map).l_map_end = (ElfW(Addr)) _end;
/* Copy the TLS related data if necessary. */
#ifndef DONT_USE_BOOTSTRAP_MAP
# if NO_TLS_OFFSET != 0
- _dl_rtld_map.l_rw->l_tls_offset = NO_TLS_OFFSET;
+ GLPM(dl_rtld_map).l_rw->l_tls_offset = NO_TLS_OFFSET;
# endif
#endif
@@ -520,7 +522,7 @@ _dl_start_final (void *arg, struct dl_start_final_info *info)
}
#ifdef DONT_USE_BOOTSTRAP_MAP
-# define bootstrap_map _dl_rtld_map
+# define bootstrap_map GLPM(dl_rtld_map)
#else
# define bootstrap_map info.l
#endif
@@ -1024,8 +1026,8 @@ ERROR: audit interface '%s' requires version %d (maximum supported version %d);
/* The dynamic linker link map is statically allocated, so the
cookie in _dl_new_object has not happened. */
- link_map_audit_state (&_dl_rtld_map, GLRO (dl_naudit))->cookie
- = (intptr_t) &_dl_rtld_map;
+ link_map_audit_state (&GLPM(dl_rtld_map), GLRO (dl_naudit))->cookie
+ = (intptr_t) &GLPM(dl_rtld_map);
++GLRO(dl_naudit);
@@ -1052,7 +1054,7 @@ load_audit_modules (struct link_map *main_map, struct audit_list *audit_list)
if (GLRO(dl_naudit) > 0)
{
_dl_audit_objopen (main_map, LM_ID_BASE);
- _dl_audit_objopen (&_dl_rtld_map, LM_ID_BASE);
+ _dl_audit_objopen (&GLPM(dl_rtld_map), LM_ID_BASE);
}
}
@@ -1062,7 +1064,7 @@ static void
rtld_chain_load (struct link_map *main_map, char *argv0)
{
/* The dynamic loader run against itself. */
- const char *rtld_soname = l_soname (&_dl_rtld_map);
+ const char *rtld_soname = l_soname (&GLPM(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);
@@ -1149,7 +1151,7 @@ rtld_setup_main_map (struct link_map *main_map)
_dl_rtld_libname.name = ((const char *) main_map->l_addr
+ ph->p_vaddr);
/* _dl_rtld_libname.next = NULL; Already zero. */
- _dl_rtld_map.l_libname = &_dl_rtld_libname;
+ GLPM(dl_rtld_map).l_libname = &_dl_rtld_libname;
has_interp = true;
break;
@@ -1231,16 +1233,16 @@ rtld_setup_main_map (struct link_map *main_map)
= (char *) main_map->l_tls_initimage + main_map->l_addr;
if (! main_map->l_map_end)
main_map->l_map_end = ~0;
- if (! _dl_rtld_map.l_libname && _dl_rtld_map.l_name)
+ if (! GLPM(dl_rtld_map).l_libname && GLPM(dl_rtld_map).l_name)
{
/* We were invoked directly, so the program might not have a
PT_INTERP. */
- _dl_rtld_libname.name = _dl_rtld_map.l_name;
+ _dl_rtld_libname.name = GLPM(dl_rtld_map).l_name;
/* _dl_rtld_libname.next = NULL; Already zero. */
- _dl_rtld_map.l_libname = &_dl_rtld_libname;
+ GLPM(dl_rtld_map).l_libname = &_dl_rtld_libname;
}
else
- assert (_dl_rtld_map.l_libname); /* How else did we get here? */
+ assert (GLPM(dl_rtld_map).l_libname); /* How else did we get here? */
return has_interp;
}
@@ -1352,7 +1354,7 @@ dl_main (const ElfW(Phdr) *phdr,
char **orig_argv = _dl_argv;
/* Note the place where the dynamic linker actually came from. */
- _dl_rtld_map.l_name = rtld_progname;
+ GLPM(dl_rtld_map).l_name = rtld_progname;
while (_dl_argc > 1)
if (! strcmp (_dl_argv[1], "--list"))
@@ -1636,22 +1638,22 @@ dl_main (const ElfW(Phdr) *phdr,
/* If the current libname is different from the SONAME, add the
latter as well. */
{
- const char *soname = l_soname (&_dl_rtld_map);
+ const char *soname = l_soname (&GLPM(dl_rtld_map));
if (soname != NULL
- && strcmp (_dl_rtld_map.l_libname->name, soname) != 0)
+ && strcmp (GLPM(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;
+ assert (GLPM(dl_rtld_map).l_libname->next == NULL);
+ GLPM(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);
+ assert (GLPM(dl_rtld_map).l_relocated);
if (! rtld_is_main)
{
@@ -1681,7 +1683,7 @@ dl_main (const ElfW(Phdr) *phdr,
_exit (has_interp ? 0 : 2);
}
- struct link_map **first_preload = &_dl_rtld_map.l_next;
+ struct link_map **first_preload = &GLPM(dl_rtld_map).l_next;
/* Set up the data structures for the system-supplied DSO early,
so they can influence _dl_init_paths. */
setup_vdso (main_map, &first_preload);
@@ -1694,20 +1696,20 @@ dl_main (const ElfW(Phdr) *phdr,
call_init_paths (&state);
/* Initialize _r_debug_extended. */
- struct r_debug *r = _dl_debug_initialize (_dl_rtld_map.l_addr,
+ struct r_debug *r = _dl_debug_initialize (GLPM(dl_rtld_map).l_addr,
LM_ID_BASE);
r->r_state = RT_CONSISTENT;
/* Put the link_map for ourselves on the chain so it can be found by
name. Note that at this point the global chain of link maps contains
exactly one element, which is pointed to by dl_loaded. */
- if (! _dl_rtld_map.l_name)
+ if (! GLPM(dl_rtld_map).l_name)
/* If not invoked directly, the dynamic linker shared object file was
found by the PT_INTERP name. */
- _dl_rtld_map.l_name = (char *) _dl_rtld_map.l_libname->name;
- _dl_rtld_map.l_type = lt_library;
- main_map->l_next = &_dl_rtld_map;
- _dl_rtld_map.l_prev = main_map;
+ GLPM(dl_rtld_map).l_name = (char *) GLPM(dl_rtld_map).l_libname->name;
+ GLPM(dl_rtld_map).l_type = lt_library;
+ main_map->l_next = &GLPM(dl_rtld_map);
+ GLPM(dl_rtld_map).l_prev = main_map;
++GL(dl_ns)[LM_ID_BASE]._ns_nloaded;
++GL(dl_load_adds);
@@ -1725,8 +1727,8 @@ dl_main (const ElfW(Phdr) *phdr,
const ElfW(Phdr) *rtld_phdr = (const void *) rtld_ehdr + rtld_ehdr->e_phoff;
- _dl_rtld_map.l_phdr = rtld_phdr;
- _dl_rtld_map.l_phnum = rtld_ehdr->e_phnum;
+ GLPM(dl_rtld_map).l_phdr = rtld_phdr;
+ GLPM(dl_rtld_map).l_phnum = rtld_ehdr->e_phnum;
/* PT_GNU_RELRO is usually the last phdr. */
@@ -1734,15 +1736,15 @@ dl_main (const ElfW(Phdr) *phdr,
while (cnt-- > 0)
if (rtld_phdr[cnt].p_type == PT_GNU_RELRO)
{
- _dl_rtld_map.l_relro_addr = rtld_phdr[cnt].p_vaddr;
- _dl_rtld_map.l_relro_size = rtld_phdr[cnt].p_memsz;
+ GLPM(dl_rtld_map).l_relro_addr = rtld_phdr[cnt].p_vaddr;
+ GLPM(dl_rtld_map).l_relro_size = rtld_phdr[cnt].p_memsz;
break;
}
/* Add the dynamic linker to the TLS list if it also uses TLS. */
- if (_dl_rtld_map.l_tls_blocksize != 0)
+ if (GLPM(dl_rtld_map).l_tls_blocksize != 0)
/* Assign a module ID. Do this before loading any audit modules. */
- _dl_assign_tls_modid (&_dl_rtld_map);
+ _dl_assign_tls_modid (&GLPM(dl_rtld_map));
audit_list_add_dynamic_tag (&state.audit_list, main_map, DT_AUDIT);
audit_list_add_dynamic_tag (&state.audit_list, main_map, DT_DEPAUDIT);
@@ -1935,30 +1937,30 @@ dl_main (const ElfW(Phdr) *phdr,
for (i = main_map->l_searchlist.r_nlist; i > 0; )
main_map->l_searchlist.r_list[--i]->l_global = 1;
- /* Remove _dl_rtld_map from the chain. */
- _dl_rtld_map.l_prev->l_next = _dl_rtld_map.l_next;
- if (_dl_rtld_map.l_next != NULL)
- _dl_rtld_map.l_next->l_prev = _dl_rtld_map.l_prev;
+ /* Remove GLPM(dl_rtld_map) from the chain. */
+ GLPM(dl_rtld_map).l_prev->l_next = GLPM(dl_rtld_map).l_next;
+ if (GLPM(dl_rtld_map).l_next != NULL)
+ GLPM(dl_rtld_map).l_next->l_prev = GLPM(dl_rtld_map).l_prev;
for (i = 1; i < main_map->l_searchlist.r_nlist; ++i)
- if (is_rtld_link_map (main_map->l_searchlist.r_list[i]))
+ if (main_map->l_searchlist.r_list[i] == &GLPM(dl_rtld_map))
break;
/* Insert the link map for the dynamic loader into the chain in
symbol search order because gdb uses the chain's order as its
symbol search order. */
- _dl_rtld_map.l_prev = main_map->l_searchlist.r_list[i - 1];
+ GLPM(dl_rtld_map).l_prev = main_map->l_searchlist.r_list[i - 1];
if (__glibc_likely (state.mode == rtld_mode_normal))
{
- _dl_rtld_map.l_next = (i + 1 < main_map->l_searchlist.r_nlist
- ? main_map->l_searchlist.r_list[i + 1]
- : NULL);
+ GLPM(dl_rtld_map).l_next = (i + 1 < main_map->l_searchlist.r_nlist
+ ? main_map->l_searchlist.r_list[i + 1]
+ : NULL);
#ifdef NEED_DL_SYSINFO_DSO
if (GLRO(dl_sysinfo_map) != NULL
- && _dl_rtld_map.l_prev->l_next == GLRO(dl_sysinfo_map)
- && _dl_rtld_map.l_next != GLRO(dl_sysinfo_map))
- _dl_rtld_map.l_prev = GLRO(dl_sysinfo_map);
+ && (GLPM(dl_rtld_map).l_prev->l_next == GLRO(dl_sysinfo_map))
+ && (GLPM(dl_rtld_map).l_next != GLRO(dl_sysinfo_map)))
+ GLPM(dl_rtld_map).l_prev = GLRO(dl_sysinfo_map);
#endif
}
else
@@ -1967,14 +1969,14 @@ dl_main (const ElfW(Phdr) *phdr,
In this case it doesn't matter much where we put the
interpreter object, so we just initialize the list pointer so
that the assertion below holds. */
- _dl_rtld_map.l_next = _dl_rtld_map.l_prev->l_next;
+ GLPM(dl_rtld_map).l_next = GLPM(dl_rtld_map).l_prev->l_next;
- assert (_dl_rtld_map.l_prev->l_next == _dl_rtld_map.l_next);
- _dl_rtld_map.l_prev->l_next = &_dl_rtld_map;
- if (_dl_rtld_map.l_next != NULL)
+ assert (GLPM(dl_rtld_map).l_prev->l_next == GLPM(dl_rtld_map).l_next);
+ GLPM(dl_rtld_map).l_prev->l_next = &GLPM(dl_rtld_map);
+ if (GLPM(dl_rtld_map).l_next != NULL)
{
- assert (_dl_rtld_map.l_next->l_prev == _dl_rtld_map.l_prev);
- _dl_rtld_map.l_next->l_prev = &_dl_rtld_map;
+ assert (GLPM(dl_rtld_map).l_next->l_prev == GLPM(dl_rtld_map).l_prev);
+ GLPM(dl_rtld_map).l_next->l_prev = &GLPM(dl_rtld_map);
}
/* Now let us see whether all libraries are available in the
@@ -2116,7 +2118,7 @@ dl_main (const ElfW(Phdr) *phdr,
while (i-- > 0)
{
struct link_map *l = main_map->l_initfini[i];
- if (l != &_dl_rtld_map && ! l->l_faked)
+ if (l != &GLPM(dl_rtld_map) && ! l->l_faked)
{
args.l = l;
_dl_receive_error (print_unresolved, relocate_doit,
@@ -2315,7 +2317,8 @@ dl_main (const ElfW(Phdr) *phdr,
{
RTLD_TIMING_VAR (start);
rtld_timer_start (&start);
- _dl_relocate_object_no_relro (&_dl_rtld_map, main_map->l_scope, 0, 0);
+ _dl_relocate_object_no_relro (&GLPM(dl_rtld_map), main_map->l_scope,
+ 0, 0);
rtld_timer_accum (&relocate_time, start);
__rtld_mutex_init ();
@@ -2323,7 +2326,7 @@ dl_main (const ElfW(Phdr) *phdr,
}
/* All ld.so initialization is complete. Apply RELRO. */
- _dl_protect_relro (&_dl_rtld_map);
+ _dl_protect_relro (&GLPM(dl_rtld_map));
/* Relocation is complete. Perform early libc initialization. This
is the initial libc, even if audit modules have been loaded with
@@ -92,8 +92,8 @@ setup_vdso (struct link_map *main_map __attribute__ ((unused)),
/* Rearrange the list so this DSO appears after rtld_map. */
assert (l->l_next == NULL);
assert (l->l_prev == main_map);
- _dl_rtld_map.l_next = l;
- l->l_prev = &_dl_rtld_map;
+ GLPM(dl_rtld_map).l_next = l;
+ l->l_prev = &GLPM(dl_rtld_map);
*first_preload = &l->l_next;
# else
GL(dl_nns) = 1;
@@ -508,6 +508,23 @@ extern struct rtld_global _rtld_global __rtld_global_attribute__;
# undef __rtld_global_attribute__
#endif
+#ifdef SHARED
+/* Implementation structure for the protected memory area. */
+struct rtld_protmem
+{
+ /* Structure describing the dynamic linker itself. */
+ struct link_map _dl_rtld_map;
+};
+extern struct rtld_protmem _rtld_protmem attribute_hidden;
+#endif /* SHARED */
+
+/* GLPM(FIELD) denotes the FIELD in the protected memory area. */
+#ifdef SHARED
+# define GLPM(name) _rtld_protmem._##name
+#else
+# define GLPM(name) _##name
+#endif
+
#ifndef SHARED
# define GLRO(name) _##name
#else
@@ -1325,9 +1342,6 @@ rtld_active (void)
return GLRO(dl_init_all_dirs) != NULL;
}
-/* Pre-allocated link map for the dynamic linker itself. */
-extern struct link_map _dl_rtld_map attribute_hidden;
-
/* Used to store the audit information for the link map of the
dynamic loader. */
extern struct auditstate _dl_rtld_auditstate[DL_NNS] attribute_hidden;
@@ -1336,7 +1350,7 @@ extern struct auditstate _dl_rtld_auditstate[DL_NNS] attribute_hidden;
static inline bool
is_rtld_link_map (const struct link_map *l)
{
- return l == &_dl_rtld_map;
+ return l == &GLPM(dl_rtld_map);
}
static inline struct auditstate *