4

I know the way normal and I tried it but it seems not work.

In linux/net/sched/sch_htb.c, I define the variable:

unsigned int queuelength;
EXPORT_SYMBOL(queuelength);

And some actions about the variable, not important.

In linux/net/ipv4/tcp_dctcp.c,

extern unsigned int queuelength;

Error come with net/built-in.o:

In function `dctcp_update_alpha':
linux/net/ipv4/tcp_dctcp.c:230: undefined reference to `queuelength'

The kernel version is v4.6.

3
  • Are both files (net/sched/sch_htb.c and net/ipv4/tcp_dctcp.c) are compiled as a part of the kernel core (that is, not as modules)? If so, no EXPORT_SYMBOL is needed. Note, that compilation of the file sched/sch_htb.c depends on CONFIG_NET_SCH_HTB configuration option. If you compile it as a module, you cannot use symbol defined in it in the kernel core. Commented May 10, 2017 at 18:08
  • I checked the '.config' file, which shows"CONFIG_TCP_CONG_DCTCP=y " and "CONFIG_NET_SCH_HTB=m". I think that maybe I should change it from 'm' to 'y' and delete the 'EXPORT_SYMBOL'.Then I can compile it successfuly? Commented May 11, 2017 at 1:39
  • I have another question. I need to use the variable 'queuelength' also in other codes (ovs). So maybe I have to reserve 'EXPORT_SYMBOL' and compilation as module?I'm not sure about it but it did work well without modifying net/ipv4/tcp_dctcp.c.What should I do to deal with the both problems at the same time? Commented May 11, 2017 at 1:56

1 Answer 1

3

It depends on how a source file, which defines the variable (generally, symbol), and a source file, which uses the variable (symbol) are compiled: as a part of the kernel module, or as a part of the kernel core (that is, built-in into kernel).

Assuming names of the source files are define-symbol.c and use-symbol.c correspondingly, you have 5 possibilities:

  1. Both define-symbol.c and use-symbol.c are compiled into kernel core.

    EXPORT_SYMBOL isn't needed.

  2. define-symbol.c is compiled into kernel core, use-symbol.c is compiled into kernel module.

    EXPORT_SYMBOL is needed.

  3. define-symbol.c is compiled into kernel module, use-symbol.c is compiled into kernel core.

    You cannot use such symbol.

  4. define-symbol.c and use-symbol.c are compiled into the same kernel module.

    EXPORT_SYMBOL isn't needed.

  5. define-symbol.c and use-symbol.c are compiled into the different kernel modules.

    EXPORT_SYMBOL is needed.

Note, that way of source compilation may depend on configuration options.

In your case, it seems you have situation 3: as net/ipv4/tcp_dctcp.c is used for built-in.o, it is part of the kernel core.


Note, that in any case variable should be declared for use it. Otherwise, it will be compile-time error, not a link one.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.