Equivalent of __declspec( naked ) in gcc/g++

后端 未结 2 1386

What is the equivalent of __declspec( naked ) in gcc/g++? __declspec( naked ) is actually used to declare a function without any epilo

相关标签:
2条回答
  • 2021-02-06 04:39

    I believe there is no such equivalent with a recent GCC under Linux. The compiler emit prologues and epilogues when appropriate, and you should leave that decision to it. It may be quite good at making prologues or epilogues quite small, or even sometimes non-existent.

    You could code your function in assembly. Or you can put asm statements inside your function.

    And you did not tell why you want to do that. What is your goal, and why precisely are you asking?

    0 讨论(0)
  • 2021-02-06 04:42

    On some architectures, gcc supports an attribute called "naked"; the most recent gcc docs I have give this list of architectures: ARM, AVR, MCORE, RX and SPU.

    If you are using one of those architectures (gcc will give you a warning if you try to use it and it isn't supported), the attribute can be used like this:

    __attribute__ ((naked)) int fun ()
    {
    }
    

    [There's been a bit of discussion recently on the gcc developer list about adding the "naked" attribute as a more general feature, and trying to support it on more architectures, but obviously that doesn't help you :).]

    0 讨论(0)
提交回复
热议问题