Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
15 years ago

MODPOST __copy_from_user module compilation issue

Hello!

I'm encountering a problem while compiling USB modules under Nios2Linux-MMU.

In Kernel config I select USB Host driver support and execute 'make modules'. At the end of the process I get the following errors:


Building modules, stage 2.
  MODPOST 21 modules
ERROR: "__copy_from_user"  undefined!
ERROR: "__copy_to_user"  undefined!
Does anyone know good documentation about this modpost stuff? Actually I have no clue and can't find anything on this topic...

Btw, also when I use the __copy_*_user and copy_*_user in my own modules it results in the same error. As a workaround 've been using the put_user and get_user functions. But this couldn't be a solution.

regards

steron

10 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    It seems nobody can help me. I'm still trying to fix that and found out some things:

    Now I'm trying to compile my own module where I use the function mentioned above.

    The module is a char device driver and the important parts are the following:

    # include <linux/init.h># include <linux/module.h># include <linux/ioport.h># include <linux/fs.h># include <asm/io.h># include <asm/uaccess.h>
    __copy_from_user(cmd,buffer,2);
    
    Now i don't get the errors anymore, but warnings instead:

    
      Building modules, stage 2.
      MODPOST 1 modules
    WARNING: "__copy_from_user"  undefined!
    
    The Makefile: (for building outside the kernel tree)

    
    obj-m := mymod.o
    all:
      $(MAKE) -C ../../../uClinux-dist SUBDIRS=$(PWD) modules
    
    Eventually the module is built, but when I try to plug it into the running kernel, I get this error:

    
    root:~> insmod mymod.ko
    mymod: Unknown symbol __copy_from_user
    insmod: can't insert 'mymod.ko': unknown symbol in module, or unknown parameter
    
    Am I missing something here? Cause the symbol _is_ actually defined, as I can see from /proc/kallsyms:

    
    root:~> cat /proc/kallsyms | grep copy_from_user
    c8006854 T __copy_from_user
    c8008210 T copy_from_user_page
    c805075c t __iovec_copy_from_user_inatomic
    c805081c T iov_iter_copy_from_user
    c80508ac T iov_iter_copy_from_user_atomic
    c8086654 t pipe_iov_copy_from_user
    c8123d58 T csum_partial_copy_from_user
    
    One other thing I've found is this post on the forum:

    http://www.alteraforum.com/forum/showthread.php?t=14426 (http://www.alteraforum.com/forum/showthread.php?t=14426&highlight=copy_from_user)

    wentao suggests to include another EXPORT_SYMBOL in the according file. I did the same in arch/nios/mm/uaccess.c but it didn't help.

    Thanks for your support

    steron
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    --- Quote Start ---

    It seems nobody can help me. I'm still trying to fix that and found out some things:

    --- Quote End ---

    Before complaining to forum members, please 'grep' the kernel source directories and find the definition of '__copy_from_user'. Maybe it exists in the file

    /nios2-linux/linux-2.6/arch/nios2/mm/uaccess.c

    and its header file is

    /nios2-linux/linux-2.6/arch/nios2/include/uaccess.h

    And please check again whether your 'include path' is right or not.

    Kazu
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi!

    --- Quote Start ---

    Before complaining to forum members

    --- Quote End ---

    Complaining was not my intention. I'm sorry if it sounded like that. I just wanted to give you more information because the error messages from my first were probably not enough.

    I checked the definition of the function and the include path. Eventually I put the EXPORT_SYMBOL(__copy_from_user); line into the arch/nios2/mm/uaccess.c file.

    Don't know if it's only a workaround, because it seems strange that other users haven't encountered such errors.

    By the way, in my last post when I wrote

    --- Quote Start ---

    I did the same in arch/nios/mm/uaccess.c but it didn't help.

    --- Quote End ---

    I just got confused with the directories in my kernel tree. Surprisingly I got another 'nios2' directory below 'arch/nios2' but this seems to be a result of any messy copying action.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi,

    --- Quote Start ---

    I checked the definition of the function and the include path. Eventually I put the EXPORT_SYMBOL(__copy_from_user); line into the arch/nios2/mm/uaccess.c file.

    Don't know if it's only a workaround, because it seems strange that other users haven't encountered such errors.

    --- Quote End ---

    You mean that you don't have the description EXPORT_SYMBOL(__copy_from_user); in your 'uaccess.c' file ?

    Modules are loaded dynamically and the linker must resolve the locations. To do this, the kernel must expose the symbol's location, and you need the macro 'EXPORT_SYMBOL(symbol)' if you want to use the 'symbol' in your module. In fact, the symbols

    
    EXPORT_SYMBOL(__copy_from_user);
    EXPORT_SYMBOL(copy_from_user);
    EXPORT_SYMBOL(__copy_to_user);
    EXPORT_SYMBOL(copy_to_user);
    EXPORT_SYMBOL(get_ds);
    EXPORT_SYMBOL(get_fs);
    EXPORT_SYMBOL(set_fs);
    
    are exported in my 'arch/nios2/mm/uaccess.c'.

    The macro 'EXPORT_SYMBOL' exports symbols as follows

    
    /* For every exported symbol, place a struct in the __ksymtab section */# define __EXPORT_SYMBOL(sym, sec)                
        extern typeof(sym) sym;                    
        __CRC_SYMBOL(sym, sec)                    
        static const char __kstrtab_##sym            
        __attribute__((section("__ksymtab_strings"), aligned(1))) 
        = MODULE_SYMBOL_PREFIX# sym;                        
        static const struct kernel_symbol __ksymtab_##sym    
        __used                            
        __attribute__((section("__ksymtab" sec), unused))    
        = { (unsigned long)&sym, __kstrtab_##sym }
    # define EXPORT_SYMBOL(sym)                    
        __EXPORT_SYMBOL(sym, "")
    
    And it seems that Wind River guys did not test the module loadings at all. Please see this

    http://www.alteraforum.com/forum/showpost.php?p=78791&postcount=48

    .

    Kazu
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Shame on me, I actually got confused with file versioning. In the recent versions there are the correct macro calls in 'arch/nios2/mm/uaccess.c' and others.

    Thanks for the hint!

    steron
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Steron,

    I actually have the same problem. Can you tell me how you fixed it? Thanks
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    I got all the necessary definitions simply by updating to the most recent git tree. :-)

    Where exactly are you encountering this problem?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hey,

    I think we need more information on your module. Can you show us some code?