mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-21 20:40:05 +00:00
elf: Fix elf_get_dynamic_info() for bootstrap
THe d6d89608ac
broke powerpc for --enable-bind-now because it turned
out that different than patch assumption rtld elf_get_dynamic_info()
does require to handle RTLD_BOOTSTRAP to avoid DT_FLAGS and
DT_RUNPATH (more specially the GLRO usage which is not reallocate
yet).
This patch fixes by passing two arguments to elf_get_dynamic_info()
to inform that by rtld (bootstrap) or static pie initialization
(static_pie_bootstrap). I think using explicit argument is way more
clear and burried C preprocessor, and compiler should remove the
dead code.
I checked on x86_64 and i686 with default options, --enable-bind-now,
and --enable-bind-now and --enable--static-pie. I also check on
aarch64, armhf, powerpc64, and powerpc with default and
--enable-bind-now.
This commit is contained in:
parent
1d3decee99
commit
5118dcac68
@ -1298,7 +1298,7 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
|
||||
else
|
||||
l->l_ld = (ElfW(Dyn) *) ((ElfW(Addr)) l->l_ld + l->l_addr);
|
||||
|
||||
elf_get_dynamic_info (l);
|
||||
elf_get_dynamic_info (l, false, false);
|
||||
|
||||
/* Make sure we are not dlopen'ing an object that has the
|
||||
DF_1_NOOPEN flag set, or a PIE object. */
|
||||
|
@ -25,7 +25,6 @@
|
||||
|
||||
#include <dl-machine.h>
|
||||
|
||||
#define STATIC_PIE_BOOTSTRAP
|
||||
#define RESOLVE_MAP(map, scope, sym, version, flags) map
|
||||
#include "dynamic-link.h"
|
||||
#include "get-dynamic-info.h"
|
||||
@ -52,7 +51,7 @@ _dl_relocate_static_pie (void)
|
||||
break;
|
||||
}
|
||||
|
||||
elf_get_dynamic_info (main_map);
|
||||
elf_get_dynamic_info (main_map, false, true);
|
||||
|
||||
# ifdef ELF_MACHINE_BEFORE_RTLD_RELOC
|
||||
ELF_MACHINE_BEFORE_RTLD_RELOC (main_map, main_map->l_info);
|
||||
|
@ -26,7 +26,8 @@
|
||||
#include <libc-diag.h>
|
||||
|
||||
static inline void __attribute__ ((unused, always_inline))
|
||||
elf_get_dynamic_info (struct link_map *l)
|
||||
elf_get_dynamic_info (struct link_map *l, bool bootstrap,
|
||||
bool static_pie_bootstrap)
|
||||
{
|
||||
#if __ELF_NATIVE_CLASS == 32
|
||||
typedef Elf32_Word d_tag_utype;
|
||||
@ -35,7 +36,7 @@ elf_get_dynamic_info (struct link_map *l)
|
||||
#endif
|
||||
|
||||
#ifndef STATIC_PIE_BOOTSTRAP
|
||||
if (l->l_ld == NULL)
|
||||
if (!bootstrap && l->l_ld == NULL)
|
||||
return;
|
||||
#endif
|
||||
|
||||
@ -112,10 +113,22 @@ elf_get_dynamic_info (struct link_map *l)
|
||||
if (info[DT_REL] != NULL)
|
||||
assert (info[DT_RELENT]->d_un.d_val == sizeof (ElfW(Rel)));
|
||||
#endif
|
||||
#ifdef STATIC_PIE_BOOTSTRAP
|
||||
if (bootstrap || static_pie_bootstrap)
|
||||
{
|
||||
assert (info[DT_RUNPATH] == NULL);
|
||||
assert (info[DT_RPATH] == NULL);
|
||||
#endif
|
||||
}
|
||||
if (bootstrap)
|
||||
{
|
||||
/* Only the bind now flags are allowed. */
|
||||
assert (info[VERSYMIDX (DT_FLAGS_1)] == NULL
|
||||
|| (info[VERSYMIDX (DT_FLAGS_1)]->d_un.d_val & ~DF_1_NOW) == 0);
|
||||
/* Flags must not be set for ld.so. */
|
||||
assert (info[DT_FLAGS] == NULL
|
||||
|| (info[DT_FLAGS]->d_un.d_val & ~DF_BIND_NOW) == 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (info[DT_FLAGS] != NULL)
|
||||
{
|
||||
/* Flags are used. Translate to the old form where available.
|
||||
@ -130,6 +143,7 @@ elf_get_dynamic_info (struct link_map *l)
|
||||
if (l->l_flags & DF_BIND_NOW)
|
||||
info[DT_BIND_NOW] = info[DT_FLAGS];
|
||||
}
|
||||
|
||||
if (info[VERSYMIDX (DT_FLAGS_1)] != NULL)
|
||||
{
|
||||
l->l_flags_1 = info[VERSYMIDX (DT_FLAGS_1)]->d_un.d_val;
|
||||
@ -144,15 +158,18 @@ elf_get_dynamic_info (struct link_map *l)
|
||||
intent of notifying the user of the problem. */
|
||||
if (__builtin_expect (GLRO(dl_debug_mask) & DL_DEBUG_FILES, 0)
|
||||
&& l->l_flags_1 & ~DT_1_SUPPORTED_MASK)
|
||||
_dl_debug_printf ("\nWARNING: Unsupported flag value(s) of 0x%x in DT_FLAGS_1.\n",
|
||||
_dl_debug_printf ("\nWARNING: Unsupported flag value(s) of 0x%x "
|
||||
"in DT_FLAGS_1.\n",
|
||||
l->l_flags_1 & ~DT_1_SUPPORTED_MASK);
|
||||
|
||||
if (l->l_flags_1 & DF_1_NOW)
|
||||
info[DT_BIND_NOW] = info[VERSYMIDX (DT_FLAGS_1)];
|
||||
}
|
||||
|
||||
if (info[DT_RUNPATH] != NULL)
|
||||
/* If both RUNPATH and RPATH are given, the latter is ignored. */
|
||||
info[DT_RPATH] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -547,7 +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 ();
|
||||
elf_get_dynamic_info (&bootstrap_map);
|
||||
elf_get_dynamic_info (&bootstrap_map, true, false);
|
||||
|
||||
#if NO_TLS_OFFSET != 0
|
||||
bootstrap_map.l_tls_offset = NO_TLS_OFFSET;
|
||||
@ -1615,7 +1615,7 @@ dl_main (const ElfW(Phdr) *phdr,
|
||||
if (! rtld_is_main)
|
||||
{
|
||||
/* Extract the contents of the dynamic section for easy access. */
|
||||
elf_get_dynamic_info (main_map);
|
||||
elf_get_dynamic_info (main_map, false, false);
|
||||
|
||||
/* If the main map is libc.so, update the base namespace to
|
||||
refer to this map. If libc.so is loaded later, this happens
|
||||
|
@ -64,7 +64,7 @@ setup_vdso (struct link_map *main_map __attribute__ ((unused)),
|
||||
l->l_map_end += l->l_addr;
|
||||
l->l_text_end += l->l_addr;
|
||||
l->l_ld = (void *) ((ElfW(Addr)) l->l_ld + l->l_addr);
|
||||
elf_get_dynamic_info (l);
|
||||
elf_get_dynamic_info (l, false, false);
|
||||
_dl_setup_hash (l);
|
||||
l->l_relocated = 1;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user