Bug 276858

Summary: php coredumps upgrading nextcloud 28.0.1 to 28.0.2 because math/gmp needs to have CPU_OPTS off
Product: Ports & Packages Reporter: dgilbert
Component: Individual Port(s)Assignee: Alex Dupre <ale>
Status: Closed Not A Bug    
Severity: Affects Many People CC: ale, diizzy
Priority: --- Flags: linimon: maintainer-feedback? (ale)
Version: Latest   
Hardware: Any   
OS: Any   

Description dgilbert 2024-02-06 22:51:08 UTC
I have tried this with both php82 ... version 8.2.13 and version 8.2.14.  This bug is submitted with a dump from 8.2.13, but I can further create one with 8.2.14 if required.

I can also provide a zfs dump of running nextcloud system ... but ... that's probably not good (contains personal information).

Backtrace is as follows:

Dwarf Error: wrong version in compilation unit header (is 4, should be 2) [in module /usr/lib/debug/libexec/ld-elf.so.1.debug]
#0  0x0000000847ea00af in __gmpz_set_str () from /usr/local/lib/libgmp.so.10
[New Thread 82a226000 (LWP 114685/<unknown>)]
(gdb) bt
#0  0x0000000847ea00af in __gmpz_set_str () from /usr/local/lib/libgmp.so.10
#1  0x0000000846c3756b in zif_gmp_init () from /usr/local/lib/php/20220829/gmp.so
#2  0x0000000846c37479 in zif_gmp_init () from /usr/local/lib/php/20220829/gmp.so
#3  0x000000000061aab1 in zend_execute ()
#4  0x00000000005e4048 in execute_ex ()
#5  0x00000000005e4220 in zend_execute ()
#6  0x00000000005c068d in zend_execute_scripts ()
#7  0x0000000000553bf7 in php_execute_script ()
#8  0x00000000006ab654 in sapi_cli_single_write ()
#9  0x00000000006a9eb7 in sapi_cli_single_write ()
#10 0x00000000003ec460 in _start ()
#11 0x0000000821303008 in ?? ()
#12 0x0000000000000000 in ?? ()

upgrade of nextcloud fails as follows:

[nextcloud@nexttext ~/nextcloud]$ php occ upgrade
Nextcloud or one of the apps require upgrade - only a limited number of commands are available
You may use your browser or the occ upgrade command to do the upgrade
Setting log level to debug
Turned on maintenance mode
Updating database schema
Updated database
Update app forms from App Store
Illegal instruction (core dumped)
Comment 1 dgilbert 2024-02-06 23:17:59 UTC
Here's an interesting addendum from another user that had this problem...

https://help.nextcloud.com/t/failed-to-install-update-apps/162650/4

... saying that something in the chain was failing for optimization flags.
Comment 2 Vladimir Druzenko freebsd_committer freebsd_triage 2024-02-06 23:22:29 UTC
> Illegal instruction

What hardware do you have (CPU)?
Is it VM (what virtualization) or baremetal?
Build all ports self? cat /etc/make.conf
math/gmp with CPU_OPTS on? pkg info math/gmp
Comment 3 dgilbert 2024-02-06 23:27:40 UTC
(In reply to Vladimir Druzenko from comment #2)

Compiled on Threadripper 1900; running on Xeon E5-2670 in a jail.

math/gmp has:

# This file is auto-generated by 'make config'.
# Options for gmp-6.2.1
_OPTIONS_READ=gmp-6.2.1
_FILE_COMPLETE_OPTIONS_LIST=CPU_OPTS
OPTIONS_FILE_SET+=CPU_OPTS

[2:169:471]root@vr:/usr/local/etc/poudriere.d> cat make.conf
DEFAULT_VERSIONS+=pgsql=15
DEFAULT_VERSIONS+=php=82
DISABLE_LICENSES=yes

SELECTED_OPTIONS+=OPENBLAS

ARCHDEF=AMD64K10h64SSE3

[2:14:314]root@ibex:~> pkg info math/gmp
gmp-6.2.1
Name           : gmp
Version        : 6.2.1
Installed on   : Wed Apr 20 16:43:32 2022 EDT
Origin         : math/gmp
Architecture   : FreeBSD:13:amd64
Prefix         : /usr/local
Categories     : math devel
Licenses       : LGPL3
Maintainer     : ale@FreeBSD.org
WWW            : https://gmplib.org/
Comment        : Free library for arbitrary precision arithmetic
Options        :
        CPU_OPTS       : on
Shared Libs provided:
        libgmpxx.so.4
        libgmp.so.10
Annotations    :
        FreeBSD_version: 1300139
        cpe            : cpe:2.3:a:gmplib:gmp:6.2.1:::::freebsd13:x64
Flat size      : 2.59MiB
Description    :
[description deleted]
Comment 4 dgilbert 2024-02-09 18:52:50 UTC
so... indeed math/gmp needs to have CPU_OPTS off.
Comment 5 Mark Linimon freebsd_committer freebsd_triage 2024-05-12 00:20:32 UTC
^Triage: update Summary and assign to math/gmp maintainer.
Comment 6 Daniel Engberg freebsd_committer freebsd_triage 2024-05-12 05:17:43 UTC
This is not a bug, it's because the feature (instruction) set is mismatched between the hardware and is determined during compile time. There's no runtime detection for gmp so it just tries to match the build box.

Defining "CPUTYPE?=x86-64-v2" in make.conf should fix the issue without disabling CPU_OPTS given the target hardware.
Comment 7 Alex Dupre freebsd_committer freebsd_triage 2024-05-12 07:22:52 UTC
I cannot agree more with @diizzy. If you are enabling an OFF-by-default option that introduces CPU-specific optimizations and then you run the binary on another CPU you are just asking for troubles, there is no technical fix to apply.