]> sourceware.org Git - glibc.git/commitdiff
elf: Introduce _dl_relocate_object_no_relro
authorFlorian Weimer <fweimer@redhat.com>
Wed, 6 Nov 2024 09:33:44 +0000 (10:33 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Wed, 6 Nov 2024 09:33:44 +0000 (10:33 +0100)
And make _dl_protect_relro apply RELRO conditionally.

Reviewed-by: DJ Delorie <dj@redhat.com>
elf/dl-reloc.c
sysdeps/generic/ldsodefs.h

index b2c1627ceb847486cb3ef90e775be127ca59a45c..76d14830ddda83b7d22fc42a5657807bb092a576 100644 (file)
@@ -202,12 +202,9 @@ resolve_map (lookup_t l, struct r_scope_elem *scope[], const ElfW(Sym) **ref,
 #include "dynamic-link.h"
 
 void
-_dl_relocate_object (struct link_map *l, struct r_scope_elem *scope[],
-                    int reloc_mode, int consider_profiling)
+_dl_relocate_object_no_relro (struct link_map *l, struct r_scope_elem *scope[],
+                             int reloc_mode, int consider_profiling)
 {
-  if (l->l_relocated)
-    return;
-
   struct textrels
   {
     caddr_t start;
@@ -338,17 +335,24 @@ _dl_relocate_object (struct link_map *l, struct r_scope_elem *scope[],
 
       textrels = textrels->next;
     }
-
-  /* In case we can protect the data now that the relocations are
-     done, do it.  */
-  if (l->l_relro_size != 0)
-    _dl_protect_relro (l);
 }
 
+void
+_dl_relocate_object (struct link_map *l, struct r_scope_elem *scope[],
+                    int reloc_mode, int consider_profiling)
+{
+  if (l->l_relocated)
+    return;
+  _dl_relocate_object_no_relro (l, scope, reloc_mode, consider_profiling);
+  _dl_protect_relro (l);
+}
 
 void
 _dl_protect_relro (struct link_map *l)
 {
+  if (l->l_relro_size == 0)
+    return;
+
   ElfW(Addr) start = ALIGN_DOWN((l->l_addr
                                 + l->l_relro_addr),
                                GLRO(dl_pagesize));
index 259ce2e7d6e8ff31da671d5a327dd114858890c8..91447a5e77c2466dcf95fbdd52819913404b1c79 100644 (file)
@@ -1014,6 +1014,13 @@ extern void _dl_relocate_object (struct link_map *map,
                                 int reloc_mode, int consider_profiling)
      attribute_hidden;
 
+/* Perform relocation, but do not apply RELRO.  Does not check
+   L->relocated.  Otherwise the same as _dl_relocate_object.  */
+void _dl_relocate_object_no_relro (struct link_map *map,
+                                  struct r_scope_elem *scope[],
+                                  int reloc_mode, int consider_profiling)
+     attribute_hidden;
+
 /* Protect PT_GNU_RELRO area.  */
 extern void _dl_protect_relro (struct link_map *map) attribute_hidden;
 
This page took 0.044376 seconds and 5 git commands to generate.