c - 文件 linux/compiler.h 中定义的预处理器宏的目的是什么?

标签 c linux gcc macros gcc-warning

我是 Linux 内核的新手。我正在使用稀疏工具来清除代码中存在的噪音。我遇到了这些宏:

   # define __user      __attribute__((noderef, address_space(1)))
   # define __kernel    __attribute__((address_space(0)))
   # define __safe      __attribute__((safe))
   # define __force __attribute__((force))
   # define __nocast    __attribute__((nocast)) 
   # define __iomem __attribute__((noderef, address_space(2)))
   # define __must_hold(x)  __attribute__((context(x,1,1)))
   # define __acquires(x)   __attribute__((context(x,0,1)))
   # define __releases(x)   __attribute__((context(x,1,0)))
   # define __acquire(x)    __context__(x,1)
   # define __release(x)    __context__(x,-1)
   # define __cond_lock(x,c)    ((c) ? ({ __acquire(x); 1; }) : 0)
   # define __percpu    __attribute__((noderef, address_space(3)))

现在我想知道:sparse 如何使用它们来报告错误/警告?

我的问题:

  1. 我想要了解它们如何帮助编译器和稀疏报告警告的详细信息。
  2. 这些 address_space(x) context(X, x, x) 是什么,有什么用途?
  3. __nocast__force__user__safe 的目的是什么?

最佳答案

我认为所有这些宏仅在 sparse 的上下文中才有意义(联机帮助页 here - 您可以在那里找到所有这些属性和稀疏警告的描述)。如果您查看上面复制的源文件,就会发现一个很大的 __CHECKER__ 宏用于启用它们。

我不确定此时 gcc 是否对它们做了任何事情 - 我认为它有点默默地忽略了它们......在 2004 年 Linus Torvalds 的一封电子邮件中说:

This is important to remember: for gcc, the sparse annotations are meaningless. They can still be useful just to tell the programmer that "hey, that pointer you got wasn't a normal pointer" in a fairly readable manner, but in the end, unless you use sparse, they don't actually do anything.

有一些票为此目的而开 - http://www.spinics.net/lists/linux-sparse/msg03366.html .

关于c - 文件 linux/compiler.h 中定义的预处理器宏的目的是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26425673/

相关文章:

c - 整数类型是如何隐式转换的?

c - 如何更改 makefile 以避免对数学库中函数的 undefined reference ?

c - 如何禁用 gcc 警告 "cc1: warning: command line option ‘-std=c++11’ 对 C++/ObjC++ 有效但对 C 无效 [默认启用]”

c++ - 我的蹦床弹不起来(绕行,C++,GCC)

c - 3 个骰子的随机骰子卷的星号直方图

c - void (*(*f[])())() 将 f 定义为未指定大小的数组……这是什么意思?

c - VxWorks PPC 中 errno 始终返回零

linux - CentOS | 命令未找到.bat 文件

python - 一旦 python 脚本从终端 (Ctrl-C) 停止,如何释放 Ubuntu 内存?

c++ - 如何强制 gcc 忽略本地化