Re: [fpc-devel] Building compiler, rtl, host, target... (cross compiling) (terminology)

2011-04-08 Thread Sven Barth

Am 07.04.2011 11:21, schrieb Skybuck Flying:

Perhaps you look at it from the binary level, but that's not fair, you
should look at it from the source code level.

Single refers to target.

A zero-target cross compiler would be a cross compiler under development
it has the framework to become a cross compiler but it does not yet have
any supported targets.

A single-target cross compiler is probably still a cross compiler under
development but already has support for a single target.

A dual-target cross compiler has support for two targets.

A 6-target cross compiler has support for six targets.

I would define a target as follows:

Target = harware (cpu) + operating system (assembler + linker + rtl (so
that application can hook into basic OS functionality))



By that definition FPC is a multi target compiler, because every FPC 
compiler for CPU A can compile code for all operating systems that are 
supported inside the compiler. E.g. the i386 compiler can compile code 
for Win32, Linux, FreeBSD, DOS, OS/2, Mac OS X, NativeNT, ..., while the 
ARM compiler can compile for WinCE, Linux, Mac OS X, ... .


Regards,
Sven
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] Building compiler, rtl, host, target... (cross compiling)

2011-04-07 Thread Michael Schnell

On 04/06/2011 09:54 PM, Skybuck Flying wrote:


First of all I would like to write that I failed to compile the RTL of 
Free Pascal so that might be adding a little bit too the confusion.
AFAIK, not all versions of the compiler are tested to compile the 
compiler and the RTL. I have a separate (old) FPC installation to be 
able to always compile the latest svn versions.


-Michael
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] Building compiler, rtl, host, target... (cross compiling)

2011-04-07 Thread Michael Schnell

On 04/07/2011 03:06 AM, Skybuck Flying wrote:


Missing from this list is ofcourse:

debuggers/cross debuggers which would still be needed for serious 
platform development but that is beyond the scope of this posting ;)
And unfortunately me very little to almost no experience with writing 
debuggers myself... perhaps a nice thing for me to explore in the 
future ;)
Do you have a gdb for the new arch ? Same should be usable to debug FPC 
generated programs.


AFAIK, someone has started a project doing a debugger in Pascal code, 
but I have no idea if this already works.


Also one the native  compiler (and command-line debugger) works, it 
should be possible to compile Lazarus for that arch. But why does it 
make  sense to do the  native development tools after all ? IMHO, 
usually, less effort and more desirable is to do a decent 
cross-compiling SDK: cross compiler, remote cross-debugger (needs only a 
stub on the target) and running Lazarus on a Windows or Linux PC.


BTW, regarding the RTL: what OS-API does the arch provide ? some open 
standard like Linux Mono or Java, something more cryptic like the 
Windows or .NET API ore even something completely propriety ?


-Michael
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel]Building compiler, rtl, host, target... (cross compiling)

2011-04-07 Thread Michael Schnell

On 04/06/2011 10:19 PM, Skybuck Flying wrote:
1. Why is it not possible for a single free pascal compiler executable 
to support and compile towards multiple targets ? (One target selected 
out of multiple target options)
It does not make much sense to request this. It's no hassel at all to 
use different compiler executables and RTL files for different targets. 
And a multi-Target compiler would be slower, as at very may lines 
case-switches between the different target would need to be handled, and 
the much bigger compiler-executable would be less efficient regarding 
the CPU's cache use.


-Michael
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] Building compiler, rtl, host, target... (cross compiling) (terminology)

2011-04-07 Thread Skybuck Flying


- Original Message - 
From: Hans-Peter Diettrich drdiettri...@aol.com

To: FPC developers' list fpc-devel@lists.freepascal.org
Sent: Thursday, 7 April, 2011 06:10 AM
Subject: Re: [fpc-devel] Building compiler, rtl, host,target... (cross 
compiling)




Skybuck Flying schrieb:

First of all free pascal compiler is not a multi-target cross 
compiler but it is a dual-target cross compiler (dual meaning host and 
target can be different ;))


FPC is a single target cross compiler. cross indicates that the target 
can be different from the host system.


Perhaps you look at it from the binary level, but that's not fair, you 
should look at it from the source code level.


Single refers to target.

A zero-target cross compiler would be a cross compiler under development it 
has the framework to become a cross compiler but it does not yet have any 
supported targets.


A single-target cross compiler is probably still a cross compiler under 
development but already has support for a single target.


A dual-target cross compiler has support for two targets.

A 6-target cross compiler has support for six targets.

I would define a target as follows:

Target = harware (cpu) + operating system (assembler + linker + rtl (so that 
application can hook into basic OS functionality))



To be able to cross compile from one target to another target actually 
requires two targets.


It requires:

1. A host/local target
2. A guest/remote target


(The source code of the compiler is compiled towards the host target, this 
requires some sort of host rtl.)
(However the source code of the compiler also requires the source code of 
the guest target/rtl.)


So in a way it needs support for both targets otherwise it will somehow not 
fully compile or it can't cross compile.


And thus when I say a dual target cross compiler this would mean it has 
support in it's source code for two targets.



The remaining question is: what is free pascal ?

Free pascal I would describe as:

a x-way self-hosting retarded (/brain-dead) (non-portable) cross compiler.

(Perhaps I should even add internal assemblers etc but let's not for now).

x should be replaced by the number of target-sub-folders.

self-hosting refers to the fact that it can compile itself once it's build.

retarded (/brain dead) refers to it's inability to switch targets during 
runtime.
(only one guest-target seems to be selected during the compiler-self-build 
process).


(non-portable) refers to it's inability of being compiled by other 
compilers.
(For example Delphi can't compile the current state of the free pascal 
compiler source code)


cross-compile refers to it's ability to cross compile to other targets.

I hope I clearified that a little bit for you ! ;) =D

Bye,
 Skybuck. 


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] Building compiler, rtl, host, target... (cross compiling)

2011-04-07 Thread Matt Emson
Advice : Google Skybuck Flying troll. Notorious. 

Sent from my iPhone 4
___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] Building compiler, rtl, host, target... (cross compiling)

2011-04-06 Thread Sven Barth

Wow, wow, wow... you are indeed a bit confused here.

On 06.04.2011 21:54, Skybuck Flying wrote:

Hello,

First of all I would like to write that I failed to compile the RTL of
Free Pascal so that might be adding a little bit too the confusion.
(Just simple i386/x86 tests to see if the sources build)

The compiler however seems to compile fine.

I am now a bit confused about the whole theory of things and I will try
to explain my confusion:

The confusion pretty much starts with the compiler needing some RTL
includes and units and especially some types like DWORD or PtrInt to be
able to compile itself ?!?

This is a little bit weird to me: Why would the compiler need an RTL to
compile itself ? (Perhaps these are accidental, or unnecessary depedancy ?)



RTL is an abbreviation for Runtime Type Library and it's necessary for 
EVERY Free Pascal program, because it abstracts the functions of the 
operating system, provides the system unit and types and other units. As 
the compiler is just a plain Free Pascal program itself (and when FPC 
compiles itself it just compiles a plain FPC program) it's absolutely 
naturaly that the compiler needs the RTL. I would have been more 
surprised if the compiler would not need the RTL...



I am now a bit confused again about what free pascal is...

As far as I can remember I once build a free pascal compiler which would
compile from a certain host operating system towards another target
operating system.

Is free pascal supposed to be able to do this all naturally by itself
(as long as it can use external tools) ?



Yes. As free pascal is able to cross compile (see below).


I just consulted my little tutorial on building a free pascal cross
compiler which I once wrote and I notice the following things:

It mentions a cross assembler and a cross linker these where
external GNU related tools.


From the looks of it I'm thinking right now that Free Pascal might

actually not be a cross compiler and it actually can only compile to
it's own platform that the compiler executable was compiled for.



This assumption is wrong.
The following assumption is right: the compile can only compile for the 
one target it was configured for. The target the compiler is compiled to 
and the target the compiler compiles for don't need to be the same. E.g. 
I could compile a PowerPC cross compiler by compiling an ARM based 
compiler that is cross compiled by a i386 cross compiler for ARM.



So in other words if this hypothesis above is correct then what was
happening at the time might have been the following situation:

1. Free Pascal (fake cross) compiler compiles the source from
PPC386.EXE (i386 host) towards Linux/PowerPC (made up target) as x86
assembly.

2. The cross-assembler.exe from GNU tools takes the x86 assembly
produced by free pascal compiler and actually cross-assembles it for
linux/powerpc into powerpc assembly.

3. The cross-linker does the rest.



Let's assume you want a native ARM compiler and start with an i386 
compiler then the steps are like this:


1. compile a i386=ARM cross compiler by compiling pp.pas using the 
correct defines

2. compile the RTL for ARM using the new cross compiler
3. compile a ARM=ARM compiler by compiling pp.pas using the correct 
defines and by using the i386=ARM compiler and the ARM RTL

= tada! you have a native ARM compiler (and a i386 = ARM compiler as well)

[of course this assumes that you have binutils and eventually needed 
libraries to do the cross compile]



So suppose that's how it was working at the time then Free Pascal is
actually not really a cross compiler.



You are supposing wrong ;)




However this does not mean it's useless for my project/experiments... I
need Free Pascal to be a cross compiler which compiles to abstract
assembly so I can assemble it further into any assembler a true cross
compiler I would say ;)


Perhaps I am wrong and you guys would like to correct me... but for that
I will help you by asking a question:


1. Would it be possible to build the following compiler:

FreePascalCompiler.exe (runs on windows) (compiles for virtual machine
instructions/outputs virtual machine assembly).



Yes this would be possible. Does that virtual machine you want to target 
FPC for provide its own virtual instruction set or does it use the 
instruction set of one of the already supported platforms?


If the latter then you don't need to do much.

If the first then you either need to find cross binutils that allow you 
to assemble code to that virtual instruction set or you must write an 
internal assembler for FPC. In both cases though you must add a new cpu 
(parallel to ARM, i386, PowerPC, etc.) that contains the needed methods 
for the compiler to call (that generate the assembler code for the 
assembler) and handles calling conventions, variable locations, etc.




Or is a FreePascalCompiler.exe (x86) only capable of producing x86
assembly like I suspect it might be/do...


Suppose I am correct and free pascal 

Re: [fpc-devel]Building compiler, rtl, host, target... (cross compiling)

2011-04-06 Thread Žilvinas Ledas

Hi,
maybe some basic info could help you understand some things: 
http://wiki.lazarus.freepascal.org/Cross_compiling


Regards
Žilvinas

On 2011-04-06 23:19, Skybuck Flying wrote:

Hello,


...


Bye,
 Skybuck.


___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel


Re: [fpc-devel] Building compiler, rtl, host, target... (cross compiling)

2011-04-06 Thread Hans-Peter Diettrich

Skybuck Flying schrieb:

First of all free pascal compiler is not a multi-target cross 
compiler but it is a dual-target cross compiler (dual meaning host 
and target can be different ;))


FPC is a single target cross compiler. cross indicates that the target 
can be different from the host system.


So starting with the basics: Suppose somebody would get the free pascal 
source codes only and now executables then that person would first need 
to compile:


1. The compiler
and
2. The run time library


No. First the RTL is compiled, then the compiler is built with that RTL.

The compiler is a little bit like an application, applications need a 
system unit, the runtime library provides that system unit.


That's why the RTL is compiled before. The compiler is built *exactly* 
like any other application, in this step.


In the next step the new compiler is used to compile itself. This way 
new features can be included, which the old (bootstrap) compiler could 
not compile (e.g. class helpers...).


This step is repeated until the last two executables are binary 
identical. This procedure allows for further extensions, that even could 
not be compiled by an earlier stage compiler, without the need to 
specify an exact number of required recompilations.




So step 1 would then produce:

A free pascal compiler executable which runs on windows.

The target to keep things easy was set to windows to first produce a 
native compiler (which runs on windows and compiles to windows)
... and which can compile the new language version, including all added 
features.



Now the mission/job/idea is to produce a cross-compiler which can 
cross-compile to a new architecture/processor/platform let's called it 
NewCPU and NewRTL in short: NewTarget.



Step 2 is a repeat of step 1. However it would be helpfull if the RTL 
itself was also compileable to the new target... but let's see how far 
we can go without it.



Step 2 specifies somehow to the build enviroment that the compiler 
sources are to be re-compiled but this time the compiler which is build 
from it should compile to the NewTarget... for that the new compiler 
needs new architecture support... So that's where the new instructions 
and new assembler come in... and perhaps new linker... but let's start 
with new assembler and such...


Since the executable to be produced must still run on windows it can and 
probably must still use the windows RTL to be able to produce the 
executable.


Right. Every application must use the RTL of its host platform.

What is needed is a full-cross compiler which also uses the NewRTL for 
the NewPlatform.


No, why should the compiler need to use a different RTL, for its *own* 
operation? Every compiler can compile the RTL for its target, as well as 
other applications.


Apperently specifieing the NewRTL can be done by compiler command line 
options or configuration files.


As is, the specification of the target (hard coded in the compiler) is 
sufficient to locate target-specific parts of the source code, in 
target-specific directories. I really like that idea :-)



Thus there are now probably two RTL's involved:

One RTL for the host, One RTL for the target.


How the compiler makes sense of this I am not yet sure... Perhaps it's a 
question of linking in the NewRTL when a NewPlatform application is 
being build by the new compiler.


Every target e.g. has its own data types, like 32 or 64 bit pointers. 
That's why the compiler has to use the target-specific version of the 
RTL, in cross-compiling any code.


So perhaps it's the internal linker which needs the NewRTL to be 
present to do it's work ?!? How else could it work ??


Every linker needs binaries that have been compiled for the target, and 
includes them into the final executable (for the same target).



However perhaps the new compiler also needs to do type checking against 
the NewRTL for NewPlatform applications...


Thus somehow the new compiler must be using the new RTL.


That's fully automatic. The compiler compiles or loads precompiled units 
recursively, by evaluating the Uses clauses, so that it traverses the 
target specific RTL and ends up in the System unit.


All parts of the target, that are required for a compilation, are 
already built into the compiler. That includes code generation for the 
target CPU, and linking executables for the target OS (what may actually 
occur in an external assembler and linker).



So if I am correct porting free pascal compiler and rtl towards a new 
platform requires the following steps:



1. Step 1 (preparing for first native free pascal compiler)

Install a external pascal compiler so that free pascal compiler 
sources can be compiled.
(ignore free pascal's own rtl if necessary), make changes to the free 
pascal compiler source code if necessary to use the external pascal 
compiler's RTL.


2. Step 2 (building free pascal compiler)

Build the free pascal compiler with the external pascal compiler. This 

Re: [fpc-devel] Building compiler, rtl, host, target... (cross compiling)

2011-04-06 Thread Hans-Peter Diettrich

Skybuck Flying schrieb:

So this is my biggest question and hunch: At some point during this 
whole step/phase the RTL needs to be switched/swapped with the new 
RTL...


No swapping required. The host-RTL is linked *into* the compiler itself, 
the target-RTL is used (read, compiled) *by* the compiler, at runtime.


DoDi

___
fpc-devel maillist  -  fpc-devel@lists.freepascal.org
http://lists.freepascal.org/mailman/listinfo/fpc-devel