How to call a function in a namespace with asm

Programming, for all ages and all languages.
Post Reply
User avatar
AlfaOmega08
Member
Member
Posts: 226
Joined: Wed Nov 07, 2007 12:15 pm
Location: Italy

How to call a function in a namespace with asm

Post by AlfaOmega08 »

I've got an header:

Code: Select all

namespace idt {
    void undefinedHandler();
};
a source file:

Code: Select all

void idt::undefindedHandler() {
    ...
}
and an nasm source file:

Code: Select all

extern idt::undefinedHandler
...
CALL idt::undefinedHandler
...
During the compilation process, nasm exit with:
line 33 (extern idt::undefinedHandler): error: no special symbol features supported here
line 138 (CALL idt::undefinedHandler): error: expression syntax error

How can I call a function in a namespace from an asm file?
jtlb
Member
Member
Posts: 29
Joined: Sat May 12, 2007 8:24 am

Post by jtlb »

good luck! i tried to call your code from a test program and to disassemble, here is the symbol to use: _ZN3idt16undefinedHandlerEv
you certainly already know that g++ modifies quit a bit the names!!

there is an option to prevent g++ from mangling the names, it is to use extern "C" before the function declaration, the big problem is that the following code won't compile:

Code: Select all

#include <iostream>

using namespace std;

namespace idt
{
    extern "C" void undefinedHandler()
    {
        cout<<"idt";
    }
}

namespace isr
{
    extern "C" void undefinedHandler()
    {
        cout<<"isr";
    }
}

int main()
{
    cout << "Hello world!" << endl;
    idt::undefinedHandler();
    return 0;
}
because the symbol undefinedHandler already exists!

my own solution is to use a function written in C, declared as extern and callable from nasm, the function the calls the CPP on in class.

have fun!
User avatar
AlfaOmega08
Member
Member
Posts: 226
Joined: Wed Nov 07, 2007 12:15 pm
Location: Italy

Post by AlfaOmega08 »

Thanks a lot.

Before you reply, I've tried to "objdump" my output file, and modify "CALL undefinedHandler" with the new name. It has worked, but it was very ugly to see "CALL _ZN3idt4undefinedHandlerEv"...

Now I understand the meaning of extern "C"
Post Reply