aboutsummaryrefslogtreecommitdiff
path: root/elf/get-dynamic-info.h
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2022-01-04 05:47:21 -0800
committerH.J. Lu <hjl.tools@gmail.com>2022-04-26 10:16:11 -0700
commit60196d2ef2850f222c7c93818ccb4d9cdbd77276 (patch)
tree2e2d678662bc8bcd7aa9075505dd8c792cdde348 /elf/get-dynamic-info.h
parente895cff59aa562cad83fa0fdd187bfe4b45312d5 (diff)
downloadglibc-60196d2ef2850f222c7c93818ccb4d9cdbd77276.tar
glibc-60196d2ef2850f222c7c93818ccb4d9cdbd77276.tar.gz
glibc-60196d2ef2850f222c7c93818ccb4d9cdbd77276.tar.bz2
glibc-60196d2ef2850f222c7c93818ccb4d9cdbd77276.zip
elf: Properly handle zero DT_RELA/DT_REL values
With DT_RELR, there may be no relocations in DT_RELA/DT_REL and their entry values are zero. Don't relocate DT_RELA/DT_REL and update the combined relocation start address if their entry values are zero.
Diffstat (limited to 'elf/get-dynamic-info.h')
-rw-r--r--elf/get-dynamic-info.h24
1 files changed, 18 insertions, 6 deletions
diff --git a/elf/get-dynamic-info.h b/elf/get-dynamic-info.h
index 6c2a3a12b1..0314baf020 100644
--- a/elf/get-dynamic-info.h
+++ b/elf/get-dynamic-info.h
@@ -75,24 +75,36 @@ elf_get_dynamic_info (struct link_map *l, bool bootstrap,
# define ADJUST_DYN_INFO(tag) \
do \
- if (info[tag] != NULL) \
- info[tag]->d_un.d_ptr += l_addr; \
+ { \
+ if (info[tag] != NULL) \
+ info[tag]->d_un.d_ptr += l_addr; \
+ } \
while (0)
ADJUST_DYN_INFO (DT_HASH);
ADJUST_DYN_INFO (DT_PLTGOT);
ADJUST_DYN_INFO (DT_STRTAB);
ADJUST_DYN_INFO (DT_SYMTAB);
+ ADJUST_DYN_INFO (DT_RELR);
+ ADJUST_DYN_INFO (DT_JMPREL);
+ ADJUST_DYN_INFO (VERSYMIDX (DT_VERSYM));
+ ADJUST_DYN_INFO (ADDRIDX (DT_GNU_HASH));
+# undef ADJUST_DYN_INFO
+
+ /* DT_RELA/DT_REL are mandatory. But they may have zero value if
+ there is DT_RELR. Don't relocate them if they are zero. */
+# define ADJUST_DYN_INFO(tag) \
+ do \
+ if (info[tag] != NULL && info[tag]->d_un.d_ptr != 0) \
+ info[tag]->d_un.d_ptr += l_addr; \
+ while (0)
+
# if ! ELF_MACHINE_NO_RELA
ADJUST_DYN_INFO (DT_RELA);
# endif
# if ! ELF_MACHINE_NO_REL
ADJUST_DYN_INFO (DT_REL);
# endif
- ADJUST_DYN_INFO (DT_RELR);
- ADJUST_DYN_INFO (DT_JMPREL);
- ADJUST_DYN_INFO (VERSYMIDX (DT_VERSYM));
- ADJUST_DYN_INFO (ADDRIDX (DT_GNU_HASH));
# undef ADJUST_DYN_INFO
}
if (info[DT_PLTREL] != NULL)