Skip to content

lld incorrectly calculates the maximum range of R_HEX_B22_PCREL relocation #116798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
androm3da opened this issue Nov 19, 2024 · 10 comments
Closed

Comments

@androm3da
Copy link
Member

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

@llvmbot
Copy link
Member

llvmbot commented Nov 19, 2024

@llvm/issue-subscribers-lld-elf

Author: Brian Cain (androm3da)

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

@llvmbot
Copy link
Member

llvmbot commented Nov 19, 2024

@llvm/issue-subscribers-backend-hexagon

Author: Brian Cain (androm3da)

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

@androm3da
Copy link
Member Author

This is fixed by #115925 - so we can cherry-pick it once it lands.

@androm3da
Copy link
Member Author

/cherry-pick 64e3466

@llvmbot
Copy link
Member

llvmbot commented Nov 19, 2024

Failed to cherry-pick: 64e3466

https://github.com/llvm/llvm-project/actions/runs/11916300231

Please manually backport the fix and push it to your github fork. Once this is done, please create a pull request

@alexrp
Copy link
Member

alexrp commented Nov 24, 2024

@androm3da does this look like the same issue?

...snip...
error: ld.lld: /home/alexrp/Source/ziglang/zig/.zig-cache/o/ac233994cecab126ab11a1a886c69fbb/test.o:(function debug.panicExtra__anon_2192: .text+0x1c7c): relocation R_HEX_B22_PCREL out of range: 2107140 is not in [-2097152, 2097151]; references 'memset'
    note: referenced by debug.zig:440 (/home/alexrp/Source/ziglang/zig/lib/std/debug.zig:440)
    note: defined in /home/alexrp/.cache/zig/o/019c1e69a1297cefadacb81f30c8d941/libcompiler_rt.a(/home/alexrp/.cache/zig/o/019c1e69a1297cefadacb81f30c8d941/libcompiler_rt.a.o)
...snip...
error: ld.lld: /home/alexrp/Source/ziglang/zig/.zig-cache/o/ac233994cecab126ab11a1a886c69fbb/test.o:(function fifo.LinearFifo(u8,.{ .Dynamic = {} }).realign: .text+0x4288): relocation R_HEX_B22_PCREL out of range: 2097208 is not in [-2097152, 2097151]; references 'memcpy'
    note: referenced by fifo.zig:99 (/home/alexrp/Source/ziglang/zig/lib/std/fifo.zig:99)
    note: defined in /home/alexrp/.cache/zig/o/019c1e69a1297cefadacb81f30c8d941/libcompiler_rt.a(/home/alexrp/.cache/zig/o/019c1e69a1297cefadacb81f30c8d941/libcompiler_rt.a.o)
...snip...

I get a bunch of relocation errors of this sort when linking Zig's compiler-rt tests.

@androm3da
Copy link
Member Author

androm3da commented Nov 24, 2024

@androm3da does this look like the same issue?

Yes it does. Note that even after this is fixed there's a (small) chance for relocations to be too far apart (if the call site is not extended and the executable is fairly large). But: #111217 should address that when it lands.

@tru tru moved this from Needs Triage to Done in LLVM Release Status Nov 25, 2024
@androm3da
Copy link
Member Author

This has been fixed in release/19.x and main branches.

@alexrp
Copy link
Member

alexrp commented Apr 7, 2025

@androm3da building Zig's std tests (fairly large binary at 69M), we now get lots of:

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

I'm wondering if we might be hitting this bug again, or if we're just running into an actual toolchain limitation here.

@androm3da
Copy link
Member Author

@androm3da building Zig's std tests (fairly large binary at 69M), we now get lots of:
...
I'm wondering if we might be hitting this bug again, or if we're just running into an actual toolchain limitation here.

It's the latter. I have not gotten around to finishing the remaining work for #111217, sadly. Hopefully we can resurrect that one and polish off the remaining work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

4 participants