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.