@@ -142,8 +142,6 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
int result;
#ifndef SHARED
- _dl_relocate_static_pie ();
-
char **ev = &argv[argc + 1];
__environ = ev;
@@ -165,24 +163,7 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
}
# endif
_dl_aux_init (auxvec);
- if (GL(dl_phdr) == NULL)
# endif
- {
- /* Starting from binutils-2.23, the linker will define the
- magic symbol __ehdr_start to point to our own ELF header
- if it is visible in a segment that also includes the phdrs.
- So we can set up _dl_phdr and _dl_phnum even without any
- information from auxv. */
-
- extern const ElfW(Ehdr) __ehdr_start
- __attribute__ ((weak, visibility ("hidden")));
- if (&__ehdr_start != NULL)
- {
- assert (__ehdr_start.e_phentsize == sizeof *GL(dl_phdr));
- GL(dl_phdr) = (const void *) &__ehdr_start + __ehdr_start.e_phoff;
- GL(dl_phnum) = __ehdr_start.e_phnum;
- }
- }
/* Initialize very early so that tunables can use it. */
__libc_init_secure ();
@@ -191,6 +172,11 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
ARCH_INIT_CPU_FEATURES ();
+ /* Do static pie self relocation after tunables and cpu features
+ are setup for ifunc resolvers. Before this point relocations
+ must be avoided. */
+ _dl_relocate_static_pie ();
+
/* Perform IREL{,A} relocations. */
ARCH_SETUP_IREL ();
@@ -202,6 +188,26 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL),
hwcap and platform fields available in the TCB. */
ARCH_APPLY_IREL ();
+# ifdef HAVE_AUX_VECTOR
+ if (GL(dl_phdr) == NULL)
+# endif
+ {
+ /* Starting from binutils-2.23, the linker will define the
+ magic symbol __ehdr_start to point to our own ELF header
+ if it is visible in a segment that also includes the phdrs.
+ So we can set up _dl_phdr and _dl_phnum even without any
+ information from auxv. */
+
+ extern const ElfW(Ehdr) __ehdr_start
+ __attribute__ ((weak, visibility ("hidden")));
+ if (&__ehdr_start != NULL)
+ {
+ assert (__ehdr_start.e_phentsize == sizeof *GL(dl_phdr));
+ GL(dl_phdr) = (const void *) &__ehdr_start + __ehdr_start.e_phoff;
+ GL(dl_phnum) = __ehdr_start.e_phnum;
+ }
+ }
+
/* Set up the stack checker's canary. */
uintptr_t stack_chk_guard = _dl_setup_stack_chk_guard (_dl_random);
# ifdef THREAD_SET_STACK_GUARD