Decrease logspam of stack MTE remapping.

Currently the log is called for each library that's loaded with MTE
stack. For apps that are a launched with stack MTE (e.g. the CTS test
apps), this causes ~40 or so loglines telling us that the stack is being
remapped.

Instead, make it log only once, the first time it's remapped.

Bug: N/A
Test: blatant visual code inspection
Change-Id: If2883bc2355318b1db83f0c5ccb67050a457b52e
diff --git a/libc/bionic/libc_init_dynamic.cpp b/libc/bionic/libc_init_dynamic.cpp
index 2dde2f1..541e71c 100644
--- a/libc/bionic/libc_init_dynamic.cpp
+++ b/libc/bionic/libc_init_dynamic.cpp
@@ -61,8 +61,9 @@
 };
 
 void memtag_stack_dlopen_callback() {
-  async_safe_format_log(ANDROID_LOG_DEBUG, "libc", "remapping stacks as PROT_MTE");
-  __pthread_internal_remap_stack_with_mte();
+  if (__pthread_internal_remap_stack_with_mte()) {
+    async_safe_format_log(ANDROID_LOG_DEBUG, "libc", "remapped stacks as PROT_MTE");
+  }
 }
 
 // Use an initializer so __libc_sysinfo will have a fallback implementation
diff --git a/libc/bionic/pthread_internal.cpp b/libc/bionic/pthread_internal.cpp
index 3c8f9d5..e8a8ba2 100644
--- a/libc/bionic/pthread_internal.cpp
+++ b/libc/bionic/pthread_internal.cpp
@@ -240,12 +240,12 @@
   return reinterpret_cast<void*>(aligned_allocation | ((1ULL << n) << 56ULL));
 }
 
-void __pthread_internal_remap_stack_with_mte() {
+bool __pthread_internal_remap_stack_with_mte() {
 #if defined(__aarch64__)
   ScopedWriteLock creation_locker(&g_thread_creation_lock);
   ScopedReadLock list_locker(&g_thread_list_lock);
   // If process already uses memtag-stack ABI, we don't need to do anything.
-  if (__libc_memtag_stack_abi) return;
+  if (__libc_memtag_stack_abi) return false;
   __libc_memtag_stack_abi = true;
 
   for (pthread_internal_t* t = g_thread_list; t != nullptr; t = t->next) {
@@ -253,8 +253,8 @@
     t->bionic_tcb->tls_slot(TLS_SLOT_STACK_MTE) =
         __allocate_stack_mte_ringbuffer(0, t->is_main() ? nullptr : t);
   }
-  if (!atomic_load(&__libc_globals->memtag)) return;
-  if (atomic_exchange(&__libc_memtag_stack, true)) return;
+  if (!atomic_load(&__libc_globals->memtag)) return false;
+  if (atomic_exchange(&__libc_memtag_stack, true)) return false;
   uintptr_t lo, hi;
   __find_main_stack_limits(&lo, &hi);
 
@@ -269,7 +269,10 @@
       async_safe_fatal("error: failed to set PROT_MTE on thread: %d", t->tid);
     }
   }
-#endif
+  return true;
+#else
+  return false;
+#endif  // defined(__aarch64__)
 }
 
 bool android_run_on_all_threads(bool (*func)(void*), void* arg) {
diff --git a/libc/bionic/pthread_internal.h b/libc/bionic/pthread_internal.h
index 765fd8b..b270a06 100644
--- a/libc/bionic/pthread_internal.h
+++ b/libc/bionic/pthread_internal.h
@@ -273,8 +273,9 @@
 __LIBC_HIDDEN__ extern void __bionic_atfork_run_child();
 __LIBC_HIDDEN__ extern void __bionic_atfork_run_parent();
 
-// Re-map all threads and successively launched threads with PROT_MTE.
-__LIBC_HIDDEN__ void __pthread_internal_remap_stack_with_mte();
+// Re-map all threads and successively launched threads with PROT_MTE. Returns 'true' if remapping
+// took place, 'false' on error or if the stacks were already remapped in the past.
+__LIBC_HIDDEN__ bool __pthread_internal_remap_stack_with_mte();
 
 extern "C" bool android_run_on_all_threads(bool (*func)(void*), void* arg);