'kernel make error "arch/x86/entry/syscall_64.o:(.rodata+0x1120): undefined reference to"

This error stops my kernel make process

ld: arch/x86/entry/syscall_64.o:(.rodata+0x1120): undefined reference to `__x64_sys_fd'
  BTF   .btf.vmlinux.bin.o
pahole: .tmp_vmlinux.btf: No such file or directory
  LD    .tmp_vmlinux.kallsyms1
.btf.vmlinux.bin.o: file not recognized: file format not recognized

Here are the files i modified in the linux kernel source code

fd.c

#include <linux/kernel.h>
#include <linux/syscalls.h>
#include <linux/fdtable.h>
#include <linux/pid.h>
#include <linux/sched/signal.h>
#include <linux/fs.h>

SYSCALL_DEFINE4(fd, pid_t, pid_input, struct fdtable*, fd, struct files_struct*, files, struct file*, f)
{
    struct pid* result_pid;
    struct task_struct* rt;
    result_pid = find_get_pid(pid_input);
    rt = get_pid_task(result_pid, PIDTYPE_PID);
    files = rt->files;
    *fd = files->fdtab;
    f = files->fd_array[0];
    printk(KERN_INFO "--------------------fd---------------------\n");
    printk(KERN_INFO " Maximum number of current file objects: [%d]", fd->max_fds);
    printk(KERN_INFO " Point to the file descriptor that needs to be closed when executing exec( )[%ld]", *(fd->close_on_exec));
    printk(KERN_INFO " Pointer to open file descriptor: [%ld]", *(fd->open_fds));
    printk(KERN_INFO " Next allocated file descriptor:[%d]", files->next_fd);
    printk(KERN_INFO "--------------------fdinfo-----------------\n");
    printk(KERN_INFO " The flag specified when opening the file: [%d]",f->f_flags);
    printk(KERN_INFO " The cursor postion value: [%lld]",f->f_pos);
    return 0;
}

Makefile in fd dir

obj-y := fd.o

Makefile in linux dir

core-y       += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/ fd/

arch/x86/entry/syscalls/

335    64    fd          sys_fd

include/linux/

asmlinkage long sys_fd(pid_t pid_input, struct fdtable* fd, struct files_struct* files, struct file* f);


Solution 1:[1]

perphas , in the file :

arch/x86/entry/syscalls/syscall_64.tbl

you should use write something like this :

335    64    fd          __x64_sys_fd

instead of us sys_fd .
since linux4.17 add a new system call must start with __x64_sys_ in the syscall_64.tbl file.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Oasis