0

I'm trying to compile a kernel module from multiple source files. When using the make, I'm getting the following error,

make -C /lib/modules/5.4.0-47-generic/build M=/path_to_source_file modules
...
LD [M]  /path_to_source_file/test.o
Building modules, stage 2.
MODPOST 1 modules
ERROR: "__udivti3" [/path_to_source_file/test.ko] undefined!
scripts/Makefile.modpost:93: recipe for target '__modpost' failed
make[2]: *** [__modpost] Error 1

I'm guessing the problem is with my Makefile. Here is the Makefile that I'm using,

obj-m += test.o
test-objs := rtmModule.o aes.o bignum.o rsa.o memset1.o memory.o

all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
    sudo insmod test.ko
clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
    sudo rmmod test.ko

My simple module source code rtmModule.c is,

#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/random.h>
#include <linux/string.h>

#include "cacheCryptoMain.h"
#include "config.h"
#include "aes.h"
#include "bignum.h"
#include "rsa.h"

MODULE_AUTHOR("XXX");
MODULE_DESCRIPTION("kernel");
MODULE_LICENSE("GPL");

static int __init hello_init(void) {
   printk(KERN_INFO "Module Loaded!\n");
   return 0;
}

static void __exit hello_cleanup(void) {
   printk(KERN_INFO "Cleaning up module.\n");
}

module_init(hello_init);
module_exit(hello_cleanup);

As my source code shows that, I'm just including some other source files into the main module source code file. As I said, my best guess is, the problem is with the Makefile I just can't figure how to fix it. Any help?

0andriy
  • 4,183
  • 1
  • 24
  • 37
perplex
  • 119
  • 2
  • 8
  • 1
    Looks like the errors are coming from your additonal header files – vmemmap Sep 17 '20 at 19:51
  • 1
    Does this answer your question? ["\_\_aeabi\_ldivmod" undefined when compiling kernel module](https://stackoverflow.com/questions/25623956/aeabi-ldivmod-undefined-when-compiling-kernel-module) In short, in the Linux kernel you cannot use operator `/` for 64bit division, you need to use a special function instead. – Tsyvarev Sep 17 '20 at 20:11
  • @Tsyvarev, No, actually. I tried. – perplex Sep 17 '20 at 21:29
  • @r0ei. Thanks. I forgot to add one file previously. But after adding the missing file, I was able to get rid of the last two error **ERROR: "buffer_alloc_free"** and **ERROR: "buffer_alloc_malloc"**. But the first problem **__udivti3** persists. – perplex Sep 17 '20 at 21:32
  • 1
    Please, show your **code**. Without it we simply cannot help you. (By code I mean the headers too, as exactly they cause the errors). – Tsyvarev Sep 17 '20 at 22:26
  • There are five modules more than the one you are showing us. Show the code! – 0andriy Sep 18 '20 at 09:56
  • Those header files are from an old [PolarSSL library](https://github.com/ARMmbed/mbedtls/tree/polarssl-1.0/library). Here is the source code that I'm using, [aes.c](https://pastebin.com/zMaDKkUV). [bignum.c](https://pastebin.com/4iYnH8sB). [memory.c](https://pastebin.com/yeSss7gt). [memset1.c](https://pastebin.com/KYq5uMqd). [memory_buffer_alloc.c](https://pastebin.com/ci6bKLv2). [rsa.c](https://pastebin.com/xAH62mkJ). – perplex Sep 18 '20 at 18:18
  • 1
    What you are doing is including into the kernel module the code, which likely is never intended to work in the Linux kernel. Do you expect us to go through that **thousands lines** of linked code and find the line which uses 64-bit division or some other thing? No, this is not how Stack Overflow works. We expect you to perform some basic **debugging**, and prepare [mcve] - the code which reproduces the problem (that is, shows similar error message), and that code should contain **as little lines as possible**. After finding a solution, you may "backport" it to the original code. – Tsyvarev Sep 18 '20 at 19:05

0 Answers0