Move the abort message to libc_shared_globals

__libc_shared_globals() is available in dynamic modules as soon as
relocation has finished (i.e. after ifuncs run). Before ifuncs have run,
the android_set_abort_message() function already doesn't work because it
calls public APIs via the PLT. (If this matters, we can use a static
bool variable to enable android_set_abort_message after libc
initialization).

__libc_shared_globals() is hidden, so it's available in the linker
immediately (i.e. before relocation). TLS memory (e.g. errno) currently
isn't accessible until after relocation, but a later patch fixes that.

Bug: none
Test: bionic unit tests
Change-Id: Ied4433758ed2da9ee404c6158e319cf502d05a53
diff --git a/libc/private/KernelArgumentBlock.h b/libc/private/KernelArgumentBlock.h
index 1e053a1..c8ce841 100644
--- a/libc/private/KernelArgumentBlock.h
+++ b/libc/private/KernelArgumentBlock.h
@@ -23,8 +23,6 @@
 
 #include "private/bionic_macros.h"
 
-struct abort_msg_t;
-
 // When the kernel starts the dynamic linker, it passes a pointer to a block
 // of memory containing argc, the argv array, the environment variable array,
 // and the array of ELF aux vectors. This class breaks that block up into its
@@ -64,9 +62,6 @@
   char** envp;
   ElfW(auxv_t)* auxv;
 
-  // Other data that we want to pass from the dynamic linker to libc.so.
-  abort_msg_t** abort_message_ptr;
-
  private:
   BIONIC_DISALLOW_COPY_AND_ASSIGN(KernelArgumentBlock);
 };
diff --git a/libc/private/bionic_globals.h b/libc/private/bionic_globals.h
index 44ec2e3..e9eaee0 100644
--- a/libc/private/bionic_globals.h
+++ b/libc/private/bionic_globals.h
@@ -30,6 +30,7 @@
 #define _PRIVATE_BIONIC_GLOBALS_H
 
 #include <sys/cdefs.h>
+#include <pthread.h>
 
 #include "private/bionic_fdsan.h"
 #include "private/bionic_malloc_dispatch.h"
@@ -44,6 +45,8 @@
 
 __LIBC_HIDDEN__ extern WriteProtected<libc_globals> __libc_globals;
 
+struct abort_msg_t;
+
 // Globals shared between the dynamic linker and libc.so.
 struct libc_shared_globals {
   FdTable fd_table;
@@ -52,6 +55,9 @@
   // record the number of arguments passed to the linker itself rather than to
   // the program it's loading. Typically 0, sometimes 1.
   int initial_linker_arg_count;
+
+  pthread_mutex_t abort_msg_lock;
+  abort_msg_t* abort_msg;
 };
 
 __LIBC_HIDDEN__ libc_shared_globals* __libc_shared_globals();