Bug 239135 - lang/fpc build failure on FBSD 11.2
Summary: lang/fpc build failure on FBSD 11.2
Status: In Progress
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Jose Alonso Cardenas Marquez
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-07-11 05:44 UTC by Trev
Modified: 2020-02-17 05:05 UTC (History)
3 users (show)

See Also:
bugzilla: maintainer-feedback? (acm)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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 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 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 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)