<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/73693>73693</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
`COMMON` Symbols causing issues when linking with LLD
</td>
</tr>
<tr>
<th>Labels</th>
<td>
lld
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Saldivarcher
</td>
</tr>
</table>
<pre>
From: https://discourse.llvm.org/t/common-symbols-causing-issues/75272
When linking an application, I noticed that when using `LLD` in some of the stages, it causes an issue at runtime. I was able to deduce that the issue was caused on how `LLD` resolves `COMMON` symbols.
As seen from the linked discourse discussion, `bfd` and `mold` seem to both leave the symbol undefined due to the shared library definition taking precedence. I noticed in the `LLD` code when a `COMMON` symbol is resolved within a shared object, it hits [this block](https://github.com/llvm/llvm-project/blob/main/lld/ELF/Symbols.cpp#L671), and doesn't overwrite the old symbol. Should it?
Here are the two files that get linked together into created a shared object:
```console
$ nm libfckit_lite.so | grep "\$data_init\$fckit_owned_object_module_"
0000000000008700 D $data_init$fckit_owned_object_module_
$ nm atlas_object.F90.o | grep "\$data_init\$fckit_owned_object_module_"
0000000000000238 C $data_init$fckit_owned_object_module_
```
`libfckit_lite.so` is what holds the actual definition, and here is the resulting shared object; note that the suffix is the linker used:
```console
$ nm libatlas_lite_lld.so | grep "\$data_init\$fckit_owned_object_module_"
000000000000e240 B $data_init$fckit_owned_object_module_
$ nm libatlas_lite_bfd.so | grep "\$data_init\$fckit_owned_object_module_"
U $data_init$fckit_owned_object_module_
```
Finally this is what the final executable looks like:
```console
$ nm exe_lld | grep "\$data_init\$fckit_owned_object_module_"
0000000000404700 B $data_init$fckit_owned_object_module_
$ nm exe_bfd | grep "\$data_init\$fckit_owned_object_module_"
U $data_init$fckit_owned_object_module_
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVk2P4jgQ_TXmUmrkOJDAIYdu2GhHYnYOrdUekWN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