<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/56842>56842</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            lld/ELF: garbage collect C-identifier sections
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            lld:ELF
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          rui314
      </td>
    </tr>
</table>

<pre>
    GNU ld and LLVM lld don't garbage-collect a section if the section name is valid as a C identifier (e.g. it doesn't start with a `.` and doesn't contain punctuators.) This is because the linkers synthesize two symbols `__start_foo` and `__stop_foo` for a section whose name is _foo_, and there is a chance that section _foo_ may be referenced indirectly via the synthesized symbols.

But I think that the behavior is too conservative and misses an optimization opportunity. If input object files do not contain `__start_foo` or `__stop_foo` at all as an undefined symbol, we should be able to safely discard section _foo_.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxlkk1vnDAQhn8NXEZBYGCze-CQj6aKlPbU9roaYwPTGhvZZlebX9-BzW4SRTLgMfPxzOuRTp2a7z9_g1GAVsHLy58fYNhQzibiNkKPXmKvb1pnjG4jIAT-kLNAHcRBX02LowYKcEBDnCuw5wOQ0jZSR9pDIrY66zOgyLl1OGcPEX2EI8WB3ZNNnvGzcry7tM5GJAvTbNs4Y3Q-ZInYwa-Bi_GSusU56JXFkP2nfYBwsmwGeuXjo2NzlM6EpcB-v5bcd85dSr2duuly2Dn_oc3j4Dj7pbvFZ5-IhzWSa_j1FKEd0LYLBMZr5OoLI56YEbzu2Jl9FJBV5NnHnOBAeBbxCqwutFmSPyb53fl9P0d4Zk_u71xjCZJ6wAMxLBNE5xalgvYHjHTQK99IIWims-CmSCO94srlpsn5OFuKpwyeO-aZOL2Tf5f77chwiHJg3bv2X4Xjql90Yyw0Zr16C7NVuiN77WfR7MiNDm7m6WJBUBrWiy8HO81KKAotevVZvCzVTbGpd6UQVS1S1ZRqV-4wjRSNbnhME_H07eUpKe8ucwqXOX24-TB7b0lDOnvTDDFOgUM4llfPszfLrHUjG8YcLp-bybtFEDZZxVkH3tSbbSXSoVGdLMS2UqWqbnlbaVlupSzwtlJ53pY6NSi1CU1S3ydCLJjl3YIpRFI_ptSIXIh8mxe5qKuiyGSr27arMd9sy1Ls6qTK9YhksoUjc75PfbMiybkP_NNQiOH9J4ZAvdV6Lcf5cY6D842fqSyqdIVvVvL_b4FVZg">