[fpc-devel] DF64 BSD -- FPC running natively but argument address mangling prevents bootstrap
John Marino
fpc-devel at marino.st
Tue Nov 18 13:00:06 CET 2014
Hi guys,
I've spent a couple of days porting FPC to DragonFly BSD with some
success.
> uname -a
DragonFly banshee.x.com 3.9-DEVELOPMENT DragonFly
v3.9.0.710.g6792a-DEVELOPMENT #0: Fri Oct 24 18:32:12 CEST 2014
root at banshee.x.com:/usr/obj/usr/src/sys/X86_64_BANSHEE_SMP
x86_64
> bin/fpc -i
Free Pascal Compiler version 2.6.4
Compiler Date : 2014/11/18
Compiler CPU Target: x86_64
Supported targets:
Linux for x86-64
FreeBSD for x86-64
Win64 for x64
Darwin for x86_64
Solaris for x86-64 (under development)
OpenBSD for x86-64 (under development)
NetBSD for x86-64 (under development)
DragonFly for x86-64
Supported CPU instruction sets:
ATHLON64
Supported FPU instruction sets:
SSE64
SSE3
Supported ABI targets:
DEFAULT
SYSV
AIX
EABI
ARMEB
Supported Optimizations:
REGVAR
STACKFRAME
LOOPUNROLL
TAILREC
CSE
Supported Whole Program Optimizations:
All
DEVIRTCALLS
OPTVMTS
SYMBOLLIVENESS
Supported Microcontroller types:
This program comes under the GNU General Public Licence
For more information read COPYING.v2
Please report bugs in our bug tracker on:
http://bugs.freepascal.org
More information may be found on our WWW pages (including directions
for mailing lists useful for asking questions or discussing potential
new features, etc.):
http://www.freepascal.org
Since DragonFly uses the FreeBSD ports collection, the plan was to start
with patches there and then get most of them into the repository (x86_64
only). However I hit a snag in the middle of the bootstrapping process
and I could use some help. It won't compile because it can't find the
units, but it can't find the units because it can't properly find out if
a directory exists.
> bin/fpc -vut
Configfile search: /home/marino/.fpc.cfg
Configfile search: /usr/local/etc/fpc.cfg
Reading options from file /usr/local/etc/fpc.cfg
Path "./lib/fpc/2.6.4/units/x86_64-dragonfly/" not found
Path "./lib/fpc/2.6.4/units/x86_64-dragonfly/*/" not found
Path "./lib/fpc/2.6.4/units/x86_64-dragonfly/rtl/" not found
Path "/home/marino/.fppkg/lib/fpc/2.6.4/units/x86_64-dragonfly/*/" not
found
Path "/usr/lib/" not found
Path "/lib/" not found
Free Pascal Compiler version 2.6.4 [2014/11/18] for x86_64
Copyright (c) 1993-2014 by Florian Klaempfl and others
Fatal: No source file name in command line
Fatal: Compilation aborted
Error: bin/ppcx64 returned an error exitcode (normal if you did not
specify a source file to be compiled)
I've narrowed down the problem to a malfunctioning strpas command, and
further to the "move" command. I've temporarily disabled the assembly
routines and I'm using the generic "move" command. What's going on is
the move "dest" argument is receiving a different address location than
the procedure that calls it gives. So the string copy works, but it's
getting copied to the wrong location. See below
> gdb bin/fpc
GNU gdb (GDB) 7.6.1
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-dragonfly".
For bug reporting instructions, please see:
<http://bugs.dragonflybsd.org/>...
Reading symbols from /usr/local/bin/fpc...done.
(gdb) set args -vut
(gdb) b generic.inc:886
Breakpoint 1 at 0x403b5f: file ../inc/generic.inc, line 886.
(gdb) r
Starting program: /usr/local/bin/fpc -vut
Breakpoint 1, fpc_shortstr_to_shortstr (RES=..., highRES=255, SSTR=...)
at ../inc/generic.inc:886
886 ../inc/generic.inc: No such file or directory.
(gdb) p sstr
$1 = '/etc/localtime'
(gdb) p slen
$2 = 14
(gdb) p @sstr
$3 = (^SHORTSTRING) 0x658c48 '/etc/localtime'
(gdb) p @res
$4 = (^
OPENSTRING) 0x7ffffffff228
'????'#127#0#0'?????'#127#0#0#27'WD'#0#0#0#0#0'??
Z'#2#1#0#0#0#1#0#0#0'?#'#4#138'?'#129'R'#128#0#0#0#0#0#0#0#0'?????)kT'#0#0#0#0'?
?S&'#0#0#0#0':?qP'#0#0#0#0#8#129'|,'#0#0#0#0':?qP'#0#0#0#0#8#129'|,'#0#0#0#0'6'#
8#0#0#0#0#0#0#4#0#0#0#0#0#0#0#0'@', #0 <repeats 30 times>,
#2#16#0#0#0#0#0#0#3#0
#0#0#0#0#0#0#0#128#0 <repeats 30 times>,
#16'????'#127#0#0#149#143'A'#0#0#0#0#0#
0'?t'#0#8#0#0#0
(gdb) s
MOVE (SOURCE=0, DEST=0, COUNT=15) at ../inc/generic.inc:30
30 in ../inc/generic.inc
(gdb) p @dest
$5 = (^formal) 0x7ffffffff3e0
(gdb) p @source
$6 = (^formal) 0x658c48
(gdb)
As you can see, the address of "dest" should be 0x7ffffffff228 but it
comes as 0x7ffffffff3e0. The address of "source", a constant, is
maintained through the call. For convenience, I've pasted the
interesting code below:
generic.inc: line 879
procedure fpc_shortstr_to_shortstr(out res:shortstring; const sstr:
shortstring
var
slen : byte;
begin
slen:=length(sstr);
if slen>high(res) then
slen:=high(res);
move(sstr[0],res[0],slen+1);
res[0]:=chr(slen);
end;
generic.inc: line 25
procedure Move(const source;var dest;count:SizeInt);[public, alias:
'FPC_MOVE']
var
aligncount : sizeint;
pdest,psrc,pend : pbyte;
begin
// snipped
end;
Maybe "dest" is getting passed by value rather than by reference. Does
anyone have any idea where I can start looking in the code? gdb won't
tell me what source code is responsible for this.
Getting FPC to run as a first-class citizen on DragonFly has been a
long-term goal of mine (ENOTIME) but I'm so close so I hope someone can
help. I also found a couple of mistakes in generic BSD code so my
patches will improve support for other BSDs potentially.
Regards,
John
More information about the fpc-devel
mailing list