1

I modified the io-packet of qnx and calculating a timestamp in the recieve.c file at ip layer.

CODE:

uint64_t ipStart_time, IPLatency;
EXPORT_SYMBOL(IPLatency);         //I am using this in Linux

void rtl_receive ()
{
      ipStart_time = clock_cycles();
      IPLatency = ipStart_time;
}

I want to read that timestamp in my user program:

So I did : code:

extern uint64_t IPLatency;

But it is showing error: undefined reference to IPLatency

Shreevardhan
  • 12,233
  • 3
  • 36
  • 50

3 Answers3

0

The extern keyword informs the compiler that it should expect a function or variable (symbol) to be defined in another of the linking objects. For a function this means that the compiler will not give an error if a function has not been implemented.

The error you get, undefined reference, indicates that the linker cannot find a exported symbol with that signature in any of the object files included in the linking.

fredrik
  • 6,483
  • 3
  • 35
  • 45
0

I'm guessing a little bit here because there isn't a lot of information about where these respective files are. With that as a disclaimer here goes ....

You have edited a file that belongs to the Operating System Kernel and exported the symbol. That just makes the symbol visible to kernel modules that wish to link with the kernel and not to a userspace program. Your userspace program is not linked to the kernel and thus when you attempt to link the linker cannot find a reference to IPLatency and it exits.

The extern keyword tells the compiler that this symbol is external to this file, and so just assume it exists and let the linker worry about it. The purpose of the extern definition is so the compiler knows what the type of this variable is, and not to reserve memory for it. The linker needs to find all the symbols in order to turn a symbol in to an actual reference to the correct memory location. So an extern variable needs to be declared somewhere in the program that you are trying to link.

What you are attempting to do is transfer information from kernel space to userspace. This is going to be much more difficult, involving either a new system call or by making the information available via some other mechanism (e.g. sysfs). You will probably need to research some more and then ask another question about that (and the answer to that question will probably be beyond me).

dave
  • 4,812
  • 4
  • 25
  • 38
0

The answer might be short: EXPORT_SYMBOL is used for exporting symbols inside the kernel, e.g. to other kernel modules. Your user space program would not have access to it, thus your linker would report a undefined reference error.

Suggestion: send the data via things like copy_to_user or write the information in /proc and let the userspace program read from it.

Community
  • 1
  • 1
starrify
  • 14,307
  • 5
  • 33
  • 50
  • I am using QNX microkernel operating system then what is your suggestion. I am modiifying the io pkt in user space only and also I am loading the io pkt into the qnx momentics ide!!! – user3635707 May 14 '14 at 09:14
  • @user3635707 You mean both two pieces of your code are expected to work in user space? Then I don't see what would `EXPORT_SYMBOL` do since it's only defined for kernel source. I'm not familiar with QNX but as it's UNIX-like, may I suppose you can still write to `/proc`? – starrify May 14 '14 at 09:20
  • Linux is a monolithic kernel, so we modify the kernel source code and we use procfs to copy the data into user space. QNX is a microkernel, so we modify the io pkt(network driver) in user space and compile with the other user space application. but dont know why am i getting the error ? – user3635707 May 14 '14 at 09:23