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

    <tr>
        <th>Summary</th>
        <td>
            lld incorrectly calculates the maximum range of R_HEX_B22_PCREL relocation
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            backend:Hexagon,
            lld:ELF
      </td>
    </tr>

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

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

<pre>
    When building the linux kernel, we see the following link error:

```
ld.lld: error: vmlinux.a(arch/hexagon/kernel/head.o):(.init.text+0x160):
relocation R_HEX_B22_PCREL out of range: 2098032 is not in [-2097152, 2097151]; references 'memset'
```

This issue was triggered by changes in layout but it uncovered an error in the way lld calculates the range of this relocation.

See also https://lore.kernel.org/linux-hexagon/20241114171834.GA1956005@thelio-3990X
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsk01vnDAQhn-NuViL7DGfBw7ZJDSHHKq0UnOLDMyCG2NHttmPf1-Z3c22USVkYDz4nfeZQXqvRoPYkHxLAKQZnJ3FIAkAyR8SuYTJuuYznHR2ODW_JjS0W5QelBlpmJBqZZYjfUdnUBO4pwekHnHd2lmt7SEmamXeKTpnHRF3hD0Qdl0LdrnWVz2kWg9E3H0m0_28KqSSQCVdPxFoJzzK0RoC7VW2nVAOqSVQx_OhSpVRIQ14DAS27MgLdtlaVRxq28ugrKEvb0-Pr29bgLfv9y-Pz9QugdodddKMGNWB1RUTQJWnxgaqDCX5dgOsLnkO0e75kZP8gYgtdbhDh6ZHTwmUM84eA4Hyv17P689Jeaq8X5AepKfBqXFEhwPtTrSfYhk-qmp5iqV1S6Aq0MX0dr9mSXMmFXMi8oM8Ua0H2kvdL1oG9Gt49RONhSh385_-XcoPRCq1t3QK4cOvIFsCrbYO0zPo1LoxRmJDNrcuAIOMc57xklciS7_d8TovGMtJxsKEWtmNqGv2mgyNGGpRywQbXgpgIDKeJVPDcl7s6qFkRQeCyzKvCha_r3MuMhSYqOYiUXMhihzSCL2oamA17nDHOMkYzlLpVOv9HKtMVqQN50VZV4mWHWp_GfRO9u9o4pA9XR3EThKA8-g9PreXX8A18bhNt4yeZEwrH_xNIKigsYmslemtc9gHffrKfZZHNS_zjf_Xebu1Ilmcbv4lP6owLV3a2zlC1_vrbfPh7G_sA4F2tekJtBen-wb-BAAA___0rjI9">