Linux device driver: Symbol "memcpy" not found

I am trying to write a Linux device driver. Everything worked out very well until I tried to use "memcpy". I don’t even get a compiler error, when I β€œdo” it just warns me:

WARNING: "memcpy" [/root/homedir/sv/main.ko] undefined!

OK, and when I try to load via insmod, I am on the console:

insmod: error inserting './main.ko': -1 Unknown symbol in module

and on dmesg:

main: Unknown symbol memcpy (err 0)

I include the following:

 #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/init.h> #include <linux/kernel.h> /* printk() */ #include <linux/slab.h> /* kmalloc() */ #include <linux/fs.h> /* everything... */ #include <linux/errno.h> /* error codes */ #include <linux/types.h> /* size_t */ #include <linux/fcntl.h> /* O_ACCMODE */ #include <linux/cdev.h> #include <asm/system.h> /* cli(), *_flags */ #include <asm/uaccess.h> /* copy_*_user */ 

Function using memcpy:

 static int dc_copy_to_user(char __user *buf, size_t count, loff_t *f_pos, struct sv_data_dev *dev) { char data[MAX_KEYLEN]; size_t i = 0; /* Copy the bulk as long as there are 10 more bytes to copy */ while (i < (count + MAX_KEYLEN)) { memcpy(data, &dev->data[*f_pos + i], MAX_KEYLEN); ec_block(dev->key, data, MAX_KEYLEN); if (copy_to_user(&buf[i], data, MAX_KEYLEN)) { return -EFAULT; } i += MAX_KEYLEN; } return 0; } 

Can someone help me? I thought it was Linux / string.h, but I get the error exactly the same. I use the 2.6.37-rc1 kernel (I work in user-mode-linux, which only works with 2.6.37-rc1). Any help is appreciated.

 # Context dependent makefile that can be called directly and will invoke itself # through the kernel module building system. KERNELDIR=/usr/src/linux ifneq ($(KERNELRELEASE),) EXTRA_CFLAGS+=-I $(PWD) -ARCH=um obj-m := main.o else KERNELDIR ?= /lib/modules/$(shell uname -r)/build PWD = $(shell pwd) all: $(MAKE) V=1 ARCH=um -C $(KERNELDIR) M=$(PWD) modules clean: rm -rf Module.symvers .*.cmd *.ko .*.o *.o *.mod.c .tmp_versions *.order endif 
+6
c linux-kernel memcpy device-driver
source share
7 answers

I do this in user-mode-linux

Can you try without Linux user mode?

The kernel does not bind to libc, but UML is an exception. This may explain your binding error.

+2
source share

memcpy either defined as its own specifics (if __HAVE_ARCH_MEMCPY ), or as a generic version in lib / string.c. In any case, it should be available. Look in / proc / kallsyms, check your module with objdump, and also check that version control of characters is not corrupted.

+1
source share

The first point is that this is a binding error, not a compilation error. This is actually a dynamic communication problem. You are compiling the module, albeit with a warning. Only when you download it does it fail. Thus, this has nothing to do with header files. The second point is that memcpy is defined and widely used in the kernel, so there is no reason why the memcpy character is not found.

The reason may simply be a problem for GCC itself. GCC uses built-in functions, some of which may reference libgcc, which is not in the kernel. If so, this can be solved using the -fno-builtin compiler option

+1
source share

memcpy is defined in string.h, which you skipped to enable.

0
source share

Let me post this comment as an answer, because there is more space for recording.

Firstly, "err 0" sounds suspicious. (Because 0 is success.) Then, your Makefile has two KERNELDIR lines, the last of which is? = D, so it may not do what you want. There is also CFLAGS = "- ARCH = um", which sounds so terribly wrong. -I $ PWD is redundant. A KERNELRELASE check is also not required. All in all, he looks overly confusing. Use this much simpler MF:

  obj-m: = main.o

 KERNELDIR = / lib / modules / $ (shell uname -r) / build

 all: modules

 modules modules_install clean:
         $ {MAKE} V = 1 ARCH = um -C $ {KERNELDIR} M = $$ PWD $@ ;
0
source share

Include the correct header string.h ;

 #include <linux/string.h> 

If you have a compilation error, submit this.

0
source share

The problem may be with the declaration EXTRA_CFLAGS . Try removing the extra space for include and - for architecture, that is:

 EXTRA_CFLAGS+=-I$(PWD) ARCH=um 
0
source share

All Articles