<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/57206>57206</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Implement global tagging from dlopen with glibc
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            compiler-rt:hwasan
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            vitalybuka
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          vitalybuka
      </td>
    </tr>
</table>

<pre>
    Globals require tagging by runtime before executing any instrumented code from dso.
Note: bionic uses provides necessary hooks https://android-review.googlesource.com/c/platform/bionic/+/1096613

Maybe we can tag globals from entire dso on the first constructor from that DSO, something like

```
+static SpinMutex global_init_mutex_;
+static DenseMap<uptr, bool> global_init_done_;
+
 __attribute__((constructor(0))) void __hwasan_init() {
   CHECK(!hwasan_init_is_running);
-  if (hwasan_inited) return;
+  if (hwasan_inited) {
+    SpinMutexLock lock(&global_init_mutex_);
+    bool & done = global_init_done_[GET_CALLER_PC()];
+    if (!done) {
+      done = true;
+      InitLoadedGlobals();
+    }
+    return;
+  }
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx1U1lz2jAQ_jXiZQfG2MTgBz-EI2mmSdtp-u6RpcVWIyRXkkn5910fBJJJZ4SxtMd3WFtaecrvtS259uDwT6scQuBVpUwF5Qlca4I6IJS4txTBvyja0MW4OYEyPrj2gCagBGElwt7ZA0hvZyzasuj2mw3IklsolTVKQOvRQ-PsUUl6MSjQe-5OUFv74qEOofGUzeI7WtxIZ5WcOjwqfJ1V1lYavW2dwJmwB8oQ9Gs0D0Ss2w4YffGanvMoS9N5MvAYnk_8VCK8IghuOo1Qjbp71qSi007kwVK4JjHK-UC6epUiWDckhpoH2D5_Z_EGvD1gqDs_tHrBazCWRuMatvHaBx7IhOdGmac24N8RvlBGheLQnRQsWX9M36Lx-MQblmzaJrgOtLRWs2T3rl5ag-_KhxcoCh6CUyW1LwoWr2hdCaJdxOJsWHAkv6mgfuWem75tX5ABW57bAWy-7DZf-_P5VWKhfEFXxZATXbMzjymA2gNlX6Wi7Fo6DK0z14T_m_qG3ifBxcBHK15A06Onk35i5xWVsbjzjlBS6AwDlmw_cfFmfb_7VWxuHx93P4sfm8EEdrP92GvgS0Z0ZZ8xhQsKGY4f6wEeCPTRcolyHMER60MiW27f7T8z75JzvngTzOdpGi1XyXKxmsg8kVmS8UlQQWP-cGg0dpM76n-b-WGCtW3QwKsKNcVVKSat0_n7Aa0o2JbjLGp9PP9NacB_o6C7c6e8b5E03d0s4yid1Dlx2WerPZdZeZNKgTLZR5kQ0WJZyv2cYDQvUfucPgGLY2rdKI1u6gKhDveCjulLTFQeR3EcrearKFpk0WqWpYlIsvkqRi5iOmCLCA9c6VlHaWZdNXF5z65sK09BrXzwlyD3XlUGcUQ-qsD1qWxf-IjH21Bbl1_OJ722vBf2D3cfo6c">