Bug 239135

Summary: lang/fpc build failure on FBSD 11.2
Product: Ports & Packages Reporter: Trev <fbsdbugs4>
Component: Individual Port(s)Assignee: Jose Alonso Cardenas Marquez <acm>
Status: Closed FIXED    
Severity: Affects Only Me CC: acm, grahamperrin, w.schwarzenfeld
Priority: --- Flags: bugzilla: maintainer-feedback? (acm)
Version: Latest   
Hardware: Any   
OS: Any   

Description Trev 2019-07-11 05:44:38 UTC
The included bootstrap compiler binary:
-rwxr-xr-x  1 1106  493    3386488 28 Nov  2017 ppcx64-3.0.4-freebsd

Cannot build anything - it simply core dumps with "Bad system call (core dumped)".

Truss reveals:

$ truss ./work/ppcx64-3.0.4-freebsd
sigaction(SIGFPE,{ 0x4224f0 SA_SIGINFO ss_t },{ SIG_DFL 0x0 ss_t }) = 0 (0x0)
sigaction(SIGSEGV,{ 0x4224f0 SA_SIGINFO ss_t },{ SIG_DFL 0x0 ss_t }) = 0 (0x0)
sigaction(SIGBUS,{ 0x4224f0 SA_SIGINFO ss_t },{ SIG_DFL 0x0 ss_t }) = 0 (0x0)
sigaction(SIGILL,{ 0x4224f0 SA_SIGINFO ss_t },{ SIG_DFL 0x0 ss_t }) = 0 (0x0)
ioctl(1,TIOCGETA,0x7fffffffe4a0)         = 0 (0x0)
ioctl(2,TIOCGETA,0x7fffffffe4a0)         = 0 (0x0)
ioctl(1,TIOCGETA,0x7fffffffe4a0)         = 0 (0x0)
ioctl(2,TIOCGETA,0x7fffffffe4a0)         = 0 (0x0)
compat6.mmap()                           ERR#78 'Function not implemented'
SIGNAL 12 (SIGSYS) code=SI_KERNEL
process killed, signal = 12 (core dumped)

I installed /usr/ports/misc/compat6x - no change.
Comment 1 Trev 2019-07-21 09:00:15 UTC
The solution was to uncomment these kernel options (they are uncommented in a  GENERIC kernel) and rebuild my kernel.

##options       COMPAT_FREEBSD32        # Compatible with i386 binaries
##options       COMPAT_FREEBSD4         # Compatible with FreeBSD4
##options       COMPAT_FREEBSD5         # Compatible with FreeBSD5
##options       COMPAT_FREEBSD6         # Compatible with FreeBSD6
##options       COMPAT_FREEBSD7         # Compatible with FreeBSD7
##options       COMPAT_FREEBSD9         # Compatible with FreeBSD9
##options       COMPAT_FREEBSD10        # Compatible with FreeBSD10

It seems the FPC binaries are calling some very old FreeBSD system calls dating back some 11 years.
Comment 2 Jose Alonso Cardenas Marquez freebsd_committer freebsd_triage 2019-08-15 19:27:26 UTC
I have committed new changes to lang/fpc and editors/lazarus ports. Please, see it at:

https://svnweb.freebsd.org/ports?view=revision&revision=509004
https://svnweb.freebsd.org/ports?view=revision&revision=509005
https://svnweb.freebsd.org/ports?view=revision&revision=509007

It doesn't work with lld and maybe will not work on short time. We must be use binutils from base or from ports and change LDPATH into fpc/Makefile to ld.bfd path. Also I have regenerated fpc bootstrap (i386 and amd64) . It should be work only with COMPAT_FREEBSD11 added to kernel config on 12.X+ (COMPAT from 4 to 10 should not be necessary)

I have removed LD_UNSAFE because now we can set LDPATH to a working linker (It works with ld.bfd from base or installed from binutils port)
Comment 3 Trev 2019-08-16 02:10:09 UTC
Builds with no issues under FreeBSD 12.0p9 (GENERIC kernel)

Fails to build under FreeBSD 11.3-STABLE #7 r349943 due to bootstrap compiler 

-rwxr-xr-x  1 root  wheel  3710776 15 Aug 12:37 /usr/ports/lang/fpc/work/ppcx64-3.0.4-freebsd

core dumping due to:

root@shadow [/usr/ports/editors/lazarus] $ truss /usr/ports/lang/fpc/work/ppcx64-3.0.4-freebsd
sigaction(SIGFPE,{ 0x429630 SA_SIGINFO ss_t },{ SIG_DFL 0x0 ss_t }) = 0 (0x0)
sigaction(SIGSEGV,{ 0x429630 SA_SIGINFO ss_t },{ SIG_DFL 0x0 ss_t }) = 0 (0x0)
sigaction(SIGBUS,{ 0x429630 SA_SIGINFO ss_t },{ SIG_DFL 0x0 ss_t }) = 0 (0x0)
sigaction(SIGILL,{ 0x429630 SA_SIGINFO ss_t },{ SIG_DFL 0x0 ss_t }) = 0 (0x0)
ioctl(1,TIOCGETA,0x7fffffffe464)                 = 0 (0x0)
ioctl(2,TIOCGETA,0x7fffffffe464)                 = 0 (0x0)
ioctl(1,TIOCGETA,0x7fffffffe464)                 = 0 (0x0)
ioctl(2,TIOCGETA,0x7fffffffe464)                 = 0 (0x0)
compat6.mmap()                                   ERR#78 'Function not implemented'
SIGNAL 12 (SIGSYS) code=SI_KERNEL
process killed, signal = 12 (core dumped)

Kernel Options:

##options       COMPAT_FREEBSD32        # Compatible with i386 binaries
##options       COMPAT_FREEBSD4         # Compatible with FreeBSD4
##options       COMPAT_FREEBSD5         # Compatible with FreeBSD5
##options       COMPAT_FREEBSD6         # Compatible with FreeBSD6
##options       COMPAT_FREEBSD7         # Compatible with FreeBSD7
##options       COMPAT_FREEBSD9         # Compatible with FreeBSD9
options         COMPAT_FREEBSD10        # Compatible with FreeBSD10
Comment 4 Trev 2019-08-16 06:46:01 UTC
To prevent the bootstrap compiler core dumping I have determined that I need to build a kernel with:

options COMPAT_FREEBSD6         # Compatible with FreeBSD6

and

options COMPAT_FREEBSD7         # Compatible with FreeBSD7

COMPAT_FREEBSD7 was necessary because the kernel would fail to build without it once I added COMPAT_FREEBSD6.
Comment 5 Trev 2019-10-11 06:07:02 UTC
I've tracked down the source of the COMPAT6 dependency to:

/usr/local/share/fpc-3.0.4/rtl/freebsd/sysnr.inc

which includes:

syscall_nr_mmap                        = 197;

and that system call belongs to COMPAT6 (see https://github.com/freebsd/freebsd/blob/master/sys/kern/syscalls.master)

The "standard" mmap system call number is 477.
Comment 6 commit-hook freebsd_committer freebsd_triage 2019-12-31 15:12:20 UTC
A commit references this bug:

Author: acm
Date: Tue Dec 31 15:11:25 UTC 2019
New revision: 521624
URL: https://svnweb.freebsd.org/changeset/ports/521624

Log:
  - Change LDPATH to FPC_LDPATH into lang/fpc/Makefile. It can be changed from
    /etc/make.conf
  - Add FPC_LDPATH to freepascal compiler. By default it is defined to
    %%LOCALBASE%%/bin/ld.bfd but it can be changed setting FPC_LDPATH environment
    variable
  - Remove compatX dependencies from bootstrap and compiler. It could fix problems
    when GENERIC kernel is not used [1]
  - Rebuild bootstrap (ppcx64 and ppc386) with new changes
  - Bump PORTREVISION

  PR:		239135
  Submitted by:	fbsdbugs4 __at__ sentry.org

Changes:
  head/databases/fpc-fpindexer/Makefile
  head/databases/fpc-gdbm/Makefile
  head/databases/fpc-ibase/Makefile
  head/databases/fpc-postgres/Makefile
  head/devel/fpc-fcl-db/Makefile
  head/devel/fpc-fcl-js/Makefile
  head/devel/fpc-fcl-json/Makefile
  head/devel/fpc-fcl-passrc/Makefile
  head/devel/fpc-fcl-pdf/Makefile
  head/devel/fpc-fcl-sdo/Makefile
  head/devel/fpc-fcl-stl/Makefile
  head/devel/fpc-fcl-web/Makefile
  head/devel/fpc-fppkg/Makefile
  head/devel/fpc-sdl/Makefile
  head/games/hedgewars/Makefile
  head/graphics/fpc-imagemagick/Makefile
  head/lang/fpc/Makefile
  head/lang/fpc/Makefile.units
  head/lang/fpc/distinfo
  head/lang/fpc/files/patch-compiler_systems_t__bsd.pas
  head/lang/fpc/files/pkg-message.in
  head/lang/fpc-rtl-objpas/Makefile
  head/lang/fpc-utils/Makefile
  head/lang/nbc/Makefile
  head/multimedia/fpc-libvlc/Makefile
  head/science/checkmol/Makefile
  head/science/checkmol/distinfo
  head/science/mol2ps/Makefile
  head/www/fpc-googleapi/Makefile
  head/x11/fpc-x11/Makefile
Comment 7 Jose Alonso Cardenas Marquez freebsd_committer freebsd_triage 2019-12-31 15:15:17 UTC
Hi Trev

Could you test my latest fpc commit? It should works now. Thanks!
Comment 8 Trev 2020-01-04 22:12:12 UTC
(In reply to Jose Alonso Cardenas Marquez from comment #7)
Sure, will test in the next couple of days (need to compile a new kernel).
Comment 9 Trev 2020-02-17 04:57:31 UTC
Sorry it took so long.

The system is now on:
12.1-STABLE FreeBSD 12.1-STABLE #3 r358002: Mon Feb 17 08:48:46 AEDT 2020

cd /usr/ports/editors/lazarus

$ make
===>   lazarus-gtk2-2.0.6 depends on file: /usr/local/bin/as - found
===>   lazarus-gtk2-2.0.6 depends on executable: fpcres - not found
===>   fpc-utils-3.0.4_5 depends on file: /usr/local/bin/as - found
===>   fpc-utils-3.0.4_5 depends on executable: ppcx64 - not found
===>  Building for fpc-3.0.4_3
##### STARTING COMPILER #####

[chomp]

gmake[8]: Entering directory '/usr/ports/lang/fpc/work/fpc-3.0.4/rtl'
gmake -C freebsd all
gmake[9]: Entering directory '/usr/ports/lang/fpc/work/fpc-3.0.4/rtl/freebsd'
as -o ../../rtl/units/x86_64-freebsd/prt0.o x86_64/prt0.as
as -o ../../rtl/units/x86_64-freebsd/cprt0.o x86_64/cprt0.as
as -o ../../rtl/units/x86_64-freebsd/gprt0.o x86_64/gprt0.as
as -o ../../rtl/units/x86_64-freebsd/dllprt0.o x86_64/dllprt0.as
/usr/ports/lang/fpc/work/ppcx64-3.0.4-freebsd -dNOMOUSE -Fi../inc -Fi../x86_64 -Fi../unix -Fi../bsd -Fi../bsd/x86_64 -Fi../freebsd/x86_64 -FE. -FU../../rtl/units/x86_64-freebsd -Cg -dx86_64 -Us -Sg ../bsd/system.pp
gmake[9]: *** [Makefile:2959: system.ppu] Bad system call (core dumped)
gmake[9]: Leaving directory '/usr/ports/lang/fpc/work/fpc-3.0.4/rtl/freebsd'
gmake[8]: *** [Makefile:2108: freebsd_all] Error 2
gmake[8]: Leaving directory '/usr/ports/lang/fpc/work/fpc-3.0.4/rtl'
gmake[7]: *** [Makefile:4077: rtl] Error 2
gmake[7]: Leaving directory '/usr/ports/lang/fpc/work/fpc-3.0.4/compiler'
gmake[6]: *** [Makefile:3970: next] Error 2
gmake[6]: Leaving directory '/usr/ports/lang/fpc/work/fpc-3.0.4/compiler'
gmake[5]: *** [Makefile:3975: ppc1] Error 2
gmake[5]: Leaving directory '/usr/ports/lang/fpc/work/fpc-3.0.4/compiler'
gmake[4]: *** [Makefile:3987: cycle] Error 2
gmake[4]: Leaving directory '/usr/ports/lang/fpc/work/fpc-3.0.4/compiler'
*** Error code 2

The kernel has these options:
options         COMPAT_FREEBSD10        # Compatible with FreeBSD10
options         COMPAT_FREEBSD11        # Compatible with FreeBSD11
Comment 10 Trev 2020-02-17 05:05:44 UTC
Running the line which dies with truss shows:

access("../bsd/system.pp",F_OK)                  = 0 (0x0)
open("../bsd/system.pp",O_RDONLY,0666)           = 3 (0x3)
read(3,"{\n    This file is part of the "...,32768) = 8389 (0x20c5)
compat11.fstat(3,{ mode=-rw-rw-r-- ,inode=10035660,size=8389,blksize=32768 }) = 0 (0x0)
compat6.lseek()                                  ERR#78 'Function not implemented'
SIGNAL 12 (SIGSYS) code=SI_KERNEL
process killed, signal = 12 (core dumped)
Comment 11 Jose Alonso Cardenas Marquez freebsd_committer freebsd_triage 2020-02-24 21:50:36 UTC
Hi, I put a new version of fpc ports at the following url:

https://people.freebsd.org/~acm/ports/freepascal/

1) Copy ppc*-freebsd.tar.gz files at /usr/ports/distfiles/freepascal
2) Uncompress fpc.tar.gz and copy fpc directory to /usr/ports/lang/
3) cd /usr/ports/lang/fpc && make install clean clean-depends

It should works fine on FreeBSD 11.x and FreeBSD 12.x (COMPAT11.X should be enable in KERNEL). COMPAT < 11 should not neccesary

Please test it and tell me if it works for you
Comment 12 Trev 2020-03-04 02:23:37 UTC
Success! Yes, this version compiles perfectly and my tests using it were all successful. Thank you very much for your efforts.

Just a note on the blurb displayed after installing: 

"1) Add lib paths to /usr/local/etc/fpc.cfg

   # searchpath for libraries
   -Fl/usr/local/lib
 
    This is necessary for correct linking of libraries."

When I checked fpc.cfg, this path was already there as follows:

"# searchpath for libraries
#-Fl/usr/local/lib/fpc/$fpcversion/lib
#-Fl/lib;/usr/lib
-Fl/usr/local/lib;/usr/local/lib/qt4;/usr/local/lib/qt5/fpc/$fpcversion/lib/$FPCTARGET"

So maybe that first note is not needed.

Additionally, while trying to retrieve the source some of the mirrors no longer exist and others failed to connect as follows:

=> fpc-3.0.4.source.tar.gz doesn't seem to exist in /usr/ports/distfiles/freepascal.
=> Attempting to fetch ftp://ftp.freepascal.org/pub/fpc/dist/3.0.4/source/fpc-3.0.4.source.tar.gz
fetch: ftp://ftp.freepascal.org/pub/fpc/dist/3.0.4/source/fpc-3.0.4.source.tar.gz: Can't open data connection
=> Attempting to fetch ftp://planetmirror.com/pub/fpc/dist/3.0.4/source/fpc-3.0.4.source.tar.gz
fetch: ftp://planetmirror.com/pub/fpc/dist/3.0.4/source/fpc-3.0.4.source.tar.gz: No address record
=> Attempting to fetch ftp://ftp.jp.freepascal.org/mirror/fpc/dist/3.0.4/source/fpc-3.0.4.source.tar.gz
fetch: ftp://ftp.jp.freepascal.org/mirror/fpc/dist/3.0.4/source/fpc-3.0.4.source.tar.gz: Operation timed out
=> Attempting to fetch ftp://freepascal.stack.nl/pub/fpc/dist/3.0.4/source/fpc-3.0.4.source.tar.gz
fetch: ftp://freepascal.stack.nl/pub/fpc/dist/3.0.4/source/fpc-3.0.4.source.tar.gz: No address record
=> Attempting to fetch ftp://ftp.no.freepascal.org/pub/fpc/dist/3.0.4/source/fpc-3.0.4.source.tar.gz
fetch: ftp://ftp.no.freepascal.org/pub/fpc/dist/3.0.4/source/fpc-3.0.4.source.tar.gz: Operation timed out
=> Attempting to fetch ftp://ftp.us.freepascal.org/pub/fpc/dist/3.0.4/source/fpc-3.0.4.source.tar.gz
fetch: ftp://ftp.us.freepascal.org/pub/fpc/dist/3.0.4/source/fpc-3.0.4.source.tar.gz: No route to host
=> Attempting to fetch https://downloads.sourceforge.net/project/freepascal/Source/3.0.4/fpc-3.0.4.source.tar.gz
fpc-3.0.4.source.tar.gz                                 38 MB 2681 kBps    15s
Comment 13 commit-hook freebsd_committer freebsd_triage 2020-03-06 06:26:28 UTC
A commit references this bug:

Author: acm
Date: Fri Mar  6 06:26:16 UTC 2020
New revision: 527858
URL: https://svnweb.freebsd.org/changeset/ports/527858

Log:
  - Remove compat < 11 dependencies from bootstrap and compiler. It could fix problems
    when GENERIC kernel is not used.
  - Rebuild bootstrap (ppcx64 and ppc386) with new changes
  - Bump PORTREVISION

  PR:		239135
  Reported by:	fbsdbugs4  at  sentry.org

Changes:
  head/archivers/peazip/Makefile
  head/cad/zcad/Makefile
  head/comms/cqrlog/Makefile
  head/databases/fpc-fpindexer/Makefile
  head/databases/fpc-gdbm/Makefile
  head/databases/fpc-ibase/Makefile
  head/databases/fpc-postgres/Makefile
  head/devel/fpc-fcl-db/Makefile
  head/devel/fpc-fcl-js/Makefile
  head/devel/fpc-fcl-json/Makefile
  head/devel/fpc-fcl-passrc/Makefile
  head/devel/fpc-fcl-pdf/Makefile
  head/devel/fpc-fcl-sdo/Makefile
  head/devel/fpc-fcl-stl/Makefile
  head/devel/fpc-fcl-web/Makefile
  head/devel/fpc-fppkg/Makefile
  head/devel/fpc-sdl/Makefile
  head/editors/cudatext/Makefile
  head/editors/lazarus/Makefile
  head/editors/picpas/Makefile
  head/games/hedgewars/Makefile
  head/graphics/fpc-imagemagick/Makefile
  head/graphics/lazpaint/Makefile
  head/lang/fpc/Makefile
  head/lang/fpc/distinfo
  head/lang/fpc/files/patch-rtl-bsd_bunxsysc.inc
  head/lang/fpc/files/patch-rtl-freebsd_sysnr.inc
  head/lang/fpc/files/patch-rtl-freebsd_unxfunc.inc
  head/lang/fpc/files/patch-rtl-unix_bunxh.inc
  head/lang/fpc/files/patch-rtl_bsd_ossysc.inc
  head/lang/fpc-base/Makefile
  head/lang/fpc-rtl-objpas/Makefile
  head/lang/fpc-source/Makefile
  head/lang/fpc-utils/Makefile
  head/lang/nbc/Makefile
  head/multimedia/fpc-libvlc/Makefile
  head/multimedia/winff/Makefile
  head/net-p2p/awgg/Makefile
  head/net-p2p/transmission-remote-gui/Makefile
  head/russian/emkatic/Makefile
  head/science/checkmol/Makefile
  head/science/mol2ps/Makefile
  head/www/fpc-googleapi/Makefile
  head/x11/fpc-x11/Makefile
  head/x11-fm/doublecmd/Makefile