[fpc-devel] about freepascal for mips

Fuxin Zhang zhangfx at lemote.com
Fri May 25 05:08:25 CEST 2012


Hello everybody,

  I am Fuxin Zhang from lemote, now we are working on mips support of fpc.
Hope you guys can help us to accelerate the process, a lots of users are
waiting for this(see at the end of copied mail between me and Florian if
interested).
  Lemote can donate developer machines to who want to help.

And my progress and problems:
  I've got the source from subversion and tried to build it in ubuntu
11.10 x86-64 machine. With the following patch and commands, I can get a
partly working ppcrossmipsel(it can at least build a helloworld and
runnable):
patch:
  Index: Makefile.fpc
===================================================================
--- Makefile.fpc	(版本 21354)
+++ Makefile.fpc	(工作副本)
@@ -35,8 +35,8 @@
 target=linux

 [compiler]
-includedir=$(INC) $(PROCINC) $(UNIXINC) $(ARCH)
-sourcedir=$(INC) $(PROCINC) $(UNIXINC) $(ARCH) $(COMMON)
+includedir=$(INC) $(PROCINC) $(UNIXINC) $(ARCH) ../objpas ../objpas/sysutils
+sourcedir=$(INC) $(PROCINC) $(UNIXINC) $(ARCH) $(COMMON)
 targetdir=.

 [shared]
@@ -89,6 +89,7 @@

 # Paths
 OBJPASDIR=$(RTL)/objpas
+UNITDIR=../unix:../objpas:../inc

 [rules]
 .NOTPARALLEL:

This is to fix various file not found errors. I am not sure whether it is
'right' fix.

commands:
  cd rtl/linux;
  patch Makefile.fpc; fpcmake -Ti386-linux,mipsel-linux
  make cycle CPU_TARGET=mipsel

But when I tried to build native mipsel ppc, I met some issues that seem
not easy to fix:
  cpugas.pas(271,7) Note: Local variable "as_MIPS_as_info" not used
Assembling cpugas
Compiling dbgstabs.pas
Assembling dbgstabs
Assembling cputarg
Assembling compiler
Assembling pp
Linking ./pp
/opt/mips-4.4.6/bin/mipsel-linux-ld: warning: ./link.res contains output
sections; did you forget -T?
/home/foxsen/fpc/rtl/units/mipsel-linux/sysutils.o: In function
`SYSUTILS_$$_finalize':
/home/foxsen/fpc/rtl/unix/sysutils.pp:1414: relocation truncated to fit:
R_MIPS_PC16 against
`SYSTEM$_$TINTERFACEDOBJECT_$__$$_QUERYINTERFACE$TGUID$formal$$LONGINT'
/home/foxsen/fpc/rtl/unix/sysutils.pp:1414: relocation truncated to fit:
R_MIPS_PC16 against `SYSTEM$_$TINTERFACEDOBJECT_$__$$__ADDREF$$LONGINT'
/home/foxsen/fpc/rtl/unix/sysutils.pp:1414: relocation truncated to fit:
R_MIPS_PC16 against `SYSTEM$_$TINTERFACEDOBJECT_$__$$__RELEASE$$LONGINT'
pp.pas(224,36) Error: Error while linking
pp.pas(224,36) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
make[1]: *** [ppcmipsel] 错误 1
make[1]:正在离开目录 `/home/foxsen/fpc/compiler'
make: *** [cycle] 错误 2

I know it is related to mips branch offset overflow. After some
research,I've found that ppc code support -fPIC. But when I try to enable
it,the other issue appears:
  make[3]: 正在进入目录 `/home/foxsen/fpc/rtl/linux'
mipsel-linux-as -EL -o ../../rtl/units/mipsel-linux/prt0.o mipsel/prt0.as
mipsel-linux-as -EL -o ../../rtl/units/mipsel-linux/dllprt0.o
mipsel/dllprt0.as
mipsel-linux-as -EL -o ../../rtl/units/mipsel-linux/cprt0.o mipsel/cprt0.as
mipsel-linux-as -EL -o ../../rtl/units/mipsel-linux/gprt0.o mipsel/gprt0.as
/home/foxsen/fpc/compiler/ppcrossmipsel -Pmipsel -XPmipsel-linux- -Xr
-Fu../unix:../objpas:../inc -Fi../inc -Fi../mipsel -Fi../unix -Fimipsel
-Fi../objpas -Fi../objpas/sysutils -FE. -FU../../rtl/units/mipsel-linux -g
-Xs- -fPIC -dmipsel  -Us -Sg system.pp
Free Pascal Compiler version 2.7.1 [2012/05/23] for mipsel
Copyright (c) 1993-2012 by Florian Klaempfl and others
Target OS: Linux for MIPSEL
Compiling system.pp
syscall.inc(42,9) Fatal: Internal error 200502052
Fatal: Compilation aborted
make[3]: *** [system.ppu] 错误 1
make[3]:正在离开目录 `/home/foxsen/fpc/rtl/linux'
make[2]: *** [linux_all] 错误 2
make[2]:正在离开目录 `/home/foxsen/fpc/rtl'
make[1]: *** [rtl] 错误 2
make[1]:正在离开目录 `/home/foxsen/fpc/compiler'
make: *** [cycle] 错误 2

gdb debug trace of this:

Breakpoint 3, TCGMIPS__MAKE_SIMPLE_REF (LIST=0xf7ff0360, REF=...,
this=<error reading variable>) at ./mips/cgcpu.pas:318
318	    if not (pi_needs_got in current_procinfo.flags) then
(gdb) where
#0  TCGMIPS__MAKE_SIMPLE_REF (LIST=0xf7ff0360, REF=..., this=<error
reading variable>) at ./mips/cgcpu.pas:318
#1  0x0817364f in TCGMIPS__HANDLE_LOAD_STORE (LIST=0xf7ff0360,
ISSTORE=false, OP=A_LW, REG=17039392, REF=..., this=<error reading
variable>)
    at ./mips/cgcpu.pas:469
#2  0x081744cb in TCGMIPS__A_LOAD_REF_REG (LIST=0xf7ff0360,
FROMSIZE=OS_32, TOSIZE=OS_32, REF=..., REG=17039392,
    this=<error reading variable>) at ./mips/cgcpu.pas:772
#3  0x08209613 in TCGLOADNODE__PASS_GENERATE_CODE (this=<error reading
variable>) at ncgld.pas:368
#4  0x0815a890 in SECONDPASS (P=0xf7f55220) at pass_2.pas:197
#5  0x0820a2a9 in TCGASSIGNMENTNODE__PASS_GENERATE_CODE (this=<error
reading variable>) at ncgld.pas:604
#6  0x0815a890 in SECONDPASS (P=0xf7f79000) at pass_2.pas:197
#7  0x08208246 in TCGBLOCKNODE__PASS_GENERATE_CODE (this=<error reading
variable>) at ncgbas.pas:366
#8  0x0815a890 in SECONDPASS (P=0xf7f78f20) at pass_2.pas:197
#9  0x08208246 in TCGBLOCKNODE__PASS_GENERATE_CODE (this=<error reading
variable>) at ncgbas.pas:366
#10 0x0815a890 in SECONDPASS (P=0xf7f79540) at pass_2.pas:197
#11 0x0815a96d in DO_SECONDPASS (P=0xf7f79540) at pass_2.pas:229
#12 0x0817ae4a in TCGPROCINFO__GENERATE_CODE (this=<error reading
variable>) at psub.pas:1236
#13 0x0817a59f in TCGPROCINFO__GENERATE_CODE_TREE (this=<error reading
variable>) at psub.pas:974
#14 0x0817c11b in READ_PROC_BODY (OLD_CURRENT_PROCINFO=0xf7ca11f0,
PD=0xf7c902c0) at psub.pas:1787
#15 0x0817c5bf in READ_PROC (ISCLASSMETHOD=false, USEFWPD=0x0) at
psub.pas:1923
#16 0x0817ca41 in READ_DECLARATIONS (ISLIBRARY=false) at psub.pas:2047
#17 0x08178902 in BLOCK (ISLIBRARY=false) at psub.pas:275
#18 0x0817bb59 in TCGPROCINFO__PARSE_BODY (this=<error reading variable>)
at psub.pas:1615
#19 0x081d4f5c in PROC_UNIT () at pmodules.pas:960
#20 0x081bcf63 in COMPILE (FILENAME=...) at parser.pas:395
#21 0x0806e878 in COMPILE (CMD=0x0) at compiler.pas:255
#22 0x080482a1 in main () at pp.pas:235

It seems that the PIC support for mipsel is somehow broken,to fix this I
have to learn more about the ppc logic. Could you please fix it or give me
some hints? I have some experiences on general compiler materials and
quite familiar with low level things like as/ld etc.

To fix the linking issue, I've also tried to use -xgot option of as which
can make use of an 32 bit got table, but it doesn't work. I think probably
it works only with -fPIC.

Best Regards
>
> Since my time for FPC development is limited, the progress on MIPS(EL)
> is slow but I do my best to get a native compiler asap. You can get this
> project moving quicker by testing the current MIPS(EL) port as it is
> available from svn and tell me what's going wrong if a program breaks.
>
> If you have any further questions, feel free to ask!
>
> Best regards,
> Florian
>
>> Dear Florian,
>>   How do you do?
>>   I am Fuxin zhang from Lemote. Lemote is a Chinese technical company
>> working on promoting Chinese cpu loongson,which is mips based. Recently
>> we are preparing to port freepascal to linux/mips platform and hope you
>> can give us a hand.
>>   We have already distributed ~150,000 sets of loongson based machines
>> to
>> around 5000 schools in China. As you probably know, freepascal is
>> selected as the formal language/platform of Chinese Olympiad of
>> Informatics. Our users want to be able to use freepascal in loongson
>> machines(with debian linux/mipsel). I think it would be great to
>> support the request.
>>   Lemote can donate necessary hardwares to you to facilitate the
>> development. Also if you can put more time to help us finish the work,
>> we can consider to sponsor you.
>>   We are also preparing to work on this project by ourselves. Could you
>> point us to some documents/reference code for a quick start? I have read
>> www.freepascal.org, but not yet found clear document on porting to a new
>> architecture, or on freepascal design logic etc. I have found a previous
>> code for 0.9.0 by a Chinese guy and trying to find him out to help too.
>>   Thank you very much for creating such a great software!
>>
>> Best Regards
>>
>> Yours Fuxin Zhang
>> CEO of Lemote
>>
>>
>
>






More information about the fpc-devel mailing list