Thread: Why is this in my object code?

  1. #1
    Registered User
    Join Date
    Apr 2004
    Posts
    21

    Why is this in my object code?

    I'm back with writing my OS, and I have problem. I compile the kernel.cpp file with g++, the loader.s file with as, and the nasmfunctions.s file with NASM, then link them together. I have it down to one error, and I can't figure it out. It says:

    kernel.o(.eh_frame+0x11): undefined reference to '__gxx_personality_v0'

    I looked in the object file and sure enough, the reference is there. How did it get there? Is there something I can do about it? Thanks!

    The code for my file:
    Code:
    extern "C"{
    extern void _sayhi();
    int _main ( void* mbd, unsigned int magic )
      {
        _sayhi();
        return 0;
      }
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    There is a reason why operating systems are written in C and not C++, and now you know.

    C++ comes with a lot more support requirements, and that "gxx_personality_v0" is just one of the things which you are missing.
    Other things you are likely to be missing are the called to global and static constructors, possible RTTI support, possible virtual function support etc etc.

    With C, you've got what you wrote - nothing more, nothing less. It's so much easier to take a bunch of C code, wrap the most miniscule of bootstrap asm around it and have it do what you want.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Apr 2004
    Posts
    21
    Uh,Huh... I see what you mean. So is there a way that I can get rid of this, or am I stuck with C? I'm not to good with the more advanced C principles, though many are similiar to C++, and the object orientation is really helpful.

    Edit:
    Speaking of which, my other file which is below doesn't make this error. Why?

    Code:
    extern "C"{
    int _main ( void* mbd, unsigned int magic )
      {
        endlessloop: goto endlessloop;
        return 0;
      }
    }
    Last edited by OSDever; 05-24-2004 at 04:48 PM.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > I looked in the object file and sure enough, the reference is there
    Well you could implement your own - what sort of reference is it?
    Loading a value from a global variable? Calling a function?
    All you need in your asm is a symbol with the same name which does the right thing, or an acceptable replacement.
    Trace through a normal C++ program compiled with the same compiler.

    > Speaking of which, my other file which is below doesn't make this error. Why?
    Erm, it doesn't call a function.
    Why that makes a difference, I don't know. Read the asm to see the context for creating that symbol.

    IMO, you should really be linking with libstdc++ to get all of these issues resolved automatically.
    You also need to draw a distinct line between various parts of the process, say
    - bootstrap - no C++ at all
    - kernel - all C++
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Apr 2004
    Posts
    21
    I looked at the binary again, and noticed that
    Code:
    __gxx_personality_v0
    comes after the _sayhi() function (which by the way is written in assembly, in nasmfunctions.s). Seeing that the first file that goes into an endless loop doesn't have either the "_sayhi()" function or "__gxx_personality_v0", the problem has a good chance of being a result of calling an external function. So, as I see it, I could make the "_sayhi()" function into inline assembly, or I could *possibly* declare the extern in the main function, or I could use inline assembly to do a
    Code:
    call _sayhi()
    What do you think about that interpretation of the problem?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Include Problems
    By loopshot in forum Game Programming
    Replies: 13
    Last Post: 02-17-2006, 03:22 PM
  2. A question about constructors...
    By Wolve in forum C++ Programming
    Replies: 9
    Last Post: 05-04-2005, 04:24 PM
  3. DirectMusic engine problem
    By VirtualAce in forum Game Programming
    Replies: 7
    Last Post: 03-17-2005, 06:12 PM
  4. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM