<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/78452>78452</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
TSAN segfault on Alpine Linux/musl dynamic linker
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Amguls
</td>
</tr>
</table>
<pre>
Encountered the same issue as reported in google/sanitizers#1713 where attempting to instrument any code with TSAN in Alpine Linux would cause a segmentation fault before `main` is called.
The source of this appears to be related to the use of `.preinit_array` to initialize TSAN - the musl-based dynamic linker/loader used in Alpine does not have the expected support for this section that the compile time feature checks expect based on the platform. As a result, the runtime is not initialized, causing the segmentation fault when an intercepted function is called.
I have confirmed this by experimenting with modifying `LazyInitialize` in `tsan_rtl.h` to remove the preprocessor conditions that exclude the implementation when `.preinit_array` is expected to have already initialized the runtime. This fixes the observed issue in my testing, getting the expected TSAN output for the example racy code.
Unsure of the context of the potential cost of removing these on more common platforms - ideally the feature check would simply be more accurate, but not sure of feasibility.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsVM2O4zYMfhrnQkzg2Mlk5uBD2m2ABRa9dHte0BJtsytLhkjNjOfpC8nz2-4lgW2J_P5IFOHRE3XV6bfq9GWHSacQu8s8Jie7Pti1-8ObkLxSJAs6EQjOBCySCFAg0hKikgX2MIYwOqqaq6Bn5WeKUjXt4Xxo4XGiSICqNC_KfgQNwF40ppm8AvoVTLAEj6wTfP_r8meud3ELe4Jv7NMTPIbkLBhMQoAgNOaLqBw8DJicQk9DiATVbT0j--q2BhYw6BzZfVV_qerL9vs9cwgpGoIwgE4sgMtCGCWD6gkiOcyMNBS-uWEYct39Eok96w-MEdfcobBgZXT8TBvum3JpTuJuehSyYFePMxtw7H9SrJqrC2gp5rr2A0sbSMAHhQkfqNSgp4VMBiJpySLDEOKGV8gU4jqhlqMmzAs7Au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