[fpc-pascal] ARM Linux crosscompiler: compiles but... executable gives segmentation fault

Reinier Olislagers reinierolislagers at gmail.com
Fri Jan 10 13:27:01 CET 2014


Hi all,

For the Dutch among us: de dag die je wist dat zou komen...

Thanks to earlier help I got to build an ARM Linux cross compiler module
in fpcup which even compiles fpcup itself (both using trunk and stable
starting compiler):
opt="-fPIC -dFPC_ARMHF"
crossopt="-CpARMV6 -CaEABIHF -CfVFPV2"

fpc -g -gl -Tlinux -Parm simple.lpr

Question: should I have compiled with -fPIC?

Uploaded resulting executable
http://ubuntuone.com/0y3yXGcU8fEXR6OTMyvfGN

The program:
program simple;

begin
  writeln('hello');
end.

Relevant fpc.cfg snippet:
#IFDEF CPUARM
#IFDEF LINUX
-CpARMV6
-CaEABIHF
-CfVFPV2
-FDC:\development\cross\bin\arm-linux\
-XParm-linux-
-Xd
-FlC:\development\cross\lib\arm-linux\
-Xr/usr/lib
#ENDIF
#ENDIF

However, running the resulting binary on my virtual Raspbian fails with
a segmentation fault. Running under gdb gives
(gdb) run
Starting program: /root/simple

Program received signal SIGSEGV, Segmentation fault.
0x0002b6e4 in
SYSTEM_$$_ARRAYSTRINGTOPPCHAR$array_of_ANSISTRING$LONGINT$$PPCHAR ()
(gdb) bt
#0  0x0002b6e4 in
SYSTEM_$$_ARRAYSTRINGTOPPCHAR$array_of_ANSISTRING$LONGINT$$PPCHAR ()
#1  0x00008124 in _start ()


On the raspbian (which is built on hardfloat), file gives
simple: ELF 32-bit LSB executable, ARM, version 1 (SYSV), statically
linked, for GNU/Linux 2.0.0, not stripped

Compare with system-provided binary:
file /usr/bin/yes
/usr/bin/yes: ELF 32-bit LSB executable, ARM, version 1 (SYSV),
dynamically linked (uses shared libs), for GNU/Linux 2.6.26,
BuildID[sha1]=0xf2df9a56df5c7b5490f7dba10f2163acb8971fce, stripped

Question: should I be worried about the GNU/Linux 2.0.0 above?

ldd simple
        not a dynamic executable

I've run
readelf -a simple
uploaded to
http://ubuntuone.com/1cAX24nbcPkGo05fFWDbOr

readelf -a /usr/bin/yes
uploaded to
http://ubuntuone.com/6FD65xgakyE9eZOIme2z47

Question: what steps should I take now?

Thanks



More information about the fpc-pascal mailing list