How to setup inter-module function calls

chodong

Member


Messages: 22

I have developed two modules (A & B) where B depends on A. Module B needs to call function func1 provided by module A.

I successfully kldload module A first, but I cannot load module B due to a linker error:

Code:
kernel: link_elf: symbol func1 undefined

How do I mark func1 for export in module A so the linker can resolve it for module B?

In Linux I would simply add EXPORT_SYMBOL(func1) in module A.

Thank you,
 

trasz@

Active Member
Developer

Reaction score: 74
Messages: 228

How is the "func1" defined? Would be great if you could paste appropriate part of your code.
 

eyebone

Active Member

Reaction score: 5
Messages: 148

i would be interested as well, also if you are loading Module B automaticly via the loading of Module A?
 
OP
C

chodong

Member


Messages: 22

I have the following setup:

1. Module A:
File A.h that defines func1 and func2 as follows:

Code:
int func1(int flag);
extern int func2(int flag); /* try extern as well. */
File A.c declares func1 and func2 as follows:

Code:
int func1(int flag) {return flag;}
int func2(int flag) {return flag;}

2. Module B:
File B.c includes A.h and tries to call func1 and func2.


I first kldload A.ko and upon success I try to load B.ko but this fails because func1 and func2 are undefined.
 
OP
C

chodong

Member


Messages: 22

The problem is solved.

I added to module B MODULE_DEPEND(A) and func1 and func2 are resolved and I can load module B after loading module A.
 

williamy

Member


Messages: 24

I met this issue, and still looking for an example,
Can someone please give an simple sample , thanks
 

iulian

New Member


Messages: 9

What chodong says is right in order to achive EXPORT_SYMBOL effect on FreeBSD you need to use MODULE_DEPEND(9), but you also need to keep in mind that:
-the prototype of your functions need to be declared nonstatic otherwise compiler will try to link against them right after compile time.
 
Top