LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
Search this Thread
Old 02-23-2009, 01:08 AM   #1
opsimath
LQ Newbie
 
Registered: Feb 2009
Posts: 4

Rep: Reputation: 0
How does one export a symbol from a module built outside the kernel source tree?


I am writing this code outside the kernel source tree. In fact up to now I have not needed the kernel source tree on my machine. I'd like to find a way to do this without movign my source tree under the kernel tree.

My driver (loadable module) receives a data stream via a USB endpoint. This module includes a facility for 3rd parties to extend the data processing by writing their own modules which they can register via a registration framework I have implemented in my module.

For example, my customer might write a module that has the following line in their init() method:

my_framework_register(my_fops);

My understanding is that I need to export the symbol my_framework_register via the EXPORT_SYMBOL() macro. When I do this, and make my module, I get a file named Module.symvers in the folder where the module .ko file is. When I load the module, I see the exported symbols in /proc/kallsyms tagged with 'T'. So far so good.

I then reference the exported routines via an include file containing
extern int my_framework_register( struct my_fops *);

When it builds, I get a WARNING about this symbol being unresolved. When I try to insmod the module I get an error. The dmesg buffer tells me two things: There is mo symbol version information for that symbol and the symbol did not load.

So, I try concatenating the Module.symvers file onto the one in /lib/modules/<version>/build. I reboot and try to build/load the module. The build works without any warnings, but now I get an error telling me "operation no permitted". However, this time there is nothing in the dmesg buffer.

I suspect the documentation that I was reading about EXPORT_DYMBOL and #define EXPORT_SYMTAB applies when the module is installed. But I cannot figure out everything I need to do to install my module. I presume that if I built the module inside the main kernel tree and added a Kconfig/Makefile pair to connect it all to the kernel build system this would probably just work. For lots of reasons I do not want to do this.

So the real question is how do I manually "install" a module into a precompiled kernel tree when that module was built using only the headers. Or, is there some other way to get an externally built module's symbols to be published (made available to other modules subsequently loaded)? I'll deal with the dependency issues later I just want to prove the concept is possible first.

Thanks a million for your help!

David

Last edited by opsimath; 02-23-2009 at 02:44 AM.
 
Old 02-23-2009, 07:35 AM   #2
ashok449
Member
 
Registered: Sep 2007
Location: noida
Distribution: suse
Posts: 63

Rep: Reputation: 16
Try this ...


Module 1:

int ash_test(int, int);

int ash_test(int a, int b)
{ int c;
c=a+b;

printk("this is test export_symbol %s\n", __FUNCTION__);
return c;
}


static int __init hello_init(void)
{
printk(KERN_ALERT "Module successfully inserted\n");

return 0;
}
static void __exit hello_exit(void)
{
printk(KERN_ALERT "Module removed ");

}
module_init(hello_init);
module_exit(hello_exit);
EXPORT_SYMBOL_GPL(ash_test);

#dmesg
Module successfully inserted
--------------------------------------------------

Module2:

int ash_test(int, int);
static int __init hello_init(void)
{

int i=0;
i=ash_test(4,5);
printk("ash_test=%d\n", i);


return 0;
}
static void __exit hello_exit(void)
{
printk(KERN_ALERT " Module removed ");

}
module_init(hello_init);
module_exit(hello_exit);



#dmesg
Module successfully inserted
this is test export_symbol ash_test
ash_test=9

ashok@ashok-linux:~/ashok> cat /proc/kallsyms | grep ash_test
f90f4000 u ash_test [sample_module1]
f90f40a4 r __ksymtab_ash_test [sample_module]
f90f40b0 r __kstrtab_ash_test [sample_module]
f90f40ac r __kcrctab_ash_test [sample_module]
f90f4000 t ash_test [sample_module]
140697fc a __crc_ash_test [sample_module]
 
Old 02-23-2009, 12:38 PM   #3
opsimath
LQ Newbie
 
Registered: Feb 2009
Posts: 4

Original Poster
Rep: Reputation: 0
RE: How does one export a symbol from a module built outside the kernel source tree

[SOLVED]

I was able to manually install the module by the following few steps:

1) Copy the .ko file to a location beneath /lib/modules/<version>/kernel
2) Add the exported symbols to /lib/modules/<version>/build/Module.symvers


That's it. There are other databases in the /lib/modules/<version> folder but it seems to work without updating those.

I'd really like to know if there is some other way to publush the exported symbols, besides putting entries in this one file. I can imagine it will be a maintenance problem long term to edit this by hand/awk-script.

The 'Operation not permitted' message was originated from the _init rountine's non-zero return value. Thanks for the helpful error message.
:|

dvb
 
Old 09-15-2011, 11:56 AM   #4
Ondiiik
LQ Newbie
 
Registered: Sep 2011
Posts: 1

Rep: Reputation: Disabled
Wink Kernel config can maybe solve this problem

I had also such problem and soved it by bit another way. The reason why exported symbols from externel kernel module are not visible is that they does not pass throught versioning check if they are not part of kernel. Disabling of versionning check in kernel configuration has solved it:

  • Enable loadable modules support -->
    • Module versionnig support [ ]



OSi
 
  


Reply

Tags
export, kernel, module, symbol


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Howto: build Linux kernel module against installed kernel w/o full kernel source tree LXer Syndicated Linux News 0 09-03-2006 09:21 PM
make only specific module is kernel source tree saranjothy Linux - Kernel 2 08-16-2006 11:05 AM
export symbol from module to kernel dogalmity Programming 0 06-05-2006 05:38 PM
single module compile in clean source tree henryquinn Linux - Software 3 02-15-2006 04:38 AM
which source tree to choose for module compilation ? roemisch Linux - Hardware 4 03-31-2005 05:03 PM


All times are GMT -5. The time now is 03:04 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration