hi,everyone. can anybody tell me where the C++ program start?

Discussion in 'C++' started by ä¼è™Ž, Apr 21, 2012.

  1. ä¼è™Ž

    ä¼è™Ž Guest

    hi,everyone. can anybody tell me where the C++ program start? I am
    writing a loader, I want know the entry point of C++ program.

    thank you.
    ä¼è™Ž, Apr 21, 2012
    #1
    1. Advertising

  2. ä¼è™Ž

    ralph Guest

    On Fri, 20 Apr 2012 20:43:33 -0700 (PDT), ?? <>
    wrote:

    >hi,everyone. can anybody tell me where the C++ program start? I am
    >writing a loader, I want know the entry point of C++ program.
    >
    >thank you.


    The "entry-point" is defined in the executable file format for the
    platform you are developing on. This starting point is set by the
    Linker used to compile the executable, it might be at the lowest
    address, the start of the TEXT section, or anywere else.

    A specific Language has no impact on the entry-point, however, a
    development framework or rapid tool might have.

    Research the documentation for the specific 'executable' file format
    for the platform of interest. Your loader will need to query it for
    the entry-point.

    -ralph
    ralph, Apr 21, 2012
    #2
    1. Advertising

  3. ä¼è™Ž

    ä¼è™Ž Guest

    On Apr 20, 10:52 pm, ralph <> wrote:
    > On Fri, 20 Apr 2012 20:43:33 -0700 (PDT), ?? <>
    > wrote:
    >
    > >hi,everyone. can anybody tell me where the C++ program start? I am
    > >writing a loader, I want know the entry point of C++ program.

    >
    > >thank you.

    >
    > The "entry-point" is defined in the executable file format for the
    > platform you are developing on. This starting point is set by the
    > Linker used to compile the executable, it might be at the lowest
    > address, the start of the TEXT section, or anywere else.
    >
    > A specific Language has no impact on the entry-point, however, a
    > development framework or rapid tool might have.
    >
    > Research the documentation for the specific 'executable' file format
    > for the platform of interest. Your loader will need to query it for
    > the entry-point.
    >
    > -ralph
    >
    >


    my question is I have a piece of asm code, and I want to start the C++
    main(), which function shall I call?

    I am using gnu tool. I compile the C++ code into .o files and use ld
    to link them together. if i want to write a ld script to tell the ld
    to output a.out file or elf file, how to do that? i checked the asm
    code output by the gcc -S, and I cannot find the start or _start
    symbol.
    ä¼è™Ž, Apr 21, 2012
    #3
  4. ä¼è™Ž

    Nobody Guest

    On Fri, 20 Apr 2012 23:25:25 -0700, ä¼è™Ž wrote:

    > my question is I have a piece of asm code, and I want to start the C++
    > main(), which function shall I call?


    Note that a C++ program doesn't start by executing main(). It starts by
    executing the constructors for variables defined at file scope. main() is
    only called after that has been done.

    > I am using gnu tool. I compile the C++ code into .o files and use ld
    > to link them together. if i want to write a ld script to tell the ld to
    > output a.out file or elf file, how to do that? i checked the asm code
    > output by the gcc -S, and I cannot find the start or _start symbol.


    When linking object files together with gcc or g++, it will also link the
    appropriate "CRT" file (unless -nostartfiles is given), and possibly
    libgcc as well.

    You're better off asking this sort of question on a group dedicated either
    to the toolchain (e.g. gcc and/or binutils) or the platform. For and
    ELF-based Linux system, you might want to look at the source code for
    ld-linux.so (which is part of glibc).

    An ELF executable specifies the entry point in the e_entry field of the
    header. If an ELF executable specifies a loader (on Linux, this is
    normally ld-linux.so.2 or ld-linux-<arch>.so.2), execve() will call the
    entry point of the loader; it's up to the loader to figure out how to run
    the program.
    Nobody, Apr 22, 2012
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jin zhang
    Replies:
    3
    Views:
    329
    Thomas Fritsch
    Oct 1, 2004
  2. =?iso-8859-1?q?vipul=20parmar?=

    can anybody tell me how to compile the C code with embedded python.

    =?iso-8859-1?q?vipul=20parmar?=, Mar 4, 2004, in forum: Python
    Replies:
    0
    Views:
    285
    =?iso-8859-1?q?vipul=20parmar?=
    Mar 4, 2004
  3. Ashu
    Replies:
    12
    Views:
    486
    Stuart Golodetz
    Jul 5, 2006
  4. Vellingiri Arul

    can anybody tell me please!

    Vellingiri Arul, Sep 25, 2007, in forum: Ruby
    Replies:
    1
    Views:
    65
    Jano Svitok
    Sep 25, 2007
  5. ä¼è™Ž
    Replies:
    1
    Views:
    375
    Keith Thompson
    Apr 21, 2012
Loading...

Share This Page