<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/138194>138194</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Crash in lld with thin LTO cache and assembly output
</td>
</tr>
<tr>
<th>Labels</th>
<td>
lld
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
quic-akaryaki
</td>
</tr>
</table>
<pre>
After #136121 is merged, thin LTO with assembly output with cache crashes lld. A test case is basic:
`int main() { return 0; }`
```
clang -c main.c -O2 -flto=thin -o main.o
ld.lld --thinlto-cache-dir=. --lto-emit-asm -e main main.o
```
The crash happens in the destructor of MCAsmStreamer, which tries to close a stream that it was passed. However, the stream was previously closed while calling the commit() function in LTOBackend.cpp: codegen().
A simple fix would be to delete the LTO pipeline before the stream commit function is called in LTOBackend.cpp: codegen().
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMk82OnDoQhZ_GbEogMNA_Cxb0tFp3caNZZF7A2NVQGWMTu-hOv30EdGZGWUWyhGSfOvVR9lExUu8QG1GfRH1O1MyDD83PmXSq3lV4qHdKOm8eTXtlDCBkWZS7QhZAEUYMPRohX4AHcvD_2yvciQdQMeLY2Qf4maeZt02t9ICgg4oDRrDWZNACY2TQKuJi16lIWpStyNe1y8kxjIqckAchjyD2JwjIc3CQi_IEYn8Wu_xD_Vx5q61yPaR6rc00pK8S0qtlL8rzCpr67ciLvLUms9ZAmi4nln26cqaGgijPGaTpsocjcariCCmulZ_lX_u-_fk_GNQ0oYtADnhAMBg5zJp9AH-Fby9tHL9zQDViWIZ3H0gPwIEwAnvQ1kcEBXGVAA-KgRjuKsK0TNZk8J-_420rXvyfylUR8EZ-jvax-ZjF3SJoZS25fpVrP47Ez6FeZ6eZvIPtAk9Kv6MzmZ4mUbagvcEenxeQbaNuIdI4WYQr_YK7n62BDhdwgxYZ1xbLU5hoQksOocOrD_iVdCP40juugGj-kSIxTWmO5VEl2BT7aleUeSX3ydB0x2t1qA0esZCqPuiu6g7HQqpuvyuqaq8TamQu67zOC5kXZbXLjMZa59UhL-uD3NelqHIcFdnM2tuY-dAnFOOMTVEeimOVWNWhjWtapLTWCCmX2IRmkafd3EdR5ZYix08DJrbYvKwvg9zy9LdEfIRmi4Zy5u_kJHOwzcA8xSUW8iLkpSce5i7TfhTysrR4ftIp-B-oWcjLChyFvDyZb438HQAA___2bUSS">