Error implementing custom system call in Ubuntu 20.04

Viewed 266

I mainly followed this tutorial but got an error.

Here's what I did:

cd linux-5.16.15

mkdir helloworld

cd helloworld

gedit helloworld.c

#include <linux/kernel.h>

asmlinkage long sys_helloworld(void){
    printk(“Hello World\n”);
    return 0;
}

gedit Makefile

obj-y := helloworld.o

cd ..

gedit Makefile

find second core-y and add

helloworld/ to that line

cd include/linux

gedit syscalls.h

in the end of the syscalls.h file before #endif add, asmlinkage long sys_helloworld(void);

cd ../..

cd arch/x86/entry/syscalls

gedit syscall_64.tbl

450 64 helloworld  sys_helloworld

When I ran the make command, I got this error:

ld: arch/x86/entry/syscall_64.o:(.rodata+0xe10): undefined reference to `__x64_sys_helloworld'
make: *** [Makefile:1161: vmlinux] Error 1

I tried changing the sys_helloworld to __x64_sys_helloworld in the syscalls.h file and the syscall_64.tbl file but that led to this error:

ld: arch/x86/entry/syscall_64.o:(.rodata+0xe10): undefined reference to `__x64___x64_sys_helloworld'
ld: arch/x86/entry/syscall_x32.o:(.rodata+0xe10): undefined reference to `__x64___x64_sys_helloworld'
make: *** [Makefile:1161: vmlinux] Error 1

What did I do wrong? Can someone please help me out?

Edit: I got that part. Just changed helloworld.c to this:

#include <linux/kernel.h>
#include <linux/syscalls.h>

//asmlinkage long sys_helloworld(void){
SYSCALL_DEFINE0(helloworld)
{

    printk("Hello world\n");
    return 0;
}

But now when I run make modules_install install I get this error:

arch/x86/Makefile:142: CONFIG_X86_X32 enabled but no binutils support
ln: target '/source' is not a directory
make[1]: *** [Makefile:1477: __modinst_pre] Error 1
make: *** [Makefile:350: __build_one_by_one] Error 2

What's wrong now? Please help.

0 Answers
Related