使用“裸体"GCC 中函数的属性 [英] Using the "naked" attribute for functions in GCC
问题描述
6.30 声明函数属性中的 GCC 文档状态::p><块引用>
裸体
在 ARM、AVR、IP2K、RX 和 SPU 端口上使用此属性来指示指定的函数不需要编译器生成的序言/尾声序列.由程序员提供这些序列.唯一可以安全地包含在裸函数中的语句是没有操作数的 asm
语句.应避免所有其他语句,包括局部变量的声明、if
语句等.应该使用裸函数来实现汇编函数的主体,同时允许编译器为汇编器构造必要的函数声明.
我可以使用 C 语法从裸函数中安全地调用函数,还是仅使用 asm?
如果你在裸函数中唯一要做的就是调用另一个函数,你可以只使用一条 JMP 机器代码指令.
您跳转到的函数将有一个有效的序言,它应该直接返回给裸函数的调用者,因为 JMP 不会将返回地址压入堆栈.
GCC documentation states in 6.30 Declaring Attributes of Functions:
naked
Use this attribute on the ARM, AVR, IP2K, RX and SPU ports to indicate that the specified function does not need prologue/epilogue sequences generated by the compiler. It is up to the programmer to provide these sequences. The only statements that can be safely included in naked functions are
asm
statements that do not have operands. All other statements, including declarations of local variables,if
statements, and so forth, should be avoided. Naked functions should be used to implement the body of an assembly function, while allowing the compiler to construct the requisite function declaration for the assembler.
Can I safely call functions using C syntax from naked functions, or only by using asm?
If the only thing you do in the naked function is call another function you can just use a single JMP machine code instruction.
The function you jump to will have a valid prologue and it should return directly to the caller of the naked function since JMP doesn't push a return address on the stack.
这篇关于使用“裸体"GCC 中函数的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!