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

    <tr>
        <th>Summary</th>
        <td>
            lld gets "relocation R_HEX_B22_PCREL out of range"
        </td>
    </tr>

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

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

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

<pre>
    When building zig test cases for `hexagon` with `lld`, we encounter range limitations in the relocations, see below for errors.  The limited range of these relocations is expected behavior, but for users making large programs it's undesirable.  `lld` can make extensions using thunks/trampolines, but those aren't yet supported.

Note also that #116798 improved `lld` by correcting the range calculation - it was previously too small.  But that fix alone is not effective for very large programs.

Thanks @alexrp for the bug report.

```
error: ld.lld: /home/alexrp/Source/ziglang/zig/.zig-cache/o/ef6d73811ed43e51b7ff5085bd10310c/test.o:(function os.linux.test.test.user and group ids: .text+0x138d57c): relocation R_HEX_B22_PCREL out of range: -11927916 is not in [-8388608, 8388607]; references 'getauxval'
    note: referenced by test.zig:107 (/home/alexrp/Source/ziglang/zig/lib/std/os/linux/test.zig:107)
    note: defined in /home/alexrp/Source/ziglang/zig/.zig-cache/o/ef6d73811ed43e51b7ff5085bd10310c/test.o
error: ld.lld: /home/alexrp/Source/ziglang/zig/.zig-cache/o/ef6d73811ed43e51b7ff5085bd10310c/test.o:(function os.linux.test.test.user and group ids: .text+0x138d5ec): relocation R_HEX_B22_PCREL out of range: -11928028 is not in [-8388608, 8388607]; references 'getauxval'
    note: referenced by test.zig:108 (/home/alexrp/Source/ziglang/zig/lib/std/os/linux/test.zig:108)
    note: defined in /home/alexrp/Source/ziglang/zig/.zig-cache/o/ef6d73811ed43e51b7ff5085bd10310c/test.o
error: ld.lld: /home/alexrp/Source/ziglang/zig/.zig-cache/o/ef6d73811ed43e51b7ff5085bd10310c/test.o:(function os.linux.test.test.user and group ids: .text+0x138d65c): relocation R_HEX_B22_PCREL out of range: -11928140 is not in [-8388608, 8388607]; references 'getauxval'
    note: referenced by test.zig:109 (/home/alexrp/Source/ziglang/zig/lib/std/os/linux/test.zig:109)
    note: defined in /home/alexrp/Source/ziglang/zig/.zig-cache/o/ef6d73811ed43e51b7ff5085bd10310c/test.o
error: ld.lld: /home/alexrp/Source/ziglang/zig/.zig-cache/o/ef6d73811ed43e51b7ff5085bd10310c/test.o:(function os.linux.test.test.user and group ids: .text+0x138d6cc): relocation R_HEX_B22_PCREL out of range: -11928252 is not in [-8388608, 8388607]; references 'getauxval'
    note: referenced by test.zig:110 (/home/alexrp/Source/ziglang/zig/lib/std/os/linux/test.zig:110)
    note: defined in /home/alexrp/Source/ziglang/zig/.zig-cache/o/ef6d73811ed43e51b7ff5085bd10310c/test.o
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsl0-P2zYQxT8NfRlYoEbWv4MOdhIjh6Io0gDtLaDEkcQuTQr84_Xm0xeUvbtNT-0iu2iBAIYljMjHeW9-B0l4ryZD1LHywBCFkc6eCikYIivfb0QMs3XdU3nTW_nQ_TaTgT4qLZWZ4KuaIJAPMAhPHkbrgFV8pouYrGEVh3sV5lTSWrKKM3wH9wRkBhtNIAdOmIlAq5MKIihrPCgDYSZwpO1wLaVNngh60vZ-PYKcs85nAJ_n22aSNyk7pu3-GwFQHuiy0JCW9TSLs7IuqfYxrHrRk_NwEnfJkhZuIlicnZw4eVCBYe0hGkleOdFryuDZEAzCpI0EdAlk_Hpc9EknzNHceYbH4MRpsVoZ8o-Hhtl6AuHIMKwDPFAAH5fFukAyY3zP-P5nGwiE9hbCLAIwLPK8qtsG1Glx9kzyL030DzBY52gI14PpFsYg9BD1GgJsQQW4Fx4WR2dlo9cPEKwFfxJaZwCHtS0RYFQXENoaSrEZG4DGMSmfac3qTO7hbxndOv48C3Pnge240HRxy7o8NdPHCRwld7eViYTrj-_XWbJiD1pmy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