View Issue Details

IDProjectCategoryView StatusLast Update
0037694FPCCompilerpublic2020-09-29 11:54
ReporterGuillaume Assigned To 
Status newResolutionopen 
Product Version3.2.0 
Summary0037694: Invalid floating point operation on aarch64 on some machines
DescriptionOn ThunderX2 machines, I always get "Invalid floating point operation" error when I try to build (or use) FPC.

[ 375s] ./fpmake compile --localunitdir=.. --os=linux --cpu=aarch64 -o -Ur -o -Xs -o -O2 -o -n -o -k--build-id -o -k-z -o -knoexecstack -o -daarch64 -o -dRELEASE --compiler=/home/abuild/rpmbuild/BUILD/fpcbuild-3.2.0/fpcsrc/compiler/ppca64 -bu -o -XX -o -CX
[ 375s] Start compiling package a52 for target aarch64-linux.
[ 376s] Compiling a52/src/a52.pas
[ 376s] The installer encountered the following error:
[ 376s] Invalid floating point operation
[ 376s] make[1]: *** [Makefile:1729: smart] Error 1
[ 376s] make[1]: Leaving directory '/home/abuild/rpmbuild/BUILD/fpcbuild-3.2.0/fpcsrc/packages'
[ 376s] make: *** [Makefile:2681: packages_smart] Error 2
Steps To ReproduceTry to build (or use) FPC on a ThunderX2 machine.
TagsNo tags attached.
Fixed in Revision
Attached Files


J. Gareth Moreton

2020-09-03 12:58

developer   ~0125343

Are you able to attempt to compile that unit directly? That might indicate a line number as to where the exception occurs.


2020-09-03 22:07

administrator   ~0125348

Most likely the ThunderX2 machines are an Aarch64 architecture supporting floating point exceptions. This is not tested yet with FPC. Is there a way to get a login on such machine to fix this?


2020-09-09 14:45

reporter   ~0125449

I cannot give access to this machine as it is on a local network, unreachable from the Internet. But I can run some commands for you, if needed.

I tried `fpc a52.pas` manually and it passed and created a52.o and a52.ppu files:
  Free Pascal Compiler version 3.2.0 [2020/08/25] for aarch64
  Copyright (c) 1993-2020 by Florian Klaempfl and others
  Target OS: Linux for AArch64
  Compiling a52.pas
  Assembling a52
  511 lines compiled, 0.1 sec


2020-09-09 19:09

administrator   ~0125452

Can you try to execute the command

./fpmake compile --localunitdir=.. --os=linux --cpu=aarch64 -o -Ur -o -Xs -o -O2 -o -n -o -k--build-id -o -k-z -o -knoexecstack -o -daarch64 -o -dRELEASE --compiler=/home/abuild/rpmbuild/BUILD/fpcbuild-3.2.0/fpcsrc/compiler/ppca64 -bu -o -XX -o -CX

with gdb in the directory /home/abuild/rpmbuild/BUILD/fpcbuild-3.2.0/fpcsrc and post the disassembly if it crashes?


2020-09-15 14:02

reporter   ~0125548

Last edited: 2020-09-15 15:21

View 3 revisions

Here are the results from GDB:
Starting program: /home/abuild/rpmbuild/BUILD/fpcbuild-3.2.0/fpcsrc/packages/fpmake compile --localunitdir=.. --os=linux --cpu=aarch64 -o -Ur -o -Xs -o -O2 -o -n -o -k--build-id -o -k-z -o -knoexecstack -o -daarch64 -o -dRELEASE --compiler=/home/abuild/rpmbuild/BUILD/fpcbuild-3.2.0/fpcsrc/compiler/ppca64 -bu -o -XX -o -CX
Missing separate debuginfos, use: zypper install glibc-debuginfo-2.31-6.4.aarch64
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/".
[Detaching after fork from child process 29296]
Program received signal SIGFPE, Arithmetic exception.
(gdb) where
0000001 0x00000000004afd5c in SYSUTILS_$$_ENCODETIME$WORD$WORD$WORD$WORD$$TDATETIME ()
0000007 0x000000000050d1e8 in FPMKUNIT$_$TBUILDENGINE_$__$$_MAYBECOMPILE$TPACKAGE ()
0000008 0x0000000000510228 in FPMKUNIT$_$TBUILDENGINE_$__$$_COMPILE$TPACKAGES ()
0000009 0x00000000005022d4 in FPMKUNIT$_$TCUSTOMINSTALLER_$__$$_COMPILE$BOOLEAN ()
0000010 0x0000000000502854 in FPMKUNIT$_$TCUSTOMINSTALLER_$__$$_RUN$$BOOLEAN ()
0000011 0x00000000004632e4 in main ()

And disassemble:
   0x00000000004afbd8 <+0>: stp x29, x30, [sp, #-16]!
   0x00000000004afbdc <+4>: mov x29, sp
   0x00000000004afbe0 <+8>: uxth w5, w0
   0x00000000004afbe4 <+12>: uxth w1, w1
   0x00000000004afbe8 <+16>: uxth w2, w2
   0x00000000004afbec <+20>: uxth w3, w3
   0x00000000004afbf0 <+24>: cmp w5, #0x18
   0x00000000004afbf4 <+28>: b.cs 0x4afc18 <SYSUTILS_$$_TRYENCODETIME$WORD$WORD$WORD$WORD$TDATETIME$$BOOLEAN+64> // b.hs, b.nlast
   0x00000000004afbf8 <+32>: cmp w1, #0x3c
   0x00000000004afbfc <+36>: b.cs 0x4afc18 <SYSUTILS_$$_TRYENCODETIME$WORD$WORD$WORD$WORD$TDATETIME$$BOOLEAN+64> // b.hs, b.nlast
   0x00000000004afc00 <+40>: cmp w2, #0x3c
   0x00000000004afc04 <+44>: b.cs 0x4afc18 <SYSUTILS_$$_TRYENCODETIME$WORD$WORD$WORD$WORD$TDATETIME$$BOOLEAN+64> // b.hs, b.nlast
   0x00000000004afc08 <+48>: cmp w3, #0x3e8
   0x00000000004afc0c <+52>: b.cs 0x4afc18 <SYSUTILS_$$_TRYENCODETIME$WORD$WORD$WORD$WORD$TDATETIME$$BOOLEAN+64> // b.hs, b.nlast
   0x00000000004afc10 <+56>: mov w0, #0x1 // 0000001
   0x00000000004afc14 <+60>: b 0x4afc1c <SYSUTILS_$$_TRYENCODETIME$WORD$WORD$WORD$WORD$TDATETIME$$BOOLEAN+68>
   0x00000000004afc18 <+64>: mov w0, #0x0 // #0
   0x00000000004afc1c <+68>: cmp w0, #0x0
   0x00000000004afc20 <+72>: b.eq 0x4afc64 <SYSUTILS_$$_TRYENCODETIME$WORD$WORD$WORD$WORD$TDATETIME$$BOOLEAN+140> // b.none
   0x00000000004afc24 <+76>: mov w6, #0xee80 // #61056
   0x00000000004afc28 <+80>: movk w6, #0x36, lsl 0000016
   0x00000000004afc2c <+84>: umull x6, w5, w6
   0x00000000004afc30 <+88>: mov w5, #0xea60 // #60000
   0x00000000004afc34 <+92>: umull x1, w1, w5
   0x00000000004afc38 <+96>: add x5, x1, x6
   0x00000000004afc3c <+100>: mov w1, #0x3e8 // 0001000
   0x00000000004afc40 <+104>: umull x1, w2, w1
   0x00000000004afc44 <+108>: add x1, x1, x5
   0x00000000004afc48 <+112>: add x1, x3, x1
   0x00000000004afc4c <+116>: scvtf d1, x1
   0x00000000004afc50 <+120>: adrp x1, 0x5bf000
   0x00000000004afc54 <+124>: ldr x1, [x1, 0002072]
   0x00000000004afc58 <+128>: ldur d0, [x1]
=> 0x00000000004afc5c <+132>: fdiv d0, d1, d0
   0x00000000004afc60 <+136>: str d0, [x4]
   0x00000000004afc64 <+140>: ldp x29, x30, [sp], 0000016
   0x00000000004afc68 <+144>: ret
End of assembler dump.

And register values:
(gdb) info registers
x0 0x1 1
x1 0x58eb38 5827384
x2 0x12 18
x3 0x0 0
x4 0xffffffffea80 281474976705152
x5 0x301f560 50460000
x6 0x3010b00 50400000
x7 0x5 5
x8 0x99 153
x9 0xd080 53376
x10 0x0 0
x11 0x10 16
x12 0xfffff7f8aee0 281474842013408
x13 0x0 0
x14 0x0 0
x15 0x0 0
x16 0x1 1
x17 0xfffff7f01930 281474841450800
x18 0x0 0
x19 0x0 0
x20 0x12 18
x21 0x1 1
x22 0xe 14
x23 0x0 0
x24 0x0 0
x25 0x0 0
x26 0x0 0
x27 0x0 0
x28 0x0 0
x29 0xffffffffea70 281474976705136
x30 0x4afd5c 4914524
sp 0xffffffffea70 0xffffffffea70
cpsr 0x20000000 [ EL=0 C ]
fpsr 0x0 0
fpcr 0x9f00 40704

(gdb) info all-registers d0 d1
d0 {f = 0x5265c00, u = 0x4194997000000000, s = 0x4194997000000000} {f = 86400000, u = 4725570615333879808, s = 4725570615333879808}
d1 {f = 0x3023bb0, u = 0x418811dd80000000, s = 0x418811dd80000000} {f = 50478000, u = 4722043852330893312, s = 4722043852330893312}


2020-09-15 23:23

administrator   ~0125558

Ok, apparently the CPU does indeed support FPU exceptions (fpcr=0x9f00). Is there any chance that you test with trunk? r43167 should have fixed this.


2020-09-16 11:04

reporter   ~0125569

Unfortunately, the build is not successful with current trunk due to a link error:
[ 776s] /usr/bin/mkdir -p units_bs/aarch64-linux
[ 776s] /home/abuild/rpmbuild/BUILD/fpcbuild-3.2.0/fpcsrc/compiler/ppca64 src/fpmkunit.pp -n -Fu/home/abuild/rpmbuild/BUILD/fpcbuild-3.2.0/fpcsrc/rtl/units/aarch64-linux -FUunits_bs/aarch64-linux -Fu../paszlib/src -Fu../hash/src -Fi../paszlib/src -Fl/usr/lib64/gcc/aarch64-suse-linux/10 -Fi../fcl-process/src/unix -Fu../fcl-process/src -Fi../fcl-process/src/linux -Fi../fcl-process/src/dummy -Fu../libtar/src -k--build-id -k-z -knoexecstack
[ 781s] make[2]: Leaving directory '/home/abuild/rpmbuild/BUILD/fpcbuild-3.2.0/fpcsrc/packages/fpmkunit'
[ 781s] /home/abuild/rpmbuild/BUILD/fpcbuild-3.2.0/fpcsrc/compiler/ppca64 fpmake.pp -n -Fu/home/abuild/rpmbuild/BUILD/fpcbuild-3.2.0/fpcsrc/packages/fpmkunit/units_bs/aarch64-linux -Fu/home/abuild/rpmbuild/BUILD/fpcbuild-3.2.0/fpcsrc/rtl/units/aarch64-linux -Fl/usr/lib64/gcc/aarch64-suse-linux/10 -k--build-id -k-z -knoexecstack
[ 791s] /usr/bin/ld: /usr/lib64/libc_nonshared.a(elf-init.oS): in function `__libc_csu_init':
[ 791s] /home/abuild/rpmbuild/BUILD/glibc-2.31/csu/elf-init.c:83: undefined reference to `_init'
[ 791s] fpmake.pp(60) Error: Error while linking
[ 791s] fpmake.pp(60) Fatal: There were 1 errors compiling module, stopping
[ 791s] Fatal: Compilation aborted

BTW, ppc64le is also affected by this link error with 3.2.0.


2020-09-16 19:34

administrator   ~0125574

Even if the directory name is /home/abuild/rpmbuild/BUILD/fpcbuild-3.2.0, it are the trunk sources? I suppose you have a libc6-dev package installed? If both yes, please run

/home/abuild/rpmbuild/BUILD/fpcbuild-3.2.0/fpcsrc/compiler/ppca64 fpmake.pp -n -Fu/home/abuild/rpmbuild/BUILD/fpcbuild-3.2.0/fpcsrc/packages/fpmkunit/units_bs/aarch64-linux -Fu/home/abuild/rpmbuild/BUILD/fpcbuild-3.2.0/fpcsrc/rtl/units/aarch64-linux -Fl/usr/lib64/gcc/aarch64-suse-linux/10 -k--build-id -k-z -knoexecstack

by hand in /home/abuild/rpmbuild/BUILD/fpcbuild-3.2.0/fpcsrc/packages and post the output.


2020-09-18 12:47

reporter   ~0125612

Yes, glibc-devel package is installed as usual and I copied trunk sources in 3.2.0 fpcsrc/ folder to keep the 3.2.0 build structure.

/home/abuild/rpmbuild/BUILD/fpcbuild-3.2.0/fpcsrc/compiler/ppca64 fpmake.pp -n -Fu/home/abuild/rpmbuild/BUILD/fpcbuild-3.2.0/fpcsrc/packages/fpmkunit/units_bs/aarch64-linux -Fu/home/abuild/rpmbuild/BUILD/fpcbuild-3.2.0/fpcsrc/rtl/units/aarch64-linux -Fl/usr/lib64/gcc/aarch64-suse-linux/10 -k--build-id -k-z -knoexecstack


/usr/bin/ld: /usr/lib64/libc_nonshared.a(elf-init.oS): in function `__libc_csu_init':
/home/abuild/rpmbuild/BUILD/glibc-2.31/csu/elf-init.c:83: undefined reference to `_init'
fpmake.pp(60) Error: Error while linking
fpmake.pp(60) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted

And I forgot to mention that this undefined reference happens on any aarch64 machine.


2020-09-18 20:43

administrator   ~0125629

There is no compiler warning before? Can you check please, where crti.o is located on the machine?


2020-09-21 09:48

reporter   ~0125697

No warning before.

The file is located at: /usr/lib64/crti.o


2020-09-22 15:02

reporter   ~0125755

Last edited: 2020-09-22 15:24

View 2 revisions

For the link failure, I just need to apply this patch:

diff -Nru fpcbuild-3.2.0.orig/fpcsrc/compiler/systems/t_linux.pas fpcbuild-3.2.0/fpcsrc/compiler/systems/t_linux.pas
--- fpcbuild-3.2.0.orig/fpcsrc/compiler/systems/t_linux.pas 2019-12-05 21:11:43.000000000 +0100
+++ fpcbuild-3.2.0/fpcsrc/compiler/systems/t_linux.pas 2020-06-25 18:33:04.362536867 +0200
@@ -142,8 +142,15 @@
-{$else powerpc64}
+{$ifdef aarch64}
+ LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib',true);
+ LibrarySearchPath.AddLibraryPath(sysrootpath,'=/lib',true);
+ LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib64',true);
+ LibrarySearchPath.AddLibraryPath(sysrootpath,'=/lib64',true);
+{$endif aarch64}
 {$endif powerpc64}
 {$endif x86_64}
@@ -223,7 +230,7 @@
 {$endif arm}
 {$ifdef aarch64}
-const defdynlinker='/lib/';
+const defdynlinker='/lib64/';
 {$endif aarch64}
 {$ifdef mips}

Any chance to merge it upstream?

Regarding the Floating Point error, if I build r43167 on a standard aarch64 and then use this fpc to rebuild fpc on a ThunderX2 machine, I get:
[ 150s] ppca64 -Ur -Ur -Xs -O2 -n -Fi../inc -Fi../aarch64 -Fi../unix -Fiaarch64 -FE. -FU/home/abuild/rpmbuild/BUILD/fpcbuild-3.2.0/fpcsrc/rtl/units/aarch64-linux -Fl/usr/lib64/gcc/aarch64-suse-linux/10 -k--build-id -k-z -knoexecstack -gl -daarch64 -dRELEASE -Us -Sg system.pp
[ 151s],7) Error: Compilation raised exception internally
[ 151s] Fatal: Compilation aborted
[ 151s] An unhandled exception occurred at $0000000000550D60:
[ 151s] EInvalidOp: Invalid floating point operation
[ 151s] $0000000000550D60
[ 151s] $00000000005CE1BC
[ 151s] $00000000005D02BC
[ 151s] $00000000005D02E0
[ 151s] $00000000005D02E0
[ 151s] $00000000005D02E0
[ 151s] $00000000005D1374
[ 151s] $00000000005E0030
[ 151s] $00000000005E02E0
[ 151s] $00000000005E41DC
[ 151s] $00000000005C6218
[ 151s] $00000000005B8324
[ 151s] $00000000005B7EA8
[ 151s] $0000000000538360
[ 151s] $0000000000533268
[ 151s] $00000000005373E0
[ 151s] $00000000005FD118

I will probably give a try to latest snapshot instead:


2020-09-22 20:27

administrator   ~0125760

Regarding the linking error: did you use latest trunk? Because I fixed there already the path issue with crti.o. Are there any other issues with linking? Changing the dyn. linker is a problem as e.g. on Debian Aarch64 the dyn. linker is located in /lib/.

Regarding the floating point error, testing with r43167 makes no sense, we are meanwhile at r46916. Please test always with latest trunk.

To avoid confusion: let's do things step by step: just try to build trunk (e.g. with the snapshot) and check where it breaks.


2020-09-23 17:05

reporter   ~0125780

With current trunk, it builds fine!

Are there some patches to backport to 3.2.0 to fix this issue, or is it too much?
Also, any ETA for a new release including this fix?


2020-09-25 08:29

reporter   ~0125832

I managed to fix the build with few backports!

Thanks for your help.


2020-09-26 16:24

administrator   ~0125877

Which revisions did you merge? I would like to merge those to official fixes.


2020-09-29 11:54

reporter   ~0125955

Here is the update on our build system:
You have the 2 patches added there.

It is and with few modifications to apply properly.

Issue History

Date Modified Username Field Change
2020-09-03 09:07 Guillaume New Issue
2020-09-03 12:58 J. Gareth Moreton Note Added: 0125343
2020-09-03 22:07 Florian Note Added: 0125348
2020-09-09 14:45 Guillaume Note Added: 0125449
2020-09-09 19:09 Florian Note Added: 0125452
2020-09-15 14:02 Guillaume Note Added: 0125548
2020-09-15 14:12 Guillaume Note Edited: 0125548 View Revisions
2020-09-15 15:21 Guillaume Note Edited: 0125548 View Revisions
2020-09-15 23:23 Florian Note Added: 0125558
2020-09-16 11:04 Guillaume Note Added: 0125569
2020-09-16 19:34 Florian Note Added: 0125574
2020-09-18 12:47 Guillaume Note Added: 0125612
2020-09-18 20:43 Florian Note Added: 0125629
2020-09-21 09:48 Guillaume Note Added: 0125697
2020-09-22 15:02 Guillaume Note Added: 0125755
2020-09-22 15:24 Guillaume Note Edited: 0125755 View Revisions
2020-09-22 20:27 Florian Note Added: 0125760
2020-09-23 17:05 Guillaume Note Added: 0125780
2020-09-25 08:29 Guillaume Note Added: 0125832
2020-09-26 16:24 Florian Note Added: 0125877
2020-09-29 11:54 Guillaume Note Added: 0125955