Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #15501 > unrolled thread
| Started by | 伏虎 <fuhu314@hotmail.com> |
|---|---|
| First post | 2012-04-20 20:43 -0700 |
| Last post | 2012-04-22 03:34 +0100 |
| Articles | 5 — 4 participants |
Back to article view | Back to comp.lang.c++
hi,everyone. can anybody tell me where the C++ program start? 伏虎 <fuhu314@hotmail.com> - 2012-04-20 20:43 -0700
Re: hi,everyone. can anybody tell me where the C++ program start? ralph <nt_consulting64@yahoo.net> - 2012-04-21 00:52 -0500
Re: hi,everyone. can anybody tell me where the C++ program start? 伏虎 <fuhu314@hotmail.com> - 2012-04-20 23:25 -0700
Re: hi,everyone. can anybody tell me where the C++ program start? scott@slp53.sl.home (Scott Lurndal) - 2012-04-21 16:59 +0000
Re: hi,everyone. can anybody tell me where the C++ program start? Nobody <nobody@nowhere.com> - 2012-04-22 03:34 +0100
| From | 伏虎 <fuhu314@hotmail.com> |
|---|---|
| Date | 2012-04-20 20:43 -0700 |
| Subject | hi,everyone. can anybody tell me where the C++ program start? |
| Message-ID | <c24c257f-50aa-4d3e-a856-fa34eb3d2cf4@lf20g2000pbb.googlegroups.com> |
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.
[toc] | [next] | [standalone]
| From | ralph <nt_consulting64@yahoo.net> |
|---|---|
| Date | 2012-04-21 00:52 -0500 |
| Message-ID | <ssh4p75mtkiucr6m7uph6qpr1fra8v8sj7@4ax.com> |
| In reply to | #15501 |
On Fri, 20 Apr 2012 20:43:33 -0700 (PDT), ?? <fuhu314@hotmail.com> 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
[toc] | [prev] | [next] | [standalone]
| From | 伏虎 <fuhu314@hotmail.com> |
|---|---|
| Date | 2012-04-20 23:25 -0700 |
| Message-ID | <b071f2ba-1c4b-42ec-8d70-c9f099044b29@k10g2000pbk.googlegroups.com> |
| In reply to | #15502 |
On Apr 20, 10:52 pm, ralph <nt_consultin...@yahoo.net> wrote: > On Fri, 20 Apr 2012 20:43:33 -0700 (PDT), ?? <fuhu...@hotmail.com> > 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.
[toc] | [prev] | [next] | [standalone]
| From | scott@slp53.sl.home (Scott Lurndal) |
|---|---|
| Date | 2012-04-21 16:59 +0000 |
| Message-ID | <KHBkr.145889$3J7.28844@news.usenetserver.com> |
| In reply to | #15503 |
=?UTF-8?B?5LyP6JmO?= <fuhu314@hotmail.com> writes: >On Apr 20, 10:52=A0pm, ralph <nt_consultin...@yahoo.net> wrote: >> On Fri, 20 Apr 2012 20:43:33 -0700 (PDT), ?? <fuhu...@hotmail.com> >> 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. > the gnu runtime C library includes a file containing the startup code which is invoked by the linker and invokes the programmers main() function. see, for example, the file sysdeps/x86_64/elf/start.S in the [e]glibc sources. The linker sets the ELF entry point to _start when linking with -lc. scott
[toc] | [prev] | [next] | [standalone]
| From | Nobody <nobody@nowhere.com> |
|---|---|
| Date | 2012-04-22 03:34 +0100 |
| Message-ID | <pan.2012.04.22.02.34.50.867000@nowhere.com> |
| In reply to | #15503 |
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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.c++
csiph-web