在讀 linux kernel context switch 讀到一段程式
regparm (NUMBER) Found in versions: 2.7-3.4 Description:
__attribute__(regparm(3));
__attribute__ 及 regparm 都是gcc所實做C語言的非標準延伸功能
上例 __attribute__ 用來定義func的行為,讓gcc在compiler的時候可以做適當對應的行為(特殊處理)。__attribute__ 可以設定Function Attributes, Variable Attributes,及Type Attrubute.可參考gcc online doc:http://gcc.gnu.org/onlinedocs/gcc-4.6.2/gcc/C-Extensions.html#C-Extensions
__attribute__的格式為 __attribute__ 前後都有兩個下底線,之後會緊接一對括號,括號內就是相對應的參數。
其他的有遇到再補充
On the Intel 386, the `regparm' attribute causes the compiler to pass up to NUMBER integer arguments in registers EAX, EDX, and ECX instead of on the stack. Functions that take a variable number of arguments will continue to be passed all of their arguments on the stack. Beware that on some ELF systems this attribute is unsuitable for global functions in shared libraries with lazy binding (which is the default). Lazy binding will send the first call via resolving code in the loader, which might assume EAX, EDX and ECX can be clobbered, as per the standard calling conventions. Solaris 8 is affected by this. GNU systems with GLIBC 2.1 or higher, and FreeBSD, are believed to be safe since the loaders there save all registers. (Lazy binding can be disabled with the linker or the loader if desired, to avoid the problem.)
Comments