Skip to content
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

RISC-V relocation R_RISCV_HI20 out of range with CONFIG_CMODEL_MEDLOW=y #1533

Open
nathanchance opened this issue Dec 7, 2021 · 3 comments
Labels
[ARCH] risc-v This bug impacts ARCH=riscv [BUG] Untriaged Something isn't working [Reported-by] kbuild test robot Reported-by: kbuild test robot <lkp@intel.com>

Comments

@nathanchance
Copy link
Member

The kernel test robot reported a build failure in the stable tree with a randconfig.

Initially, I thought this was related to CONFIG_MMU, as defconfig + CONFIG_MMU=n reproduces a similar error (also reported in #1409):

$ make -skj"$(nproc)" ARCH=riscv LLVM=1 distclean defconfig

$ scripts/config -d MMU

$ make -skj"$(nproc)" ARCH=riscv LLVM=1 olddefconfig all
ld.lld: error: kernel/built-in.a(kallsyms.o):(function kallsyms_lookup_name: .text+0x42): relocation R_RISCV_PCREL_HI20 out of range: -524432 is not in [-524288, 524287]; references kallsyms_num_syms
>>> referenced by kallsyms.c
>>> defined in kernel/built-in.a(kallsyms.o)

ld.lld: error: kernel/built-in.a(kallsyms.o):(function kallsyms_lookup_name: .text+0x56): relocation R_RISCV_PCREL_HI20 out of range: -524432 is not in [-524288, 524287]; references kallsyms_names
>>> referenced by kallsyms.c
>>> defined in kernel/built-in.a(kallsyms.o)

ld.lld: error: kernel/built-in.a(kallsyms.o):(function kallsyms_lookup_name: .text+0x5e): relocation R_RISCV_PCREL_HI20 out of range: -524432 is not in [-524288, 524287]; references kallsyms_token_index
>>> referenced by kallsyms.c
>>> defined in kernel/built-in.a(kallsyms.o)

ld.lld: error: kernel/built-in.a(kallsyms.o):(function kallsyms_lookup_name: .text+0x66): relocation R_RISCV_PCREL_HI20 out of range: -524432 is not in [-524288, 524287]; references kallsyms_token_table
>>> referenced by kallsyms.c
>>> defined in kernel/built-in.a(kallsyms.o
...

However, that one goes away when CONFIG_KALLSYMS gets disabled. To reproduce this exact build failure on v5.16-rc4, I disabled CONFIG_KALLSYMS and CONFIG_MMU then switched CONFIG_CMODEL_MEDANY for CONFIG_CMODEL_MEDLOW:

$ make -skj"$(nproc)" ARCH=riscv LLVM=1 distclean defconfig

$ scripts/config -d CMODEL_MEDANY -e CMODEL_MEDLOW -d KALLSYMS -d MMU

$ make -skj"$(nproc)" ARCH=riscv LLVM=1 olddefconfig all
ld.lld: error: init/built-in.a(initramfs.o):(function wait_for_initramfs: .text+0x8): relocation R_RISCV_HI20 out of range: 526574 is not in [-524288, 524287]
>>> referenced by initramfs.c

ld.lld: error: init/built-in.a(initramfs.o):(function wait_for_initramfs: .text+0x14): relocation R_RISCV_HI20 out of range: 526366 is not in [-524288, 524287]
>>> referenced by initramfs.c

ld.lld: error: init/built-in.a(initramfs.o):(function wait_for_initramfs: .text+0x26): relocation R_RISCV_HI20 out of range: 526547 is not in [-524288, 524287]
>>> referenced by initramfs.c

ld.lld: error: init/built-in.a(main.o):(function do_one_initcall: .text+0x10): relocation R_RISCV_HI20 out of range: 526574 is not in [-524288, 524287]; references __stack_chk_guard
>>> referenced by main.c
>>> defined in arch/riscv/built-in.a(kernel/process.o)

ld.lld: error: init/built-in.a(main.o):(function do_one_initcall: .text+0x34): relocation R_RISCV_HI20 out of range: 526574 is not in [-524288, 524287]; references initcall_debug
>>> referenced by main.c
>>> defined in init/built-in.a(main.o)
...
@nathanchance nathanchance added [BUG] Untriaged Something isn't working [ARCH] risc-v This bug impacts ARCH=riscv [Reported-by] kbuild test robot Reported-by: kbuild test robot <lkp@intel.com> labels Dec 7, 2021
@nathanchance
Copy link
Member Author

Per Arnd's recommendation during our weekly meeting, I can reproduce these same errors with GCC 10.2.0 and binutils 2.35.2 from Debian:

$ make -skj"$(nproc)" ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- distclean defconfig

$ scripts/config -d CMODEL_MEDANY -e CMODEL_MEDLOW -d KALLSYMS -d MMU

$ make -skj"$(nproc)" ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- olddefconfig all
init/main.o: in function `do_one_initcall':
main.c:(.text+0x12): relocation truncated to fit: R_RISCV_HI20 against symbol `__stack_chk_guard' defined in .sbss section in arch/riscv/kernel/process.o
init/main.o: in function `set_reset_devices':
main.c:(.init.text+0x8): relocation truncated to fit: R_RISCV_HI20 against symbol `reset_devices' defined in .sbss section in init/main.o
init/main.o: in function `run_init_process':
main.c:(.text.unlikely+0x2c): relocation truncated to fit: R_RISCV_HI20 against `.LC9'
init/main.o: in function `rest_init':
main.c:(.ref.text+0x12): relocation truncated to fit: R_RISCV_HI20 against `kernel_init'
init/do_mounts.o: in function `name_to_dev_t':
do_mounts.c:(.text+0x82): relocation truncated to fit: R_RISCV_HI20 against symbol `__stack_chk_guard' defined in .sbss section in arch/riscv/kernel/process.o
init/do_mounts.o: in function `rootwait_setup':
do_mounts.c:(.init.text+0x50): relocation truncated to fit: R_RISCV_HI20 against `root_wait'
init/do_mounts.o: in function `.L40':
do_mounts.c:(.text.unlikely+0x1a): relocation truncated to fit: R_RISCV_HI20 against `.LC1'
init/do_mounts_initrd.o: in function `no_initrd':
do_mounts_initrd.c:(.init.text+0x8): relocation truncated to fit: R_RISCV_HI20 against `.LANCHOR0'
init/initramfs.o: in function `wait_for_initramfs':
initramfs.c:(.text+0x8): relocation truncated to fit: R_RISCV_HI20 against `initramfs_cookie'
init/initramfs.o: in function `error':
initramfs.c:(.init.text+0x4): relocation truncated to fit: R_RISCV_HI20 against `.LANCHOR0'
init/initramfs.o: in function `panic_show_mem':
initramfs.c:(.text.unlikely+0xa): additional relocation overflows omitted from the output

@emojifreak
Copy link

Linux 5.18 nommu_qemu_defconfig in riscv64 + KALLSYM_ALL causes this error in ld.llld-14 while gcc-11+binutils 2.38 do not cause this error. Specifically,

xzcat linux-5.18.tar.xz | tar xf -
cd linux-5.18
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- nommu_virt_defconfig
cat >>.config <<EOF
CONFIG_KALLSYMS=y
CONFIG_KALLSYMS_ALL=y
CONFIG_KALLSYMS_BASE_RELATIVE=y
EOF
make ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- V=1 W=0 >error.txt 2>&1 &
tail -f error.txt

The above script does not cause errors with

ryutaroh@bookworm-amd64:~/nommu/gcctest$ riscv64-linux-gnu-ld --version
GNU ld (GNU Binutils for Debian) 2.38
Copyright (C) 2022 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.
ryutaroh@bookworm-amd64:~/nommu/gcctest$ riscv64-linux-gnu-gcc --version
riscv64-linux-gnu-gcc (Debian 11.2.0-9) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

But clang 14.0.4 + lld 14.0.4 on Debian unstable cause this runtime error as

ld.lld: error: kernel/built-in.a(kallsyms.o):(function update_iter: .text+0x94e): relocation R_RISCV_PCREL_HI20 out of range: -524390 is not in [-524288, 524287]; references kallsyms_relative_base
>>> referenced by kallsyms.c
>>> defined in kernel/built-in.a(kallsyms.o)

ld.lld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors)

A reproducing script is below:

xzcat linux-5.18.tar.xz | tar xf -
cd linux-5.18
make LLVM=1 LLVM_IAS=1 ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- nommu_virt_defconfig
cat >>.config <<EOF
CONFIG_KALLSYMS=y
CONFIG_KALLSYMS_ALL=y
CONFIG_KALLSYMS_BASE_RELATIVE=y
EOF
make LLVM=1 LLVM_IAS=1 ARCH=riscv CROSS_COMPILE=riscv64-linux-gnu- V=1 W=0 >error.txt 2>&1 &
tail -f error.txt

@nickdesaulniers
Copy link
Member

Just grepping for R_RISCV_HI20 on lore, it looks like there's been lots of reports of this one.
https://lore.kernel.org/llvm/?q=R_RISCV_HI20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[ARCH] risc-v This bug impacts ARCH=riscv [BUG] Untriaged Something isn't working [Reported-by] kbuild test robot Reported-by: kbuild test robot <lkp@intel.com>
Projects
None yet
Development

No branches or pull requests

3 participants