[MTE] do not use ldg in linker if MTE is off for process

Test: with and without MTE:
      atest libprocinfo_test bionic-unit-tests bionic-unit-tests-static debuggerd_test memtag_stack_dlopen_test
Bug: 381781855
Change-Id: I3f6923715d2ce442a2e8c23215f36911b305ede3
diff --git a/libc/bionic/heap_tagging.cpp b/libc/bionic/heap_tagging.cpp
index 6741be3..c731970 100644
--- a/libc/bionic/heap_tagging.cpp
+++ b/libc/bionic/heap_tagging.cpp
@@ -123,6 +123,7 @@
         }
         atomic_store(&__libc_memtag_stack, false);
         atomic_store(&globals->memtag, false);
+        atomic_store(&__libc_shared_globals()->memtag_currently_on, false);
       });
 
       if (heap_tagging_level != M_HEAP_TAGGING_LEVEL_TBI) {
diff --git a/libc/bionic/libc_init_mte.cpp b/libc/bionic/libc_init_mte.cpp
index 3c8ef7d..eda2eec 100644
--- a/libc/bionic/libc_init_mte.cpp
+++ b/libc/bionic/libc_init_mte.cpp
@@ -273,6 +273,7 @@
     if (prctl(PR_SET_TAGGED_ADDR_CTRL, prctl_arg | PR_MTE_TCF_SYNC, 0, 0, 0) == 0 ||
         prctl(PR_SET_TAGGED_ADDR_CTRL, prctl_arg, 0, 0, 0) == 0) {
       __libc_shared_globals()->initial_heap_tagging_level = level;
+      atomic_store(&__libc_shared_globals()->memtag_currently_on, true);
 
       struct sigaction action = {};
       action.sa_flags = SA_SIGINFO | SA_RESTART;
@@ -320,6 +321,5 @@
 #endif  // __aarch64__
 
 bool __libc_mte_enabled() {
-  HeapTaggingLevel lvl = __libc_shared_globals()->initial_heap_tagging_level;
-  return lvl == M_HEAP_TAGGING_LEVEL_SYNC || lvl == M_HEAP_TAGGING_LEVEL_ASYNC;
+  return atomic_load(&__libc_shared_globals()->memtag_currently_on);
 }