[v3,22/32] elf: Introduce GLPM accessor for the protected memory area

Message ID 9b39c743e4b9f33bd45379781355eef7a0f873e5.1701944612.git.fweimer@redhat.com
State New
Headers
Series RELRO linkmaps |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
redhat-pt-bot/TryBot-still_applies warning Patch no longer applies to master

Commit Message

Florian Weimer Dec. 7, 2023, 10:32 a.m. UTC
  The memory area is still allocated in the data segment, so this change
is preparatory only.
---
 elf/dl-load.c              |  12 ++--
 elf/rtld.c                 | 129 +++++++++++++++++++------------------
 elf/setup-vdso.h           |   4 +-
 sysdeps/generic/ldsodefs.h |  24 +++++--
 sysdeps/x86/dl-cet.c       |   4 +-
 sysdeps/x86/dl-prop.h      |   2 +-
 6 files changed, 94 insertions(+), 81 deletions(-)
  

Comments

Joseph Myers Feb. 28, 2024, 12:44 p.m. UTC | #1
On Thu, 7 Dec 2023, Florian Weimer wrote:

> The memory area is still allocated in the data segment, so this change
> is preparatory only.

OK, presuming that before commit you check for any new / moved references 
to dl_rtld_map and update them as well.  (At least dl-cet.c has moved to 
sysdeps/x86_64/ - though as per my review of the previous patch, I tend to 
think the references there should change to using is_rtld_link_map.)
  

Patch

diff --git a/elf/dl-load.c b/elf/dl-load.c
index 9e64992c36..30727afddb 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -744,7 +744,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 = &GL (dl_rtld_map);
+    l = &GLPM (dl_rtld_map);
 #endif
   assert (l->l_type != lt_loaded);
 
@@ -969,8 +969,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, &GL(dl_rtld_map).l_file_id)
-	  || _dl_name_match_p (name, &GL(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.  */
@@ -979,7 +979,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 = &GL(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_public.l_addr = l->l_real->l_public.l_addr;
@@ -1284,7 +1284,7 @@  _dl_map_object_from_fd (const char *name, const char *origname, int fd,
 	  const uintptr_t p = (uintptr_t) &__stack_prot & -GLRO(dl_pagesize);
 	  const size_t s = (uintptr_t) (&__stack_prot + 1) - p;
 
-	  struct link_map_private *const m = &GL(dl_rtld_map);
+	  struct link_map_private *const m = &GLPM(dl_rtld_map);
 	  const uintptr_t relro_end = ((m->l_public.l_addr + m->l_relro_addr
 					+ m->l_relro_size)
 				       & -GLRO(dl_pagesize));
@@ -2071,7 +2071,7 @@  _dl_map_new_object (struct link_map_private *loader, const char *name,
 	      l = (loader
 		   ?: GL(dl_ns)[LM_ID_BASE]._ns_loaded
 # ifdef SHARED
-		   ?: &GL(dl_rtld_map)
+		   ?: &GLPM(dl_rtld_map)
 # endif
 		  );
 
diff --git a/elf/rtld.c b/elf/rtld.c
index c92e99927b..733dbf46a3 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -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.  */
@@ -464,9 +465,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;
-  GL (dl_rtld_map).l_rw = &rtld_map_rw.l;
+  GLPM (dl_rtld_map).l_rw = &rtld_map_rw.l;
 #if NO_TLS_OFFSET != 0
-  GL (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.  */
@@ -477,18 +478,18 @@  _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
-  GL(dl_rtld_map).l_public.l_addr = info->l.l_public.l_addr;
-  GL(dl_rtld_map).l_public.l_ld = info->l.l_public.l_ld;
-  GL(dl_rtld_map).l_ld_readonly = info->l.l_ld_readonly;
-  memcpy (GL(dl_rtld_map).l_info, info->l.l_info,
-	  sizeof GL(dl_rtld_map).l_info);
-  GL(dl_rtld_map).l_mach = info->l.l_mach;
-  GL(dl_rtld_map).l_relocated = 1;
+  GLPM(dl_rtld_map).l_public.l_addr = info->l.l_public.l_addr;
+  GLPM(dl_rtld_map).l_public.l_ld = info->l.l_public.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 (&GL(dl_rtld_map));
-  GL(dl_rtld_map).l_real = &GL(dl_rtld_map);
-  GL(dl_rtld_map).l_map_start = (ElfW(Addr)) &__ehdr_start;
-  GL(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;
 
   /* Initialize the stack end variable.  */
   __libc_stack_end = __builtin_frame_address (0);
@@ -513,7 +514,7 @@  _dl_start_final (void *arg, struct dl_start_final_info *info)
 }
 
 #ifdef DONT_USE_BOOTSTRAP_MAP
-# define bootstrap_map GL(dl_rtld_map)
+# define bootstrap_map GLPM(dl_rtld_map)
 #else
 # define bootstrap_map info.l
 #endif
@@ -1036,8 +1037,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 (&GL (dl_rtld_map), GLRO (dl_naudit))->cookie
-    = (intptr_t) &GL (dl_rtld_map);
+  link_map_audit_state (&GLPM (dl_rtld_map), GLRO (dl_naudit))->cookie
+    = (intptr_t) &GLPM (dl_rtld_map);
 
   ++GLRO(dl_naudit);
 
@@ -1065,7 +1066,7 @@  load_audit_modules (struct link_map_private *main_map,
   if (GLRO(dl_naudit) > 0)
     {
       _dl_audit_objopen (main_map, LM_ID_BASE);
-      _dl_audit_objopen (&GL(dl_rtld_map), LM_ID_BASE);
+      _dl_audit_objopen (&GLPM(dl_rtld_map), LM_ID_BASE);
     }
 }
 
@@ -1075,7 +1076,7 @@  static void
 rtld_chain_load (struct link_map_private *main_map, char *argv0)
 {
   /* The dynamic loader run against itself.  */
-  const char *rtld_soname = l_soname (&GL(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);
@@ -1161,7 +1162,7 @@  rtld_setup_main_map (struct link_map_private *main_map)
 	_dl_rtld_libname.name = ((const char *) main_map->l_public.l_addr
 				 + ph->p_vaddr);
 	/* _dl_rtld_libname.next = NULL;	Already zero.  */
-	GL(dl_rtld_map).l_libname = &_dl_rtld_libname;
+	GLPM(dl_rtld_map).l_libname = &_dl_rtld_libname;
 
 	has_interp = true;
 	break;
@@ -1243,16 +1244,16 @@  rtld_setup_main_map (struct link_map_private *main_map)
       = (char *) main_map->l_tls_initimage + main_map->l_public.l_addr;
   if (! main_map->l_map_end)
     main_map->l_map_end = ~0;
-  if (! GL(dl_rtld_map).l_libname && GL(dl_rtld_map).l_public.l_name)
+  if (! GLPM(dl_rtld_map).l_libname && GLPM(dl_rtld_map).l_public.l_name)
     {
       /* We were invoked directly, so the program might not have a
 	 PT_INTERP.  */
-      _dl_rtld_libname.name = GL(dl_rtld_map).l_public.l_name;
+      _dl_rtld_libname.name = GLPM(dl_rtld_map).l_public.l_name;
       /* _dl_rtld_libname.next = NULL;	Already zero.  */
-      GL(dl_rtld_map).l_libname =  &_dl_rtld_libname;
+      GLPM(dl_rtld_map).l_libname =  &_dl_rtld_libname;
     }
   else
-    assert (GL(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;
 }
@@ -1369,7 +1370,7 @@  dl_main (const ElfW(Phdr) *phdr,
       char **orig_argv = _dl_argv;
 
       /* Note the place where the dynamic linker actually came from.  */
-      GL(dl_rtld_map).l_public.l_name = rtld_progname;
+      GLPM(dl_rtld_map).l_public.l_name = rtld_progname;
 
       while (_dl_argc > 1)
 	if (! strcmp (_dl_argv[1], "--list"))
@@ -1645,22 +1646,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 (&GL(dl_rtld_map));
+    const char *soname = l_soname (&GLPM(dl_rtld_map));
     if (soname != NULL
-	&& strcmp (GL(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 (GL(dl_rtld_map).l_libname->next == NULL);
-	GL(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 (GL(dl_rtld_map).l_relocated);
+  assert (GLPM(dl_rtld_map).l_relocated);
 
   if (! rtld_is_main)
     {
@@ -1690,7 +1691,7 @@  dl_main (const ElfW(Phdr) *phdr,
       _exit (has_interp ? 0 : 2);
     }
 
-  struct link_map **first_preload = &GL(dl_rtld_map).l_public.l_next;
+  struct link_map **first_preload = &GLPM(dl_rtld_map).l_public.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);
@@ -1703,20 +1704,20 @@  dl_main (const ElfW(Phdr) *phdr,
   call_init_paths (&state);
 
   /* Initialize _r_debug_extended.  */
-  struct r_debug *r = _dl_debug_initialize (GL(dl_rtld_map).l_public.l_addr,
+  struct r_debug *r = _dl_debug_initialize (GLPM(dl_rtld_map).l_public.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 (! GL(dl_rtld_map).l_public.l_name)
+  if (! GLPM(dl_rtld_map).l_public.l_name)
     /* If not invoked directly, the dynamic linker shared object file was
        found by the PT_INTERP name.  */
-    GL(dl_rtld_map).l_public.l_name = (char *) GL(dl_rtld_map).l_libname->name;
-  GL(dl_rtld_map).l_type = lt_library;
-  main_map->l_public.l_next = &GL(dl_rtld_map).l_public;
-  GL(dl_rtld_map).l_public.l_prev = &main_map->l_public;
+    GLPM(dl_rtld_map).l_public.l_name = (char *) GLPM(dl_rtld_map).l_libname->name;
+  GLPM(dl_rtld_map).l_type = lt_library;
+  main_map->l_public.l_next = &GLPM(dl_rtld_map).l_public;
+  GLPM(dl_rtld_map).l_public.l_prev = &main_map->l_public;
   ++GL(dl_ns)[LM_ID_BASE]._ns_nloaded;
   ++GL(dl_load_adds);
 
@@ -1734,8 +1735,8 @@  dl_main (const ElfW(Phdr) *phdr,
 
   const ElfW(Phdr) *rtld_phdr = (const void *) rtld_ehdr + rtld_ehdr->e_phoff;
 
-  GL(dl_rtld_map).l_phdr = rtld_phdr;
-  GL(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.  */
@@ -1743,15 +1744,15 @@  dl_main (const ElfW(Phdr) *phdr,
   while (cnt-- > 0)
     if (rtld_phdr[cnt].p_type == PT_GNU_RELRO)
       {
-	GL(dl_rtld_map).l_relro_addr = rtld_phdr[cnt].p_vaddr;
-	GL(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 (GL(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 (&GL(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);
@@ -1945,12 +1946,12 @@  dl_main (const ElfW(Phdr) *phdr,
     main_map->l_searchlist.r_list[--i]->l_global = 1;
 
   /* Remove _dl_rtld_map from the chain.  */
-  GL(dl_rtld_map).l_public.l_prev->l_next = GL(dl_rtld_map).l_public.l_next;
-  if (GL(dl_rtld_map).l_public.l_next != NULL)
-    GL(dl_rtld_map).l_public.l_next->l_prev = GL(dl_rtld_map).l_public.l_prev;
+  GLPM(dl_rtld_map).l_public.l_prev->l_next = GLPM(dl_rtld_map).l_public.l_next;
+  if (GLPM(dl_rtld_map).l_public.l_next != NULL)
+    GLPM(dl_rtld_map).l_public.l_next->l_prev = GLPM(dl_rtld_map).l_public.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 (main_map->l_searchlist.r_list[i] == &GLPM(dl_rtld_map))
       break;
 
   bool rtld_multiple_ref = false;
@@ -1962,21 +1963,21 @@  dl_main (const ElfW(Phdr) *phdr,
 	 its symbol search order.  */
       rtld_multiple_ref = true;
 
-      GL(dl_rtld_map).l_public.l_prev
+      GLPM(dl_rtld_map).l_public.l_prev
 	= &main_map->l_searchlist.r_list[i - 1]->l_public;
       if (__glibc_likely (state.mode == rtld_mode_normal))
 	{
-	  GL(dl_rtld_map).l_public.l_next
+	  GLPM(dl_rtld_map).l_public.l_next
 	    = (i + 1 < main_map->l_searchlist.r_nlist
 	       ? &main_map->l_searchlist.r_list[i + 1]->l_public
 	       : NULL);
 #ifdef NEED_DL_SYSINFO_DSO
 	  if (GLRO(dl_sysinfo_map) != NULL
-	      && (GL(dl_rtld_map).l_public.l_prev->l_next
+	      && (GLPM(dl_rtld_map).l_public.l_prev->l_next
 		  == &GLRO(dl_sysinfo_map)->l_public)
-	      && (GL(dl_rtld_map).l_public.l_next
+	      && (GLPM(dl_rtld_map).l_public.l_next
 		  != &GLRO(dl_sysinfo_map)->l_public))
-	    GL(dl_rtld_map).l_public.l_prev = &GLRO(dl_sysinfo_map)->l_public;
+	    GLPM(dl_rtld_map).l_public.l_prev = &GLRO(dl_sysinfo_map)->l_public;
 #endif
 	}
       else
@@ -1985,17 +1986,17 @@  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.  */
-	GL(dl_rtld_map).l_public.l_next
-	  = GL(dl_rtld_map).l_public.l_prev->l_next;
+	GLPM(dl_rtld_map).l_public.l_next
+	  = GLPM(dl_rtld_map).l_public.l_prev->l_next;
 
-      assert (GL(dl_rtld_map).l_public.l_prev->l_next
-	      == GL(dl_rtld_map).l_public.l_next);
-      GL(dl_rtld_map).l_public.l_prev->l_next = &GL(dl_rtld_map).l_public;
-      if (GL(dl_rtld_map).l_public.l_next != NULL)
+      assert (GLPM(dl_rtld_map).l_public.l_prev->l_next
+	      == GLPM(dl_rtld_map).l_public.l_next);
+      GLPM(dl_rtld_map).l_public.l_prev->l_next = &GLPM(dl_rtld_map).l_public;
+      if (GLPM(dl_rtld_map).l_public.l_next != NULL)
 	{
-	  assert (GL(dl_rtld_map).l_public.l_next->l_prev
-		  == GL(dl_rtld_map).l_public.l_prev);
-	  GL(dl_rtld_map).l_public.l_next->l_prev = &GL(dl_rtld_map).l_public;
+	  assert (GLPM(dl_rtld_map).l_public.l_next->l_prev
+		  == GLPM(dl_rtld_map).l_public.l_prev);
+	  GLPM(dl_rtld_map).l_public.l_next->l_prev = &GLPM(dl_rtld_map).l_public;
 	}
     }
 
@@ -2138,7 +2139,7 @@  dl_main (const ElfW(Phdr) *phdr,
 	      while (i-- > 0)
 		{
 		  struct link_map_private *l = main_map->l_initfini[i];
-		  if (l != &GL(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,
@@ -2288,7 +2289,7 @@  dl_main (const ElfW(Phdr) *phdr,
 	/* Also allocated with the fake malloc().  */
 	l->l_free_initfini = 0;
 
-	if (l != &GL(dl_rtld_map))
+	if (l != &GLPM(dl_rtld_map))
 	  _dl_relocate_object (l, l->l_scope, GLRO(dl_lazy) ? RTLD_LAZY : 0,
 			       consider_profiling);
 
@@ -2349,8 +2350,8 @@  dl_main (const ElfW(Phdr) *phdr,
       rtld_timer_start (&start);
 
       /* Mark the link map as not yet relocated again.  */
-      GL(dl_rtld_map).l_relocated = 0;
-      _dl_relocate_object (&GL(dl_rtld_map), main_map->l_scope, 0, 0);
+      GLPM(dl_rtld_map).l_relocated = 0;
+      _dl_relocate_object (&GLPM(dl_rtld_map), main_map->l_scope, 0, 0);
 
       rtld_timer_accum (&relocate_time, start);
     }
diff --git a/elf/setup-vdso.h b/elf/setup-vdso.h
index 8aaa44ca26..2934ed187a 100644
--- a/elf/setup-vdso.h
+++ b/elf/setup-vdso.h
@@ -93,8 +93,8 @@  setup_vdso (struct link_map_private *main_map __attribute__ ((unused)),
       /* Rearrange the list so this DSO appears after rtld_map.  */
       assert (l->l_public.l_next == NULL);
       assert (l->l_public.l_prev == &main_map->l_public);
-      GL(dl_rtld_map).l_public.l_next = &l->l_public;
-      l->l_public.l_prev = &GL(dl_rtld_map).l_public;
+      GLPM(dl_rtld_map).l_public.l_next = &l->l_public;
+      l->l_public.l_prev = &GLPM(dl_rtld_map).l_public;
       *first_preload = &l->l_public.l_next;
 # else
       GL(dl_nns) = 1;
diff --git a/sysdeps/generic/ldsodefs.h b/sysdeps/generic/ldsodefs.h
index c5d49cae62..0015fcf993 100644
--- a/sysdeps/generic/ldsodefs.h
+++ b/sysdeps/generic/ldsodefs.h
@@ -406,11 +406,6 @@  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
   EXTERN void (*_dl_rtld_lock_recursive) (void *);
@@ -528,6 +523,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.  */
+  EXTERN struct link_map_private _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
@@ -1334,7 +1346,7 @@  static inline bool
 is_rtld_link_map (const struct link_map_private *map)
 {
 #ifdef SHARED
-  return map == &GL (dl_rtld_map);
+  return map == &GLPM (dl_rtld_map);
 #else
   return false;
 #endif
diff --git a/sysdeps/x86/dl-cet.c b/sysdeps/x86/dl-cet.c
index 60ea1cb558..c47b2c8f4e 100644
--- a/sysdeps/x86/dl-cet.c
+++ b/sysdeps/x86/dl-cet.c
@@ -107,8 +107,8 @@  dl_cet_check (struct link_map *m, const char *program)
 	      /* Skip CET check for ld.so since ld.so is CET-enabled.
 		 CET will be disabled later if CET isn't enabled in
 		 executable.  */
-	      if (l == &GL(dl_rtld_map)
-		  ||  l->l_real == &GL(dl_rtld_map)
+	      if (l == &GLPM(dl_rtld_map)
+		  ||  l->l_real == &GLPM(dl_rtld_map)
 		  || (program && l == m))
 		continue;
 #endif
diff --git a/sysdeps/x86/dl-prop.h b/sysdeps/x86/dl-prop.h
index f24fc1b028..64710b76cc 100644
--- a/sysdeps/x86/dl-prop.h
+++ b/sysdeps/x86/dl-prop.h
@@ -46,7 +46,7 @@  dl_isa_level_check (struct link_map_private *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 (l == &GLPM(dl_rtld_map) || l->l_real == &GLPM(dl_rtld_map))
 	continue;
 #endif