From b84498990c9812476158f137c9e60230965ad9cf Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Tue, 4 Jan 2022 16:42:06 -0800 Subject: [PATCH] elf: Perform DT_RELR relocation only once on ld.so ld.so is relocated twice. The first time is during bootstrap and the second time is during the final startup. Check RTLD_BOOTSTRAP to perform DT_RELR relocation only once on ld.so. --- elf/dynamic-link.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/elf/dynamic-link.h b/elf/dynamic-link.h index 6710211367..e8880b7b1a 100644 --- a/elf/dynamic-link.h +++ b/elf/dynamic-link.h @@ -179,13 +179,19 @@ elf_machine_lazy_rel (struct link_map *map, struct r_scope_elem *scope[], /* This can't just be an inline function because GCC is too dumb to inline functions containing inlines themselves. */ +# ifdef RTLD_BOOTSTRAP +# define DO_RTLD_BOOTSTRAP 1 +# else +# define DO_RTLD_BOOTSTRAP 0 +# endif # define ELF_DYNAMIC_RELOCATE(map, scope, lazy, consider_profile, skip_ifunc) \ do { \ int edr_lazy = elf_machine_runtime_setup ((map), (scope), (lazy), \ (consider_profile)); \ ELF_DYNAMIC_DO_REL ((map), (scope), edr_lazy, skip_ifunc); \ ELF_DYNAMIC_DO_RELA ((map), (scope), edr_lazy, skip_ifunc); \ - ELF_DYNAMIC_DO_RELR ((map)); \ + if ((map) != &GL(dl_rtld_map) || DO_RTLD_BOOTSTRAP) \ + ELF_DYNAMIC_DO_RELR (map); \ } while (0) #endif -- 2.33.1