[fpc-devel] elf load order

Sven Barth pascaldragon at googlemail.com
Fri Mar 16 22:48:42 CET 2012


On 16.03.2012 21:37, Andrew Haines wrote:
> 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 look at e.g. $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 look at cprt0.as 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




More information about the fpc-devel mailing list