diff options
| author | Treehugger Robot <treehugger-gerrit@google.com> | 2018-05-31 01:45:41 +0000 |
|---|---|---|
| committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2018-05-31 01:45:41 +0000 |
| commit | 8b14ed45ec1ee92ee371c5ec7b0097c7e026da5c (patch) | |
| tree | 58ccaceefd1e97a670494384d428fe0c55c8a5d1 | |
| parent | d0c330b5d852d9c397fe86845893c46103ecf09e (diff) | |
| parent | 6631f9b03dd032519be4b1971c2399a6e5e59357 (diff) | |
Merge "Clean up TLS_SLOT_BIONIC_PREINIT usage a bit"
| -rw-r--r-- | libc/bionic/__libc_init_main_thread.cpp | 7 | ||||
| -rw-r--r-- | libc/bionic/libc_init_dynamic.cpp | 16 | ||||
| -rw-r--r-- | libc/bionic/libc_init_static.cpp | 3 | ||||
| -rw-r--r-- | linker/linker_main.cpp | 4 |
4 files changed, 12 insertions, 18 deletions
diff --git a/libc/bionic/__libc_init_main_thread.cpp b/libc/bionic/__libc_init_main_thread.cpp index efa7dee57..a18a8317c 100644 --- a/libc/bionic/__libc_init_main_thread.cpp +++ b/libc/bionic/__libc_init_main_thread.cpp @@ -81,8 +81,7 @@ void __libc_init_main_thread(KernelArgumentBlock& args) { // We don't want to free the main thread's stack even when the main thread exits // because things like environment variables with global scope live on it. - // We also can't free the pthread_internal_t itself, since that lives on the main - // thread's stack rather than on the heap. + // We also can't free the pthread_internal_t itself, since it is a static variable. // The main thread has no mmap allocated space for stack or pthread_internal_t. main_thread.mmap_size = 0; @@ -102,9 +101,5 @@ void __libc_init_main_thread(KernelArgumentBlock& args) { __init_thread(&main_thread); - // Store a pointer to the kernel argument block in a TLS slot to be - // picked up by the libc constructor. - main_thread.tls[TLS_SLOT_BIONIC_PREINIT] = &args; - __init_alternate_signal_stack(&main_thread); } diff --git a/libc/bionic/libc_init_dynamic.cpp b/libc/bionic/libc_init_dynamic.cpp index 0b682808f..fb086c83b 100644 --- a/libc/bionic/libc_init_dynamic.cpp +++ b/libc/bionic/libc_init_dynamic.cpp @@ -85,14 +85,11 @@ static void __libc_preinit_impl(KernelArgumentBlock& args) { // to run before any others (such as the jemalloc constructor), and lower // is better (http://b/68046352). __attribute__((constructor(1))) static void __libc_preinit() { - // Read the kernel argument block pointer from TLS. + // Read the kernel argument block pointer from TLS, then clear the slot so no + // other initializer sees its value. void** tls = __get_tls(); - KernelArgumentBlock** args_slot = &reinterpret_cast<KernelArgumentBlock**>(tls)[TLS_SLOT_BIONIC_PREINIT]; - KernelArgumentBlock* args = *args_slot; - - // Clear the slot so no other initializer sees its value. - // __libc_init_common() will change the TLS area so the old one won't be accessible anyway. - *args_slot = NULL; + KernelArgumentBlock* args = static_cast<KernelArgumentBlock*>(tls[TLS_SLOT_BIONIC_PREINIT]); + tls[TLS_SLOT_BIONIC_PREINIT] = nullptr; // The linker has initialized its copy of the global stack_chk_guard, and filled in the main // thread's TLS slot with that value. Initialize the local global stack guard with its value. @@ -102,9 +99,8 @@ __attribute__((constructor(1))) static void __libc_preinit() { } // This function is called from the executable's _start entry point -// (see arch-$ARCH/bionic/crtbegin_dynamic.S), which is itself -// called by the dynamic linker after it has loaded all shared -// libraries the executable depends on. +// (see arch-$ARCH/bionic/crtbegin.c), which is itself called by the dynamic +// linker after it has loaded all shared libraries the executable depends on. // // Note that the dynamic linker has also run all constructors in the // executable at this point. diff --git a/libc/bionic/libc_init_static.cpp b/libc/bionic/libc_init_static.cpp index d19dd2882..4d62efe8d 100644 --- a/libc/bionic/libc_init_static.cpp +++ b/libc/bionic/libc_init_static.cpp @@ -86,10 +86,9 @@ __noreturn void __libc_init(void* raw_args, BIONIC_STOP_UNWIND; KernelArgumentBlock args(raw_args); - __libc_init_main_thread(args); // Initializing the globals requires TLS to be available for errno. - __init_thread_stack_guard(__get_thread()); + __libc_init_main_thread(args); __libc_init_globals(args); __libc_init_AT_SECURE(args); diff --git a/linker/linker_main.cpp b/linker/linker_main.cpp index 00c72d02a..fa4fd4ccb 100644 --- a/linker/linker_main.cpp +++ b/linker/linker_main.cpp @@ -414,6 +414,10 @@ static ElfW(Addr) __linker_init_post_relocation(KernelArgumentBlock& args) { if (!get_cfi_shadow()->InitialLinkDone(solist)) __linker_cannot_link(g_argv[0]); + // Store a pointer to the kernel argument block in a TLS slot to be + // picked up by the libc constructor. + __get_tls()[TLS_SLOT_BIONIC_PREINIT] = &args; + si->call_pre_init_constructors(); /* After the prelink_image, the si->load_bias is initialized. |
