0

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.

1 Answer 1

0

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.

1
  • Thank you very much for your response.It worked.
    – Imran Khan
    Dec 7, 2021 at 18:38

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.