<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/62690>62690</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
getELFSectionType should have more checks for SHT_NOBITS
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
PiJoules
</td>
</tr>
</table>
<pre>
At the moment, `getELFSectionType` will only deem a section as `SHT_NOBITS` if it has determined earlier it was in a `.bss` section, but some sections can still contain all zeros and be candidates for `nobits`. Take for example:
```
__attribute__((section(".abc")))
char arr[1024];
```
which will emit:
```
.section .abc,"aw",@progbits
.globl arr
.p2align 4
arr:
.zero 1024
.size arr, 1024
```
A custom named section will only be named with `nobits` if it starts with `.bss`. We should also consider making it `nobits` if the contents of this section are all zeros similar to [isSuitableForBSS](https://github.com/llvm/llvm-project/blob/19c5740a5a3a57454416ccade7640cb4ac6db43d/llvm/lib/Target/TargetLoweringObjectFile.cpp#LL81C13-L81C29). This can be checked easily via the GlobalObject which is available in all callers of `getELFSectionType`.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVF1v6zYM_TXKC3ENWf5I8uCHJl32gWJ3QALsMaBsxuYqW4EkN-v99YMcJ23vugE3MOxIJA8Oj46I3nM7EFWi2IjicYFj6Kyr_uDf7GjIL7RtXquHAKEj6G1PQxBqC6KULYWfnnZ7qgPb4fB6JlFKuLAxYAfzCg1RDwj-Ggf0sWb_y-H4-9fNr4d9TOYTcIAOPTQUyPU8UAOEzjC5GLmgBx4AY2WivY81M17koMcA3vZ02_NQ4wA-RAq1HQLGWmPgGznrAYcGNMWUhhsM5OFkXUQerOYQsRM44DNN2_Q39mdDInsQ8lHI27uU8zMtj0cMwbEeAx2PQq2EWt3ZrYRSCepaKCXUen6mqrpDB-icKDapVLkoHkW2-RT_-r50XHdXXann8P-UYP4lN9mvHLZCKbxMXLYil2dn26nnjzWtsdrAxO1j4KzQcDtAft2PCTcW95woMgBMLX1Hhb8RXGHV9l3Cp90-QD36YHsYsKfm7p43W2maQxcO3Yfjm-3kA7rg7-HZNwn8SeA7O5oG0HgbDeK5IQc9PvPQxsrvwaLjo49oCB5sXLN_87Ojd-by3LNBB8GCKDbs9yMH1IZ21m32-3jGatWFcPZROLUTatdy6Ead1LYXamfMy-3z5ezsX1QHoXbaWC3ULl3XxTKXWGCGxTIv8jwt6xobWpa5rHWOddnoPGve4XCsO6BrKdz_PNkLOR7arzrC79hQUp_PQmVPT6t0m2Zf4mfyaQKH2Gm8TPHCdFQ_T_fSs3mFF8ZJmJ-N1WiuYHD1KHvAF2QTG4f57tVoDLlJvv8YGcmiqbJmna1xQVVarrJ1pgqZLrpK4qo5oSqXp7zJtS7SYoWaMq2wxrVcrxdcKakyWaRKZTLN00RRmcpTrspMZUu5KkQuqUc2SRQmsa5dsPcjVaUq13JhUJPxt7nnqkl-PbZe5NKwD_6tLHAwVP2L_s1RHb7E4ehmta6j5W3WLUZnqh8-_omqF2o3sf0nAAD__xxVwFc">