Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2012-03

elf load order

4 messages · 2 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Andrew Haines

Hi,

I'm trying to figure out the order of events when an elf file is executed.

I think that the _start symbol just points to the start of the .text section and crt1 is first followed by crti followed by crtbegin. After that I'm not sure.

I am porting fpc to the xenon platform and it uses the elf file format for executables.

I know that code in System.pp the begin end block at the end is being executed but when that procedure (PASCALMAIN?) exits, where is the next code begin executed?

in my test program.pas the begin end block is not called afaict.

I only have a putline method I wrote to debug. I can't currently follow the code with a debugger.

Regards,

Andrew

Reply by email

Sven Barth
to Andrew Haines
Andrew Haines wrote 19 lines
Hi, I'm trying to figure out the order of events when an elf file is executed. I think that the _start symbol just points to the start of the .text section and crt1 is first followed by crti followed by crtbegin. After that I'm not sure. I am porting fpc to the xenon platform and it uses the elf file format for executables. I know that code in System.pp the begin end block at the end is being executed but when that procedure (PASCALMAIN?) exits, where is the next code begin executed? in my test program.pas the begin end block is not called afaict. I only have a putline method I wrote to debug. I can't currently follow the code with a debugger.

Take a . $fpcdir/rtl/linux/i386/prt0.as. This contains the startup (and shutdown) code for Free Pascal executables on linux-i386 that don't use libc. You'll see the call to PASCALMAIN there as well as the halt code after it (which is executed once PASCALMAIN returns).

Regards,
Sven

Reply by email

Andrew Haines
to Sven Barth
Sven Barth wrote 15 lines
On 16.03.2012 19:16, Andrew Haines wrote: > Hi, > > I'm trying to figure out the order of events when an elf file is > executed. > > I think that the _start symbol just points to the start of the .text > section and crt1 is first followed by crti followed by crtbegin. After > that I'm not sure. Take a . $fpcdir/rtl/linux/i386/prt0.as. This contains the startup (and shutdown) code for Free Pascal executables on linux-i386 that don't use libc. You'll see the call to PASCALMAIN there as well as the halt code after it (which is executed once PASCALMAIN returns).

Thanks that is helpful. PASCALMAIN is the begin end block at the end of the system unit? Or is it the begin end block in the program.pas file?

libxenon, which I am linking to, uses newlib.

Regards,

Andrew

Reply by email

Sven Barth
to Andrew Haines
Andrew Haines wrote 18 lines
On 03/16/12 15:27, Sven Barth wrote: > On 16.03.2012 19:16, Andrew Haines wrote: >> Hi, >> >> I'm trying to figure out the order of events when an elf file is >> executed. >> >> I think that the _start symbol just points to the start of the .text >> section and crt1 is first followed by crti followed by crtbegin. After >> that I'm not sure. > Take a . $fpcdir/rtl/linux/i386/prt0.as. This contains the > startup (and shutdown) code for Free Pascal executables on linux-i386 > that don't use libc. You'll see the call to PASCALMAIN there as well as > the halt code after it (which is executed once PASCALMAIN returns). > Thanks that is helpful. PASCALMAIN is the begin end block at the end of the system unit? Or is it the begin end block in the program.pas file?

Yes, PASCALMAIN is the "begin ... end" of the program file (or the library file). It's first call before any of your code is run is to initialize all other units (calling the initialization sections of all other units with the system one being the first).

libxenon, which I am linking to, uses newlib.

You can also take a which is the same for applications using the C-library. I don't know though where the startup files are located on a Xenon system, because then you could check how a C application is started and adjust that for FPC.

Regards,
Sven

Reply by email