ld.so: Initialize bootstrap_map.l_ld_readonly [BZ #28340]
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 23 Sep 2021 16:06:49 +0000 (09:06 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Tue, 19 Oct 2021 13:40:38 +0000 (06:40 -0700)
1. Define DL_RO_DYN_SECTION to initalize bootstrap_map.l_ld_readonly
before calling elf_get_dynamic_info to get dynamic info in bootstrap_map,
2. Define a single

static inline bool
dl_relocate_ld (const struct link_map *l)
{
  /* Don't relocate dynamic section if it is readonly  */
  return !(l->l_ld_readonly || DL_RO_DYN_SECTION);
}

This updates BZ #28340 fix.

elf/rtld.c
sysdeps/generic/dl-relocate-ld.h
sysdeps/generic/ldsodefs.h
sysdeps/mips/dl-relocate-ld.h
sysdeps/riscv/dl-relocate-ld.h

index c66a1d0..b8ba2d8 100644 (file)
@@ -547,6 +547,7 @@ _dl_start (void *arg)
 
   /* Read our own dynamic section and fill in the info array.  */
   bootstrap_map.l_ld = (void *) bootstrap_map.l_addr + elf_machine_dynamic ();
+  bootstrap_map.l_ld_readonly = DL_RO_DYN_SECTION;
   elf_get_dynamic_info (&bootstrap_map, true, false);
 
 #if NO_TLS_OFFSET != 0
index 5fae206..cfb86c2 100644 (file)
 #ifndef _DL_RELOCATE_LD_H
 #define _DL_RELOCATE_LD_H
 
-/* Return true if dynamic section in the shared library L should be
-   relocated.  */
-
-static inline bool
-dl_relocate_ld (const struct link_map *l)
-{
-  /* Don't relocate dynamic section if it is readonly  */
-  return !l->l_ld_readonly;
-}
+/* The dynamic section is writable.  */
+#define DL_RO_DYN_SECTION 0
 
 #endif /* _DL_RELOCATE_LD_H */
index 9ec1511..0410f77 100644 (file)
@@ -69,6 +69,16 @@ __BEGIN_DECLS
    `ElfW(TYPE)' is used in place of `Elf32_TYPE' or `Elf64_TYPE'.  */
 #define ELFW(type)     _ElfW (ELF, __ELF_NATIVE_CLASS, type)
 
+/* Return true if dynamic section in the shared library L should be
+   relocated.  */
+
+static inline bool
+dl_relocate_ld (const struct link_map *l)
+{
+  /* Don't relocate dynamic section if it is readonly  */
+  return !(l->l_ld_readonly || DL_RO_DYN_SECTION);
+}
+
 /* All references to the value of l_info[DT_PLTGOT],
   l_info[DT_STRTAB], l_info[DT_SYMTAB], l_info[DT_RELA],
   l_info[DT_REL], l_info[DT_JMPREL], and l_info[VERSYMIDX (DT_VERSYM)]
index 0c18d9a..376ad75 100644 (file)
 #ifndef _DL_RELOCATE_LD_H
 #define _DL_RELOCATE_LD_H
 
-/* Return true if dynamic section in the shared library L should be
-   relocated.  */
-
-static inline bool
-dl_relocate_ld (const struct link_map *l)
-{
-  /* Never relocate dynamic section.  */
-  return false;
-}
+/* The dynamic section is readonly.  */
+#define DL_RO_DYN_SECTION 1
 
 #endif /* _DL_RELOCATE_LD_H */
index 1032745..2ab2b8a 100644 (file)
 #ifndef _DL_RELOCATE_LD_H
 #define _DL_RELOCATE_LD_H
 
-/* Return true if dynamic section in the shared library L should be
-   relocated.  */
-
-static inline bool
-dl_relocate_ld (const struct link_map *l)
-{
-  /* Never relocate dynamic section for ABI compatibility.  */
-  return false;
-}
+/* The dynamic section is readonly for ABI compatibility.  */
+#define DL_RO_DYN_SECTION 1
 
 #endif /* _DL_RELOCATE_LD_H */