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

    <tr>
        <th>Summary</th>
        <td>
            [lld] Large sections are sorted incorrectly for no-pic links
        </td>
    </tr>

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

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

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

<pre>
    With https://reviews.llvm.org/D150510, we place large sections farther from text to mitigate relocation overflows to small sections. However, "farther from text" is only correct for PIC builds that use relative relocations. Non-PIC builds use absolute relocations and typically assume that small sections are in the lower 2GB of the address space. Currently we place `.lrodata` at the very beginning of the binary, but for non-PIC builds it should go at the end.

To prevent extra segments, should we also place `.rodata` toward the end so it still shares a segment with `.lrodata`? But non-PIC binaries can still have PC-relative relocations, so keeping `.rodata` before `.text` is still useful for mitigating that type of relocation pressure?

@MaskRay 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsVFGPszYQ_DXmZRVkTCDhgYfv7pS2Ult9qir1eYEF3HNs5LWTj39fmeTuEvV7SSQ0np0dzxiZ9WSJWlG9iOotwxhm51uk2KF956xzw9r-o8MMcwgLi_KbUCehTp4umq6cG3M5585PQp3eikpWhRTqFa4Ei8GewKCfCJj6oJ1lGNGHmTyM3p0h0I8AwcFZBz1hIPBkXI8JCe5CfjTuygnAZzTmkySHX92VLuTTIKHU_ziFUqAZnDUr9M576gOMzsP3316hi9oMDGHGAJG3kRj05XE25_Cns7sHdAJix87EJ5EMaAcI66J7NGYFZI5nunE_Swb0BNpCmAmMu5IH9csLuHH7gMPgiRl4wZ5yeI3ekw1m_TJR1DI33g0YUNQSMGznLuRX6GjS1mo7fbB12qJfkzVdvK1tn5fRAXh20QwwuQ8qskMu5JuQ326_fztYPF3IBqAfwSMwTWeygRPv_fSVAA27B4lfCoO7oh8-qIHdNjXoZMmMnhg-KeGasvW8oShP8BLDl_K0kyaGHu2dZsYLwffX3c_ubxPp4J1oScY8S-todP6md8tKLVNWbqSRaYxmM-2eyXR-u8-wLpQsfojokm4tehLl6dE7sZd_IL__hStkQ1sOTdlgRm1xkFVV7mVRZ3N7PMqxafqqaSRVSGUzHqr9cRyrpmgKrPaZbpVUe1kUB1Wquqrzpir7cpD1oZF1LdVR7CWdUZvP_mWaOVJ7OFaqyAx2ZHirtFLGDEKp1G3fJvSuixOLvTSaw1d_s6CD2V6BhK_e4Pfn5qYEs_OBBtD23iqz3gO2W3QPRqf3InrTPr8Ukw5z7PLenYU6pXH3v93i3b_UB6FOm3YW6rTJ_y8AAP__wvuN0Q">