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

    <tr>
        <th>Summary</th>
        <td>
            LLD [feature request] Automatic splitting of input sections
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    I work in embedded and there is a feature that I have wanted out of lld for the better part of a decade. Doing some research suggests this feature has been missing decades longer than that.

The ask would be to better support fragmented memory maps of embedded devices by not forcing the user to manually create and place sections due to the fragmentation. Instead, it would be infinitely helpful if the linker could support automatic splitting of input sections. Many commercial embedded compiler vendors support this feature in their linkers. However, in my case, we want / need to move to open source tooling due to cost.

Two fairly common scenarios in embedded
1. The silicon vendor (for whatever reason) decides not to make its internal memory block contiguous. In recent years, vendors have been getting a lot better so its not as big of an issue anymore as it was 5 - 10 years ago. There are also legitimate reasons to make memory blocks non contiguous within a chip, but this request isn't really targeting those scenarios.
2. More often than not, there is a silicon bug / errata with regards to (usually) the beginning or ending of a memory block which essentially causes a 'hole' in that memory block that cannot be used. If there are 2 contiguous memory blocks, we can define it in the linker script as a single block. Great. However, a silicon bug has caused 4 bytes at an offset of 0x2000 within the block to be unusable. Now we have to try and move a bunch of code around with tons of nasty pragmas and manual section management.

What we really need is the ability to spread or split an input section among several memory blocks. This single linker feature has prevented me and my teams from using open source tools for a very long time. It's really that important. With a few developers, manual section management may be a huge pain but can be managed. When that team grows in size to 4 - 10 developers, it becomes a nightmare, because everybody is working on their own code files which end up generating different code output sizes.

The closest example for gnu linker script syntax that I can provide an example for is from TI. Their linker scripts allow to specify multiple memory output sections ORed together. The linker then automatically spreads the section among several memory blocks. 

.text
{
    *(.text)
} >> MEM1 | MEM2 | MEM3


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMV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