user3635707
user3635707

Reputation: 5

error in kernel source code of linux?

I modified the kernel source code r8169.c and calculating the timestamp as below:

s64 a;
EXPORT_SYMBOL(a);
a = time();

I did not add the original timestamp function call

I am using the variable a in another source file in kernel: ip_input.c

extern s64 a;

s64 b,c;
b= time();
c = b-a; 

I receive this error:

 ERROR: undefined reference to a 

How to solve it?

Upvotes: 0

Views: 152

Answers (2)

John
John

Reputation: 3520

r8169.c is a module, whereas ip_input.c is in the main kernel. The main kernel cannot import symbols from a module. The fix for this is to declare your variable within ip_input.c, and import it from r8169.c. You also have to use file scope as Olaf mentioned.

ip_input.c:

s64 a, b, c;
EXPORT_SYMBOL(a);

void someFunc() {
   b=time();
   c=b-a;
}

r8169.c:

extern s64 a;

void someFunc() {
    a=time();
}

Upvotes: 1

Olaf Dietsche
Olaf Dietsche

Reputation: 74028

From the incomplete source code, I guess that

s64 a;
EXPORT_SYMBOL(a);
a = time();

is inside a function and therefore, a cannot be exported, because it is local to that function.

To use a outside of this module, you must define it with file scope, e.g.

s64 a;
EXPORT_SYMBOL(a);

void some_function()
{
    a = time();
}

This allows the symbol for a to be exported and then used in another module.

Upvotes: 1

Related Questions