Entry point - Unix

This is a discussion on Entry point - Unix ; What's the entry point for executable and shared library on UNIX? I mean analog to WinMainCRTStartup for executable on Windows? Is it possible to overwrite entry point? Does linker have this option? I assume this entry point besides other stuff ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: Entry point

  1. Entry point

    What's the entry point for executable and shared library on UNIX? I
    mean analog to WinMainCRTStartup for executable on Windows? Is it
    possible to overwrite entry point? Does linker have this option? I
    assume this entry point besides other stuff contains calls to all
    static instances constructors and destructors and actually calls main.

  2. Re: Entry point

    Sasha writes:
    >What's the entry point for executable and shared library on UNIX? I
    >mean analog to WinMainCRTStartup for executable on Windows? Is it
    >possible to overwrite entry point? Does linker have this option? I
    >assume this entry point besides other stuff contains calls to all
    >static instances constructors and destructors and actually calls main.


    The entry point is the start of the code space (unless otherwise
    specified with a linker option), which for executables is almost
    always crt0. The c compiler system will have crt0.o in its standard
    link area, very dependant on the system for where this is. crt0 is the
    one that initializes the standard C lib, and eventually calls main().
    There may be additional stages depending on the language (ie. crt1,
    crt2, etc).

    All linkers have many options to specify these things, and most are
    pretty different than one another.

    There are additional init link areas for static constructors and
    destructors in the executable file, usually specified with #pragmas to
    the compiler to be gathered together in the link stage.

    shared libraries don't have an entry point on unix systems. They have
    static constructors/destructures, again in seperate areas in the
    object file to be gathered together properly in the link stage.

    The C compiler system is the one area where different unix systems are
    vastly different than one another. Even though many use GCC
    now-a-days, even then, they get installed and used very differently
    (ie. Darwin vs. Linux x86 systems).
    And the bigger vendors have their own compiler suites (ie. Sun and HP)
    that are all different than GCC as well.

    You'll really have to study the specific system you are interested in
    for their documentation on the C compiler system for this sort of info.

  3. Re: Entry point

    On Aug 19, 9:09 am, Doug McIntyre wrote:

    > shared libraries don't have an entry point on unix systems. They have
    > static constructors/destructures, again in seperate areas in the
    > object file to be gathered together properly in the link stage.


    As a little side note, this is not entirely true. Shared libraries
    can have entry points. For example, if you have access to a Linux
    system, try executing /lib/libc.so.6 . However, these entry points
    are not used in ordinary situations.

  4. Re: Entry point

    On Aug 19, 12:09*pm, Doug McIntyre wrote:
    > Sasha writes:
    > >What's the entry point for executable and shared library on UNIX? I
    > >mean analog to WinMainCRTStartup for executable on Windows? Is it
    > >possible to overwrite entry point? Does linker have this option? I
    > >assume this entry point besides other stuff contains calls to all
    > >static instances constructors and destructors and actually calls main.

    >
    > The entry point is the start of the code space (unless otherwise
    > specified with a linker option), which for executables is almost
    > always crt0. The c compiler system will have crt0.o in its standard
    > link area, very dependant on the system for where this is. crt0 is the
    > one that initializes the standard C lib, and eventually calls main().
    > There may be additional stages depending on the language (ie. crt1,
    > crt2, etc).
    >
    > All linkers have many options to specify these things, and most are
    > pretty different than one another.
    >
    > There are additional init link areas for static constructors and
    > destructors in the executable file, usually specified with #pragmas to
    > the compiler to be gathered together in the link stage.
    >
    > shared libraries don't have an entry point on unix systems. *They have
    > static constructors/destructures, again in seperate areas in the
    > object file to be gathered together properly in the link stage.
    >
    > The C compiler system is the one area where different unix systems are
    > vastly different than one another. Even though many use GCC
    > now-a-days, even then, they get installed and used very differently
    > (ie. Darwin vs. Linux x86 systems).
    > And the bigger vendors have their own compiler suites (ie. Sun and HP)
    > that are all different than GCC as well.
    >
    > You'll really have to study the specific system you are interested in
    > for their documentation on the C compiler system for this sort of info.


    If I am not using CRT, I don';t need crt() to be the entry point. On
    Windows platform linker has /ENTRY switch that specifies the entry
    point. Does GCC have similar option on Solaris for instance?

  5. Re: Entry point

    On Aug 22, 12:59 pm, Sasha wrote:

    > If I am not using CRT, I don';t need crt() to be the entry point. On
    > Windows platform linker has /ENTRY switch that specifies the entry
    > point. Does GCC have similar option on Solaris for instance?


    It won't be an option for gcc, but for ld, but it should exist. Check
    the man page for ld(1).

  6. Re: Entry point

    On 2008-08-22, Sasha wrote:
    >
    > On Aug 19, 12:09*pm, Doug McIntyre wrote:
    >
    > If I am not using CRT, I don';t need crt() to be the entry point. On
    > Windows platform linker has /ENTRY switch that specifies the entry
    > point. Does GCC have similar option on Solaris for instance?


    You're looking for the -e linker option, "man ld" for details.

    (at least the GNU ld and the IRIX ld which I've just checked accept that
    flag, should be the same on solaris but I can't verify).

    --
    John Tsiombikas (Nuclear / Mindlapse)
    http://nuclear.sdf-eu.org/

+ Reply to Thread