1

I'm a beginner C and Linux developer so I'm sorry if this sounds confusing.

I managed to create a very simple system call successfully by updating the syscall_64.tbl, adding asmlinkage method definition to syscalls.h, adding the folder to main makefile and creating a makefile which has only one line:

obj-y := syscall.o

No problems until this, I compiled Linux source code and it worked. I want to build a more advanced system call. So I added a function to vmx.c(which is in arch/x86/kvm):

void myFunction(void){
//Some code
}
EXPORT_SYMBOL(myFunction);

and defined it in vmx.h(It is in arch/x86/include/asm):

void myFunction(void);

Now the problem begins. I included vmx.h to my syscall.c file and called this function. I'm getting an "undefined reference to myFunction" when I try to compile Linux source code. What am I doing wrong? This is my syscall.c:

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

asmlinkage long sys_customsyscall(const char *test)
{
   printk(KERN_ALERT "Test: %s,\n", test);
   myFunction();
   return 0;
}
2
  • maybe #include "asm/vmx.h" Commented Apr 25, 2016 at 2:25
  • Can you see your syscall.c compilation in the make output? Can you edit your question to show what superfolder's makefile did you include your directory in and how? You have made a good, illustrative of how to add stuff to the linux kernel and so I upvoted you, but to solve your problem it's better to have all data at view. No need to include the whole superfolder's makefile, just the directory name and the including line with two or three lines of context. Commented Apr 26, 2016 at 6:58

2 Answers 2

2

After the things you had done, next thing need to be considered if you are using your function in vmx.c, then in Linux/arch/x86/kvm/Makefile you can see like this

kvm-intel-y             += vmx.o pmu_intel.o

So while compiling make sure, you are using intel's configuration and not amd, otherwise it will not compile along with the source! If it is amd you can define it inside svm.c.

With that, make sure that Virtualization is also enabled, in make menuconfig Virtualization

Also your function prototype, definition/ declaration should not be falling under any #ifdef or similar, until you are sure about that block.

And also check in vmx.h, you added extern keyword, while defining.

Sign up to request clarification or add additional context in comments.

1 Comment

I edited vmx.c file previously to see more information about virtual machines, it works fine as it prints out the variables I added as I interact with VM. So I assume this is not the case. I also added extern keyword, but I'm still getting the same error.
1

You need to export that symbol so it can be referenced by other components, add

EXPORT_SYMBOL(myFunction);

3 Comments

Thank you for the reply. I added this line and updated my post accordingly, but still getting the same error.
@tugce is kvm enabled in the build config?
How do I check this? I don't think this is the case because I edited vmx.c file before to see more information about virtual machines. It works fine(Printing some stuff to system log) as I interact with VM. So I assume this is not the case.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.