https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111323
Bug ID: 111323
Summary: [RISC_V] During Insmod "unknown relocation type 57"
type in kernel space observed
Product: gcc
Version: 13.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: libstdc++
Assignee: unassigned at gcc dot gnu.org
Reporter: akhilesh.k at samsung dot com
Target Milestone: ---
Hello
with gcc 13.1 open source RISC-V Toolchain I observed "unknown relocation type
57" error message during insmod my kernel modules it seems this issue could
occurs in RISC-V when we try to assemble or link a program, and the toolchain
encounters a relocation type that it doesn't recognize or support.
as per latest kernel 6.1 (which i am using code) doesn't support RELOC_NUMBER
(R_RISCV_32_PCREL, 57) .
Here is my sample driver makefile
=============================================================
CFLAGSÂ +=-std=gnu11 #with this option getting "unknown relocation type 57"
obj-m := hello.o
hello-y := hello.o
all:
make -C ${KDIR} M=$(PWD) modules
clean:
make -C ${KDIR} M=$(PWD) clean
====================================================================
My dummy drive hello.c
====================================================================
#include <linux/module.h>
#include <linux/kernel.h>
int init_module(void) { printk(KERN_INFO "Hello
world.\n"); return 0; }
void cleanup_module(void) { printk(KERN_INFO "Goodbye
world.\n"); }
MODULE_LICENSE("GPL");
======================================================================
Using -std=gnu11 with gcc 13 generates R_RISCV_SET6 relocation in eh_frame
section which is not generated without -std=gnu11 flag even with same compiler
optimisations:
My insmod logs
=========================================================
/bin # insmod hello.ko
[ 11.807337] hello: loading out-of-tree module taints kernel.
[ 11.809680] hello: Unknown relocation type 57
insmod: can't insert 'hello.ko': invalid parameter
=========================================================
readelf output with -std=gnu11
Relocation section '.rela.eh_frame' at offset 0xb08 contains 10 entries:
Offset Info Type Sym. Value Sym. Name +
Addend
00000000001c 001e00000039 R_RISCV_32_PCREL 0000000000000000 .L0 + 0
000000000020 001f00000023 R_RISCV_ADD32 0000000000000022 .L0 + 0
000000000020 001e00000027 R_RISCV_SUB32 0000000000000000 .L0 + 0
000000000031 002000000035 R_RISCV_SET6 000000000000001a .L0 + 0
000000000031 002100000034 R_RISCV_SUB6 0000000000000008 .L0 + 0
000000000044 002200000039 R_RISCV_32_PCREL 0000000000000022 .L0 + 0
000000000048 002300000023 R_RISCV_ADD32 0000000000000042 .L0 + 0
000000000048 002200000027 R_RISCV_SUB32 0000000000000022 .L0 + 0
000000000059 002400000035 R_RISCV_SET6 000000000000003c .L0 + 0
000000000059 002500000034 R_RISCV_SUB6 000000000000002a .L0 + 0
readelf output without -std=gnu11
Relocation section '.rela.text.unlikely' at offset 0x920 contains 6 entries:
Offset Info Type Sym. Value Sym. Name +
Addend
000000000008 001900000017 R_RISCV_PCREL_HI2 0000000000000000 .LC0 + 0
00000000000c 001a00000018 R_RISCV_PCREL_LO1 0000000000000008 .L0 + 0
000000000010 002000000013 R_RISCV_CALL_PLT 0000000000000000 _printk + 0
00000000002a 001b00000017 R_RISCV_PCREL_HI2 0000000000000010 .LC1 + 0
00000000002e 001c00000018 R_RISCV_PCREL_LO1 000000000000002a .L0 + 0
000000000032 002000000013 R_RISCV_CALL_PLT 0000000000000000 _printk +
As a workaround i have two options either remove -std=gnu11 and use default
standards (-std=gnu17) or use KBUILD_CFLAGS += -fno-asynchronous-unwind-tables
-fno-unwind-tables option
but my query is why such relocations are generated with -std=gnu11