http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50242

             Bug #: 50242
           Summary: __attribute__((naked)) is ignored on IA32 (x86)
    Classification: Unclassified
           Product: gcc
           Version: 4.5.2
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: congru...@yahoo.co.uk


Given the follow c++ file:
---(start)---
__attribute__((naked)) void test(int a)
{
    asm("//Do stuff");
    asm("ret $4");
};

struct myclass
{
    __attribute__((naked)) ~myclass()
    {
        asm("//Do stuff");
        asm("ret");
    }

    virtual void virt() { };
};

void testmyclass()
{
    myclass x;
}
---(end)---
The compiler will give the following complaints:
testnaked.cpp:1:39: warning: 'naked' attribute directive ignored
testnaked.cpp:9:34: warning: 'naked' attribute directive ignored
Additionally, prolog and epilog code is generated. The relevant parts of the
assembler output with added commentary follow:
---(start)---
__Z4testi: //test(int)
/APP
 # 3 "testnaked.cpp" 1
    //Do stuff
 # 0 "" 2
 # 4 "testnaked.cpp" 1
    ret $4
 # 0 "" 2
/NO_APP
    ret // This ret shouldn't be here.
...(snip)...
__ZN7myclassD1Ev: //myclass::~myclass()
    movl    4(%esp), %eax // Destructor prolog that restores the vtable.
    movl    $__ZTV7myclass+8, (%eax) // These 2 lines shouldn't be present.
/APP
 # 11 "testnaked.cpp" 1
    //Do stuff
 # 0 "" 2
 # 12 "testnaked.cpp" 1
    ret
 # 0 "" 2
/NO_APP
    ret // This ret shouldn't be here.
---(end)---
My apologies for the AT&T syntax, but that's what -S yields.

Reply via email to