Split main thread init into early+late functions
Split __libc_init_main_thread into __libc_init_main_thread_early and
__libc_init_main_thread_late. The early function is called very early in
the startup of the dynamic linker and static executables. It initializes
the global auxv pointer and enough TLS memory to do system calls, access
errno, and run -fstack-protector code (but with a zero cookie because the
code for generating a cookie is complex).
After the linker is relocated, __libc_init_main_thread_late finishes
thread initialization.
Bug: none
Test: bionic unit tests
Change-Id: I6fcd8d7587a380f8bd649c817b40a3a6cc1d2ee0
Merged-In: I6fcd8d7587a380f8bd649c817b40a3a6cc1d2ee0
(cherry picked from commit 39bc44bb0e03514e8d92f8c0ceb0b5901e27a485)
diff --git a/linker/linker_main.cpp b/linker/linker_main.cpp
index aa12b6e..b384ce4 100644
--- a/linker/linker_main.cpp
+++ b/linker/linker_main.cpp
@@ -559,11 +559,9 @@
* function, or other GOT reference will generate a segfault.
*/
extern "C" ElfW(Addr) __linker_init(void* raw_args) {
+ // Initialize TLS early so system calls and errno work.
KernelArgumentBlock args(raw_args);
-
-#if defined(__i386__)
- __libc_init_sysinfo(args);
-#endif
+ __libc_init_main_thread_early(args);
// When the linker is run by itself (rather than as an interpreter for
// another program), AT_BASE is 0.
@@ -622,8 +620,8 @@
*/
static ElfW(Addr) __attribute__((noinline))
__linker_init_post_relocation(KernelArgumentBlock& args, soinfo& tmp_linker_so) {
- // Initialize the main thread (including TLS, so system calls really work).
- __libc_init_main_thread(args);
+ // Finish initializing the main thread.
+ __libc_init_main_thread_late(args);
// We didn't protect the linker's RELRO pages in link_image because we
// couldn't make system calls on x86 at that point, but we can now...