<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/64126>64126</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Several Solaris/amd64 asan tests FAIL with ASan init calls itself!
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang:driver,
compiler-rt:asan,
platform:solaris
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
rorth
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
rorth
</td>
</tr>
</table>
<pre>
A couple of asan tests `FAIL` on Solaris/amd64:
```
AddressSanitizer-Unit :: ./Asan-i386-calls-Dynamic-Test/failed_to_discover_tests_from_gtest
AddressSanitizer-Unit :: ./Asan-i386-inline-Dynamic-Test/failed_to_discover_tests_from_gtest
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/no-fd.cpp
AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/start-deactivated.cpp
AddressSanitizer-i386-sunos-dynamic :: TestCases/default_options.cpp
```
The failure mode is always the same:
```
AddressSanitizer: CHECK failed: asan_rtl.cpp:387 "((!asan_init_is_running && "ASan init calls itself!")) != (0)" (0x0, 0x0) (tid=1)
```
With great help from Ali Bahrami, the Solaris linker engineer, I've managed to determine what's going on here: there's a cycle calling `AsanInitInternal` like so:
```
libclang_rt-i386.so .init_array -> asan_rtl.cpp (AsanInitInternal)
-> asan_flags.cpp (InitializeFlags)
-> executable (__asan_default_options)
executable .init_array -> executable (asan.module_ctor)
-> asan_rtl.cpp (__asan_init)
-> asan_rtl.cpp (AsanInitInternal)
```
When `AsanInitInternal` calls `InitializeFlags`, that calls back into the executable where `clang` has created a definition of `__asan_default_options`. However, that call triggers the executable's `.init_array` processing, which includes `asan.module_ctor`. That again calls `__asan_init` and into `AsanInitInternal` a second time, completing the cycle.
I've long known that this can be avoided by disabling lazy binding, either with `LD_BIND_NOW=1` or by passing `-z now` to `ld`, either directly or via the `LD_OPTIONS` environment variable. Ali confirmed that this seems to be the sensible thing to do given the circumstances.
For a long time, I've used that workaround locally and in the Solaris/amd64 buildbot, but this has now broken down for one testcase (`AddressSanitizer-i386-sunos-dynamic :: TestCases/Posix/start-deactivated.cpp`) where the testsuite explicitly doesn't pass on `LD_*` environment variables.
I've now got a driver patch to pass `-z now` as appropriate, to be submitted shortly.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy0VsFu2zAS_Rr6MrAhS7EcH3xwkxoNtmgLJIseDYocSbOhSIGk7DpfvxjKbpw0XuwCXUBILJF8w3nvDTkyBGos4losPok8987HVuS5WNxP5BBb59fp06Ry-rjegHJDbxBcDTJICxFDDCDKbLt5-CrKDJyFR2ekpyDyrex0eSOKjcjuRbYRZXZ60itstPYYwqO0FOkF_fSfliLw9GIDM5FvN0HaKRW35VRJY8L0_mhlR2r6hCGKfFtLMqh30e00BeX26HdpO7vau27X8O__PRJZQxb_YqiEGgbrwlSPoOfAjH0nAzJTP1ygXyLfWjet9Uz1_d-BC1H6ONUoVaS9jPgXoDXWcjBx5_pIzoZXwHfyPrUITNvgETqnESiANAd5DBBbhCA7vOaM9zvjLdx9-Xz3Dxh14Hd2385Hk-IXm-J2Ceza_DY98zRMluKOws4P1pJtQOSlyEuet3mUFngYkrOAYkBTi3yeMFYiXwG_FPcg8tssfcnTz1-ZyO8g_eMpt5G0KO7nPOOjTH5SbKHxKCO0aHpgu8DGEHySrZcdMRizcSoZMGSf0QPahiyi5-EHkS_3CJ20skEN0YHGiL4ji3BoZRT5MkDjOD9noUXPtDKoxzQkQR2VwZRoIqHM2O0PluKDjeitNFy3hp4RgrtarIYqZaRtdj4mo8yCE9lqliiW3sujyFZTUXx-Iwwz9EewM1UgstXl87q6NrIJ5_W8lqShF9zy51emP1iNv1ANUVYGeeVul9DeGfY1_sX0EeODbN4iMt6sc3owuFPR-Qusq8lcUHHaEEf5j2n81xS-d1uL9pq-o89Fmb3ns8xGE8pzLVRSPQPZ6JIzLwg4sKcYIhmBQVsZQLG7UYMEjTWnRs7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