最近,我正试图了解iw中的代码是如何工作的。在iw.h,我遇到了以下情况:
#define __COMMAND(sect, name, args, nlcmd, flags, idby, handler) \
static const struct cmd __cmd_ ## handler ## nlcmd ## idby \
__attribute__((used)) __attribute__((section("__cmd"))) \
= { sect, name, args, nlcmd, flags, idby, handler }
#define COMMAND(section, name, args, cmd, flags, idby, handler) \
__COMMAND(#section, #name, args, cmd, flags, idby, handler)
#define TOPLEVEL(name, args, cmd, flags, idby, handler) \
__COMMAND(NULL, #name, args, cmd, flags, idby, handler)
extern struct cmd __start___cmd;
extern struct cmd __stop___cmd;我尝试了一些搜索谷歌,但只能理解"__start___cmd“和"__stop___cmd”是由链接器生成的。对此还有什么外行的解释吗?
代码中没有使用定义的__COMMAND,我不知道服务的目的是什么。我只能假设它与定义的外部结构相关。
我从https://www.kernel.org/pub/software/network/iw/iw-0.9.1.tar.gz下载了源代码
发布于 2014-06-03 14:49:54
这个宏定义中有趣的是可变属性的使用:
#define __COMMAND(sect, name, args, nlcmd, flags, idby, handler) \
static const struct cmd __cmd_ ## handler ## nlcmd ## idby \
__attribute__((used)) __attribute__((section("__cmd"))) \
= { sect, name, args, nlcmd, flags, idby, handler }gcc (ld )生成两个神奇的变量:__start_SECTION和__stop_SECTION。这些可以用于检索节的起始地址和结束地址。
https://askubuntu.com/questions/476258
复制相似问题