From 8e7496aa64952200e5971b3c03f9d1ec9c306609 Mon Sep 17 00:00:00 2001
From: kib <kib@FreeBSD.org>
Date: Mon, 29 Oct 2018 23:56:39 +0000
Subject: [PATCH] Initialize ifunc calling machinery earlier.

In particular, do it before the first call to allocate_initial_tls(),
which contains MD parts to set the initial thread' TLS pointer.

Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
---
 libexec/rtld-elf/rtld.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
index c59d4e0098e6..bae25210cb1b 100644
--- a/libexec/rtld-elf/rtld.c
+++ b/libexec/rtld-elf/rtld.c
@@ -709,6 +709,8 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entry **objp)
        exit (0);
     }
 
+    ifunc_init(aux);
+
     /*
      * Setup TLS for main thread.  This must be done after the
      * relocations are processed, since tls initialization section
@@ -730,7 +732,6 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entry **objp)
     r_debug_state(NULL, &obj_main->linkmap); /* say hello to gdb! */
 
     map_stacks_exec(NULL);
-    ifunc_init(aux);
 
     dbg("resolving ifuncs");
     if (resolve_objects_ifunc(obj_main,