Imran Khan
Imran Khan

Reputation: 31

Error while implementing hello world system call in Lunix

I am compiling my kernel for my hello world system call but getting following error:

ld: arch/x86/entry/syscall_64.o:(.rodata+0xdc0): undefined reference to __x64_sys_hello' ld: arch/x86/entry/syscall_x32.o:(.rodata+0xdc0): undefined reference to __x64_sys_hello' make: *** [Makefile:1139: vmlinux] Error 1 site:stackoverflow.com

Following are the changes i made to add my hello world system call:

Current kernel version=5.11.0.40

linux-5.8.1/hello/hello.c:

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

asmlinkage long sys_hello(void)
{
        printk("Hello world\n");
        return 0;
}

linux-5.8.1/Makefile:

ifeq ($(KBUILD_EXTMOD),)
core-y        += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/ hello/

linux-5.8.1/include/linux$ gedit syscalls.h

asmlinkage long sys_hello(void);

linux-5.8.1/arch/x86/entry/syscalls$ gedit syscall_64.tbl

440    common    hello            sys_hello

Looking forward for your responses.Thanks in advance.

Upvotes: 0

Views: 852

Answers (1)

Ian Abbott
Ian Abbott

Reputation: 17438

This code:

asmlinkage long sys_hello(void)
{
        printk("Hello world\n");
        return 0;
}

needs to be changed to:

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

The SYSCALL_DEFINE0(sname) macro is defined by #include <linux/syscalls.h>. It is defined differently depending on whether CONFIG_ARCH_HAS_SYSCALL_WRAPPER is defined in the kernel config. It is defined for some architectures, but not for others.

Upvotes: 0

Related Questions