[fpc-devel] How hard is it to port FPC to AIX

Jonas Maebe jonas.maebe at elis.ugent.be
Sun Sep 14 00:41:39 CEST 2008


On 13 Sep 2008, at 21:49, Peter Popov wrote:

> I read Felipe's wiki thouroughly and i think I can manage that part.  
> I also see I have to use the Darwin (powerpc) rtl, not the linux  
> (powerpc) rtl. I will start experimenting with it on monday.

You can choose either the Darwin or the Solaris rtl, both are libc- 
based. However, the Solaris one is probably closer since Darwin is  
based on BSD while Solaris on sysv. AIX is also based on sysv (in  
spite of the fact that it uses a different ABI).

> I have one question though, which is not clear to me, as I am not a  
> low-level system guy:
> To get the whole thing started I have two options:
> 1. Generate cross-compiler capable of producing AIX compatible  
> binaries and start working on the rtl.
> 2. Generate a compiler for AIX and and start working on the rtl.
>
> Option 1 seems the easier.

I don't understand what you mean by option 2. You always have to start  
with a cross compiler, since before you can have a native compiler you  
need a port of the rtl.

> I don't have mac powerpc machine, so I have to work from linux.

That doesn't really matter.

> Your suggestion is to start with the darwin compiler, right?

The compiler is mostly OS-agnostic. When cross-compiling, you can use  
pretty much anything as a host platform. See Marco's buildfaq for some  
more information about building the compiler and cross-compiling in  
general: http://www.stack.nl/~marcov/buildfaq.pdf

> As far as I looked, AIX uses XCOFF binaries. Can the mac powerpc  
> compiler generate compatible binaries?

The compiler generates assembler code. This assembler code has to be  
passed, in your case, to a cross-assembler which generates AIX XCOFF  
object files, and subsequently to a cross-linker to generate an XCOFF  
binary. The compiler couldn't care less what the object format is, it  
just generates assembler (except if you use an internal object writer,  
but that is optional and not required).

Usually, assemblers for new targets do some small things slightly  
different, and you'll probably have to compensate for that in your  
assembler writer. Most of it can probably be shared with the existing  
assembler writers though (compiler/aggas.pas, compiler/ppcgen/ 
agppcgas.pas).

> Is the FPC_DARWIN_JMP_MAIN suggestion solution to this problem?

When the operating systems starts a program, there is usually some  
setup that needs to be done: running init routines, store the pointers  
to the parameters and environment variables in global variables, etc.  
This code usually resides in a file called crt1.o or similar and is  
distributed either with the OS or with the (C) compilers.

You can either create a patched Pascal (or assembler) version of such  
a file (as has been done for Solaris and Linux), or you can use the  
system version of this file and simply take over when it calls  
'main' (normally to start the 'main' function of a C program). The  
latter is what is done if you use the FPC_DARWIN_JMP_MAIN functionality.

> Option 2 seems complicated: I will have to first generate the  
> compiler and rtl object files for AIX. Next,  link the compiler on  
> AIX using AIX's linker. Afterwards, work can begin on the rtl, which  
> seems more complex?

You cannot generate a compiler and rtl object files for AIX before you  
have ported the rtl and the compiler to AIX.

> Either way, I will have to first be able to generate aix compatible  
> object files before starting the actual compiler branch. Unless you  
> advise otherwise I will generate a linux-darwin cross and start  
> experimenting with option 1.

A compiler is always built for a particular target architecture, and  
then it always supports generating code for all OSes on that  
architecture. So if you have an i386 machine, you have to build an  
i386->powerpc (or i386->powerpc64) cross compiler. This compiler will  
(if you don't change anything) support generating assembler code for  
all ppc(64) targets, including linux and darwin(regardless of whether  
it's built on Windows, on Linux or on anything else). When you add  
support for AIX to the compiler sources, it will also support  
generating assembler code for AIX/ppc(64).

See the buildfaq for more details.

ppc and ppc64 are two different targets (so a single compiler cannot  
generate both ppc and ppc64 code at this time), but they share a lot  
of code. You're free to choose which one you want to port (first), as  
I guess that AIX likes most ppc OSes seamlessly supports both 32 and  
64 bit binaries.


Jonas

PS: while porting the compiler, you may want to grep the compiler  
sources for systems_darwin and system_powerpc64_darwin, to see whether  
the special cases for those targets also apply to AIX. Also note that  
the Darwin ABI slightly deviates from the standard AIX ABI regarding  
some alignments,




More information about the fpc-devel mailing list