<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/124215>124215</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Destroy unused `MaterializationUnit`s outside the session lock.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
orcjit
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
lhames
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
lhames
</td>
</tr>
</table>
<pre>
`UnmaterializedInfo` objects own `MaterializationUnit`s whose destructors may take locks as part of cleanup. This can lead to lock-cycle warnings from TSan. E.g. in LLJIT recently there was a cycle where an IRModule's context lock (M0) was held while the session lock was taken (M1) to register new materializing symbols, but also the session lock (M1) could be held during `JITDylib::IR_removeTracker` when the IRModule's context lock (M0) was taken in order to destroy the module.
We should ensure that the session lock is always a leaf lock to avoid this. To do so, `MaterializationUnit`s to be discarded should be moved out from under the session lock before destroying them.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMU8GO2zYQ_RrqMliBoi15fdBh260BB9lL6qDHgiJHErMUZ8Eh7bpfX1B2EqALLHISQM17896bGc3spoDYi_Y3oZSf9YIslBLtc6Vzmin2t7dqIHvtRSe_hkUnjE579y_aYxhJdBJo-IYmMdAlgOjky48SnRyFr8El0UmGy0yMYJFTzCZRZFj0FZJ-RfBkXhk0w5uOCWgE41GH_FbDaXYMRgfwqC0kWksfzNV4hIuOwYWJYYy0wOlPHWr4o55qcAE-f_50PEFEgyH5K6QZYwEwaLiD1xcd4PjlhWz2KNSOwVBI-E9au4BQjy9SqP2Km9FbuMzOYyEDRmZH4VZY_hcfYYU0BZIIIk6OE0YIeIGfubkwAV-XgTwL9TsMOYH2TO9Zf3AZyt7CgDcNNsdCITr56Xh6vno3iM2T2Dwdv_wdcaEznqI2rxjLZC4zhpX4F03eTLgAFC3GYmIdF60BwrJS1EI-Cfn0FwLPqzAMnGNJRaf3JhyD9hd9LcF71OPtNRHoMzkLaXZcw4nAEjCVPD5YoEQlBOvY6GjRfu8_FGVntEA53VYhh1X9_7UMOFLE75ZKiGnGpa5sv7H7zV5X2De7za57VHulqrl_lFYP7WODaruT2Jp9g1LZVkkjB7mXu8r1SqpWNmorm62Sqh51t1WbxuzabjeOoxJbiYt2vvb-vNQUp8oxZ-wbtVVNW3k9oOf7-VE031y6n1_sC-JhyBOLrfSOE__kSC557J_vk8khM9qPcqOc2Nn3e1tXOfp-TumNywqpg1CHyaU5D7WhRahD6Xj_PLxFKlcu1GG1wEId7i7OvfovAAD__0HIdXo">