<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/105958>105958</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[lld] Thread-related non-reproducibility when linking FreeBSD EFI loader
</td>
</tr>
<tr>
<th>Labels</th>
<td>
lld:ELF
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
DimitryAndric
</td>
</tr>
</table>
<pre>
As part of investigations for https://bugs.freebsd.org/276961 ("buildworld artifacts not reproducible between native and cross build") @emaste and I also noticed that parts of the FreeBSD EFI boot loaders would be different between each build.
This turned out to be an lld issue, where linking exactly same binary twice results in a different output file. It is related to threading, because adding `-Wl,--threads=1` makes the output reproducible. (And this is the workaround we have committed in https://github.com/freebsd/freebsd-src/commit/f5ce3f4ef562ea9fc4d8f9c13c268f48a5bacba7.)
Since this does not happen to any other ELF binaries in our tree, the custom linker script is probably the cause, but we would still expect the output of lld to be deterministic.
I have attached a tarball with a full reproduction test case:
[loader_simp.tar.gz](https://github.com/user-attachments/files/16737898/loader_simp.tar.gz)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJx8lE2P2zYQhn8NfRnYkKkPSwcdnHgNLJBbAvRYDMmRxS5FCuRoHffXF5Q2u9uiyMUyJM4Hn3nfwZTszRP1ov4i6ssOFx5D7C92shwfZ2-i1TsVzKM_J5gxMoQBrH-lxPaGbINPMIQII_OcRHkW8irkVS23dBgikUrmEOJNyKs8NV1zBCFbIaVarDP3EJ0BjGwH1JzAB4ZIcwxm0VY5AkV8J_Lgke0rAXoDOoaUYA0XUgrZgagKmjDx9v0Z0KWQU1lNBnhEXrtOuW0eCa6R6Mv3Czxdn0GFwOACGooJ7mFxBhSBscNAkTy_1yfU41bzIIqLKM7b74_RJuAlejIQFgYOORw9OGfAprSQkF_hPlIkcNa_WH8D-oma3QMSTgTKeowP4LvVBJHS4jiB9YCfeggLzwvDYB0d4JnBJ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