<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/84730>84730</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[ELF] Unused symbol is not being garbage-collected
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
partaror
</td>
</tr>
</table>
<pre>
LLD is not garbage collecting an unused symbol that is referenced by an unused provide symbol.
Reproducible example:
```bash
#!/usr/bin/env bash
cat >1.c <<\EOF
int foo() { return 1; }
int bar() { return 3; }
int main() { return foo(); }
EOF
cat >script.t <<\EOF
PROVIDE(unused = bar);
EOF
clang-15 -o 1.o 1.c -c -ffunction-sections
ld.lld -o 1.elf 1.o -T script.t --gc-sections --print-gc-sections -e main
```
The section `.text.bar` can be garbage-collected but remains uncollected.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsk11r6zgQhn_N-Gaw0YedjwtftE0MC4Uupbv3kjxxtCiSkeRu--8PdnLS5LSgSCA9M_NmPK9KyQ6eqIXmEZpdoaZ8DLEdVcwqhljo0H-2z887tAl9yDioqNVAaIJzZLL1AyqPk58S9Zg-Tzo4zEeVZz7SgSJ5Qz3qzxtsjOHd9nTBK2A7YA_n_ZXGGPrJWO0I6UOdRkcgH24RWLHz0iodL1dCguAguilFEJ22HkRH_h1vkGU3KiPIPa8MgnyaV_O0f-nOj9ZnPIQAYgNii7B-xEh5ih45yEeE9e4L0yp-x-Qd9gWf1KznT_pa6S7qKuZObzLRjrnKP4j--_Xl3792exCbS3NB7s7y5sQ_J3XKDyVvsAzIq_lnsDRYHg6TN9kGXyZaznTmXV85159pcoclpnzDq6iyHMw1BMtyjNbn-zs6N-H--91qejsSXnCEFasyfeRq_hsrhkZ51PR78srL5M1DNWWMNGdOOPnrfVX0rey3cqsKavmaM16vJWfFsRVyJcgotTr01NRabGu2XnOppDZMGM4K2womaiY5Z5um4azSXAjBm4bRVm_1oYaazQVd5dz7qQpxKGxKE7Wbei1Z4ZQmlxYrCeHpf1weQYjZWbGdY0o9DQlq5mzK6StLttktHtw_d9Ds8J87Q128p2m227c-FFN07THnMc1OER2IbrD5OOnKhBOIbi5yOcoxhv_IZBDdIi2B6BbpvwIAAP__s683Eg">