Skip to content

"R_RISCV_HI20 out of range" with clang-21+ after -next commit ee10b1028129 #2179

Description

@nathanchance

After commit ee10b1028129 ("riscv/runtime-const: Replace open-coded placeholder with RUNTIME_MAGIC"), I am seeing the following build error when building with LLVM 21 and newer:

$ make -skj"$(nproc)" ARCH=riscv LLVM=1 mrproper defconfig all
ld.lld: error: vmlinux.a(kernel/futex/core.o):(function futex_init: .init.text+0x3e0): relocation R_RISCV_HI20 out of range: 563901 is not in [-524288, 524287]; references ''
>>> referenced by core.c
>>> defined in vmlinux.a(kernel/futex/core.o)

ld.lld: error: vmlinux.a(kernel/futex/core.o):(function futex_init: .init.text+0x3e4): relocation R_RISCV_HI20 out of range: 563901 is not in [-524288, 524287]; references ''
>>> referenced by core.c
>>> defined in vmlinux.a(kernel/futex/core.o)

ld.lld: error: vmlinux.a(kernel/futex/core.o):(function __futex_hash: .text+0x4a4): relocation R_RISCV_HI20 out of range: 563901 is not in [-524288, 524287]; references ''
>>> referenced by core.c
>>> defined in vmlinux.a(kernel/futex/core.o)

ld.lld: error: vmlinux.a(kernel/futex/core.o):(function __futex_hash: .text+0x4a8): relocation R_RISCV_HI20 out of range: 563901 is not in [-524288, 524287]; references ''
>>> referenced by core.c
>>> defined in vmlinux.a(kernel/futex/core.o)

ld.lld: error: vmlinux.a(fs/file_table.o):(function alloc_empty_file: .text+0x9a): relocation R_RISCV_HI20 out of range: 563901 is not in [-524288, 524287]; references ''
>>> referenced by file_table.c
>>> defined in vmlinux.a(fs/file_table.o)

ld.lld: error: vmlinux.a(fs/file_table.o):(function alloc_empty_file: .text+0x9e): relocation R_RISCV_HI20 out of range: 563901 is not in [-524288, 524287]; references ''
>>> referenced by file_table.c
>>> defined in vmlinux.a(fs/file_table.o)

ld.lld: error: vmlinux.a(fs/file_table.o):(function alloc_empty_file_noaccount: .text+0x256): relocation R_RISCV_HI20 out of range: 563901 is not in [-524288, 524287]; references ''
>>> referenced by file_table.c
>>> defined in vmlinux.a(fs/file_table.o)

ld.lld: error: vmlinux.a(fs/file_table.o):(function alloc_empty_file_noaccount: .text+0x25a): relocation R_RISCV_HI20 out of range: 563901 is not in [-524288, 524287]; references ''
>>> referenced by file_table.c
>>> defined in vmlinux.a(fs/file_table.o)

ld.lld: error: vmlinux.a(fs/file_table.o):(function alloc_empty_backing_file: .text+0x2d6): relocation R_RISCV_HI20 out of range: 563901 is not in [-524288, 524287]; references ''
>>> referenced by file_table.c
>>> defined in vmlinux.a(fs/file_table.o)

ld.lld: error: vmlinux.a(fs/file_table.o):(function alloc_empty_backing_file: .text+0x2da): relocation R_RISCV_HI20 out of range: 563901 is not in [-524288, 524287]; references ''
>>> referenced by file_table.c
>>> defined in vmlinux.a(fs/file_table.o)

ld.lld: error: vmlinux.a(fs/file_table.o):(function alloc_file_pseudo_noaccount: .text+0x514): relocation R_RISCV_HI20 out of range: 563901 is not in [-524288, 524287]; references ''
>>> referenced by file_table.c
>>> defined in vmlinux.a(fs/file_table.o)

ld.lld: error: vmlinux.a(fs/file_table.o):(function alloc_file_pseudo_noaccount: .text+0x518): relocation R_RISCV_HI20 out of range: 563901 is not in [-524288, 524287]; references ''
>>> referenced by file_table.c
>>> defined in vmlinux.a(fs/file_table.o)

ld.lld: error: vmlinux.a(fs/file_table.o):(function __fput: .text+0xa6c): relocation R_RISCV_HI20 out of range: 563901 is not in [-524288, 524287]; references ''
>>> referenced by file_table.c
>>> defined in vmlinux.a(fs/file_table.o)

ld.lld: error: vmlinux.a(fs/file_table.o):(function __fput: .text+0xa70): relocation R_RISCV_HI20 out of range: 563901 is not in [-524288, 524287]; references ''
>>> referenced by file_table.c
>>> defined in vmlinux.a(fs/file_table.o)

ld.lld: error: vmlinux.a(fs/file_table.o):(function file_free: .text+0xe62): relocation R_RISCV_HI20 out of range: 563901 is not in [-524288, 524287]; references ''
>>> referenced by file_table.c
>>> defined in vmlinux.a(fs/file_table.o)

ld.lld: error: vmlinux.a(fs/file_table.o):(function file_free: .text+0xe66): relocation R_RISCV_HI20 out of range: 563901 is not in [-524288, 524287]; references ''
>>> referenced by file_table.c
>>> defined in vmlinux.a(fs/file_table.o)

ld.lld: error: vmlinux.a(fs/file_table.o):(function backing_file_free: .text+0xece): relocation R_RISCV_HI20 out of range: 563901 is not in [-524288, 524287]; references ''
>>> referenced by file_table.c
>>> defined in vmlinux.a(fs/file_table.o)

ld.lld: error: vmlinux.a(fs/file_table.o):(function backing_file_free: .text+0xed2): relocation R_RISCV_HI20 out of range: 563901 is not in [-524288, 524287]; references ''
>>> referenced by file_table.c
>>> defined in vmlinux.a(fs/file_table.o)

ld.lld: error: vmlinux.a(fs/namei.o):(function do_getname: .text+0x30): relocation R_RISCV_HI20 out of range: 563901 is not in [-524288, 524287]; references ''
>>> referenced by namei.c
>>> defined in vmlinux.a(fs/namei.o)

ld.lld: error: vmlinux.a(fs/namei.o):(function do_getname: .text+0x34): relocation R_RISCV_HI20 out of range: 563901 is not in [-524288, 524287]; references ''
>>> referenced by namei.c
>>> defined in vmlinux.a(fs/namei.o)
...

If I build with the GNU assembler using CROSS_COMPILE=riscv64-linux-gnu- LLVM_IAS=0, there is no error.

I bisected to LLVM commit b9b39db5d767 ("RISCVAsmParser: Don't treat operands with relocation specifier as parse-time constants", 2025-03-29) as the source of the changed behavior between LLVM versions, which certainly seems likely (cc @MaskRay).

I guess this error is legitimate given the relocation constraints? It kind of sucks that there is a divergence between the LLVM and GNU assemblers here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    [ARCH] risc-vThis bug impacts ARCH=riscv[BUG] linux-nextThis is an issue only seen in linux-next[TOOL] integrated-asThe issue is relevant to LLVM integrated assembler

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions