Opened 8 weeks ago

Closed 6 weeks ago

Last modified 6 weeks ago

#70987 closed defect (fixed)

php73, php74, php80, php81: Segmentation fault when generating phar.php

Reported by: exlemor (Emmanuel Lemor) Owned by: ryandesign (Ryan Carsten Schmidt)
Priority: Normal Milestone:
Component: ports Version: 2.10.1
Keywords: sequoia haspatch Cc:
Port: php73 php74 php80 php81 php82 php83 php84

Description

Follow-up to ticket #70981...

As requested here is the main.log file to try help figure out how to get php 7.4 working via MacPorts for PHPWebStudy under Mac OS 15 Sequoia.

Sincerely,

Emmanuel.

Attachments (7)

main.log (829.2 KB) - added by exlemor (Emmanuel Lemor) 8 weeks ago.
main log file as requested.
main-both-commands.log (837.0 KB) - added by exlemor (Emmanuel Lemor) 7 weeks ago.
Main log file MacPorts PHP74 with both commands
php80.ips (8.4 KB) - added by ryandesign (Ryan Carsten Schmidt) 7 weeks ago.
php81-0.ips (10.6 KB) - added by ryandesign (Ryan Carsten Schmidt) 7 weeks ago.
php81-1.ips (8.4 KB) - added by ryandesign (Ryan Carsten Schmidt) 7 weeks ago.
php81-2.ips (10.6 KB) - added by ryandesign (Ryan Carsten Schmidt) 7 weeks ago.
php81-3.ips (8.4 KB) - added by ryandesign (Ryan Carsten Schmidt) 7 weeks ago.

Download all attachments as: .zip

Change History (23)

Changed 8 weeks ago by exlemor (Emmanuel Lemor)

Attachment: main.log added

main log file as requested.

comment:1 Changed 8 weeks ago by ryandesign (Ryan Carsten Schmidt)

Owner: set to ryandesign
Status: newassigned

I don't see any signs of -Wno-error=implicit-int in the log so you haven't succeeded in running sudo port install php74 configure.cflags="-Os -Wno-error=implicit-int" after running sudo port clean php74.

Changed 7 weeks ago by exlemor (Emmanuel Lemor)

Attachment: main-both-commands.log added

Main log file MacPorts PHP74 with both commands

comment:2 Changed 7 weeks ago by exlemor (Emmanuel Lemor)

I ran both sudo port clean php74 and sudo port install php74 configure.cflags="-Os -Wno-error=implicit-int" and still the same failure...

Please find the new main.log file (called main-both-commands.log) attached.

Sincerely,

Emmanuel.

Last edited 7 weeks ago by ryandesign (Ryan Carsten Schmidt) (previous) (diff)

comment:3 Changed 7 weeks ago by ryandesign (Ryan Carsten Schmidt)

Keywords: sequoia added
Port: php80 added; php74 removed
Status: assignedaccepted
Summary: php74: Undefined Symbolsphp80: Segmentation fault when generating phar.php

The log shows a different failure now—the one I expected to see:

Generating phar.php
/bin/sh: line 1: 55243 Segmentation fault

We see this same problem building php80 on macOS Sequoia, but not php81 or later, and not on earlier macOS versions.

I'll have to investigate why it's crashing when building phar.php.

comment:4 Changed 7 weeks ago by ryandesign (Ryan Carsten Schmidt)

Can you see if macOS generated a crash log for this crash, probably a crash of the php or php74 process, probably in /Library/Logs/DiagnosticReports, and if so attach it?

comment:5 Changed 7 weeks ago by ryandesign (Ryan Carsten Schmidt)

Port: php81 added
Summary: php80: Segmentation fault when generating phar.phpphp80, php81: Segmentation fault when generating phar.php

I found the crash reports on the build machine. The crash when building php80 is a little vague to me; it doesn't show the usual stack trace that should tell us what function was running when the problem happened:

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x00000000000001e8
Exception Codes:       0x0000000000000001, 0x00000000000001e8

Termination Reason:    Namespace SIGNAL, Code 11 Segmentation fault: 11
Terminating Process:   exc handler [75775]

VM Region Info: 0x1e8 is not in any region.  Bytes before following region: 4509498904
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                      10cc98000-10d683000    [  9.9M] r-x/r-x SM=COW  /opt/local/var/macports/*/php

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   ???                           	             0x1e8 ???


Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x00007fd29780c900  rbx: 0x000000010e205000  rcx: 0x0000000000000003  rdx: 0x000000010e205020
  rdi: 0x000000010e205000  rsi: 0x000000010e200000  rbp: 0x000000000000001a  rsp: 0x00007ff7b3266be0
   r8: 0x000000010e205000   r9: 0x000000000000006c  r10: 0x00000000001ff800  r11: 0x0000000000000030
  r12: 0x0000000000000000  r13: 0x000000010d6989c0  r14: 0x00007ff7b3266c00  r15: 0x000000010ce78ecd
  rip: 0x00000000000001e8  rfl: 0x0000000000010202  cr2: 0x00000000000001e8
  
Logical CPU:     0
Error Code:      0x00000014 (no mapping for user instruction read)
Trap Number:     14

But there were four more crash logs from the build of php81. I now realize generating phar.php also crashes when building php81 on macOS 15, but unlike with php80 and earlier it doesn't stop the build. Two of the crashes are segmentation faults and the logs look like the one from php80. The other two crashes are abort traps and their logs more helpfully point to a function—zend_hash_find or rather the unnamed label .LL31 that zend_hash_find calls:

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000

Termination Reason:    Namespace SIGNAL, Code 6 Abort trap: 6
Terminating Process:   php [40488]

Application Specific Information:
abort() called


Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib        	    0x7ff813d7db52 __pthread_kill + 10
1   libsystem_pthread.dylib       	    0x7ff813db7f85 pthread_kill + 262
2   libsystem_c.dylib             	    0x7ff813cd8b19 abort + 126
3   libsystem_malloc.dylib        	    0x7ff813bd7ab1 malloc_vreport + 857
4   libsystem_malloc.dylib        	    0x7ff813bdb58b malloc_report + 151
5   php                           	       0x10cf5e27d .LL31 + 203
6   php                           	       0x10cef6498 zend_hash_find + 128
7   php                           	       0x10cf752b1 lookup_class_ex + 312
8   php                           	       0x10cf70823 zend_perform_covariant_type_check + 885
9   php                           	       0x10cf75ae8 zend_do_perform_implementation_check + 554
10  php                           	       0x10cf755f8 do_inheritance_check_on_method + 344
11  php                           	       0x10cf722df do_interface_implementation + 520
12  php                           	       0x10ceec276 zend_class_implements + 216
13  php                           	       0x10cf5d6fd zend_register_weakref_ce + 316
14  php                           	       0x10cf703be zend_register_default_classes + 34
15  php                           	       0x10cef7ba5 zm_startup_core + 101
16  php                           	       0x10cee9ff9 zend_startup_module_ex + 259
17  php                           	       0x10ceea38f zend_startup_module_zval + 12
18  php                           	       0x10cef55cd zend_hash_apply + 87
19  php                           	       0x10ce87a9c php_module_startup + 2180
20  php                           	       0x10cfbb90d php_cli_startup + 13
21  php                           	       0x10cfb9666 main + 1356
22  dyld                          	    0x7ff813a2a2cd start + 1805


Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x0000000000000000  rbx: 0x0000000000000006  rcx: 0x00007ff7b3203dc8  rdx: 0x0000000000000000
  rdi: 0x0000000000000103  rsi: 0x0000000000000006  rbp: 0x00007ff7b3203df0  rsp: 0x00007ff7b3203dc8
   r8: 0x000000000000002e   r9: 0x0000000000000000  r10: 0x0000000000000000  r11: 0x0000000000000246
  r12: 0x0000000000000000  r13: 0x0000000000000050  r14: 0x0000000000000103  r15: 0x0000000000000016
  rip: 0x00007ff813d7db52  rfl: 0x0000000000000246  cr2: 0x0000000000000000
  
Logical CPU:     0
Error Code:      0x02000148 
Trap Number:     133

I don't know what phar.php is, why it is being generated, or what it is used for. It does not, for example, as far as I can tell, get installed.

Would you try installing the php81, php82, and php83 ports and running php81 -v, php82 -v, and php83 -v? I believe php81 will crash but hope php82 and php83 don't. This would help determine if we're looking for an existing fix in php82 that we can backport or something new that still needs to have a fix developed.

Changed 7 weeks ago by ryandesign (Ryan Carsten Schmidt)

Attachment: php80.ips added

Changed 7 weeks ago by ryandesign (Ryan Carsten Schmidt)

Attachment: php81-0.ips added

Changed 7 weeks ago by ryandesign (Ryan Carsten Schmidt)

Attachment: php81-1.ips added

Changed 7 weeks ago by ryandesign (Ryan Carsten Schmidt)

Attachment: php81-2.ips added

Changed 7 weeks ago by ryandesign (Ryan Carsten Schmidt)

Attachment: php81-3.ips added

comment:6 in reply to:  4 ; Changed 7 weeks ago by exlemor (Emmanuel Lemor)

Replying to ryandesign:

Can you see if macOS generated a crash log for this crash, probably a crash of the php or php74 process, probably in /Library/Logs/DiagnosticReports, and if so attach it?

Gladly, but what would that log file have for a name - lots of files in that folder structure :/

Sincerely,

Emmanuel

comment:7 in reply to:  5 Changed 7 weeks ago by exlemor (Emmanuel Lemor)

Replying to ryandesign:

I found the crash reports on the build machine. The crash when building php80 is a little vague to me; it doesn't show the usual stack trace that should tell us what function was running when the problem happened:

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x00000000000001e8
Exception Codes:       0x0000000000000001, 0x00000000000001e8

Termination Reason:    Namespace SIGNAL, Code 11 Segmentation fault: 11
Terminating Process:   exc handler [75775]

VM Region Info: 0x1e8 is not in any region.  Bytes before following region: 4509498904
      REGION TYPE                    START - END         [ VSIZE] PRT/MAX SHRMOD  REGION DETAIL
      UNUSED SPACE AT START
--->  
      __TEXT                      10cc98000-10d683000    [  9.9M] r-x/r-x SM=COW  /opt/local/var/macports/*/php

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   ???                           	             0x1e8 ???


Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x00007fd29780c900  rbx: 0x000000010e205000  rcx: 0x0000000000000003  rdx: 0x000000010e205020
  rdi: 0x000000010e205000  rsi: 0x000000010e200000  rbp: 0x000000000000001a  rsp: 0x00007ff7b3266be0
   r8: 0x000000010e205000   r9: 0x000000000000006c  r10: 0x00000000001ff800  r11: 0x0000000000000030
  r12: 0x0000000000000000  r13: 0x000000010d6989c0  r14: 0x00007ff7b3266c00  r15: 0x000000010ce78ecd
  rip: 0x00000000000001e8  rfl: 0x0000000000010202  cr2: 0x00000000000001e8
  
Logical CPU:     0
Error Code:      0x00000014 (no mapping for user instruction read)
Trap Number:     14

But there were four more crash logs from the build of php81. I now realize generating phar.php also crashes when building php81 on macOS 15, but unlike with php80 and earlier it doesn't stop the build. Two of the crashes are segmentation faults and the logs look like the one from php80. The other two crashes are abort traps and their logs more helpfully point to a function—zend_hash_find or rather the unnamed label .LL31 that zend_hash_find calls:

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000

Termination Reason:    Namespace SIGNAL, Code 6 Abort trap: 6
Terminating Process:   php [40488]

Application Specific Information:
abort() called


Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib        	    0x7ff813d7db52 __pthread_kill + 10
1   libsystem_pthread.dylib       	    0x7ff813db7f85 pthread_kill + 262
2   libsystem_c.dylib             	    0x7ff813cd8b19 abort + 126
3   libsystem_malloc.dylib        	    0x7ff813bd7ab1 malloc_vreport + 857
4   libsystem_malloc.dylib        	    0x7ff813bdb58b malloc_report + 151
5   php                           	       0x10cf5e27d .LL31 + 203
6   php                           	       0x10cef6498 zend_hash_find + 128
7   php                           	       0x10cf752b1 lookup_class_ex + 312
8   php                           	       0x10cf70823 zend_perform_covariant_type_check + 885
9   php                           	       0x10cf75ae8 zend_do_perform_implementation_check + 554
10  php                           	       0x10cf755f8 do_inheritance_check_on_method + 344
11  php                           	       0x10cf722df do_interface_implementation + 520
12  php                           	       0x10ceec276 zend_class_implements + 216
13  php                           	       0x10cf5d6fd zend_register_weakref_ce + 316
14  php                           	       0x10cf703be zend_register_default_classes + 34
15  php                           	       0x10cef7ba5 zm_startup_core + 101
16  php                           	       0x10cee9ff9 zend_startup_module_ex + 259
17  php                           	       0x10ceea38f zend_startup_module_zval + 12
18  php                           	       0x10cef55cd zend_hash_apply + 87
19  php                           	       0x10ce87a9c php_module_startup + 2180
20  php                           	       0x10cfbb90d php_cli_startup + 13
21  php                           	       0x10cfb9666 main + 1356
22  dyld                          	    0x7ff813a2a2cd start + 1805


Thread 0 crashed with X86 Thread State (64-bit):
  rax: 0x0000000000000000  rbx: 0x0000000000000006  rcx: 0x00007ff7b3203dc8  rdx: 0x0000000000000000
  rdi: 0x0000000000000103  rsi: 0x0000000000000006  rbp: 0x00007ff7b3203df0  rsp: 0x00007ff7b3203dc8
   r8: 0x000000000000002e   r9: 0x0000000000000000  r10: 0x0000000000000000  r11: 0x0000000000000246
  r12: 0x0000000000000000  r13: 0x0000000000000050  r14: 0x0000000000000103  r15: 0x0000000000000016
  rip: 0x00007ff813d7db52  rfl: 0x0000000000000246  cr2: 0x0000000000000000
  
Logical CPU:     0
Error Code:      0x02000148 
Trap Number:     133

I don't know what phar.php is, why it is being generated, or what it is used for. It does not, for example, as far as I can tell, get installed.

Would you try installing the php81, php82, and php83 ports and running php81 -v, php82 -v, and php83 -v? I believe php81 will crash but hope php82 and php83 don't. This would help determine if we're looking for an existing fix in php82 that we can backport or something new that still needs to have a fix developed.

Actually MacPorts php8.1 installed fine it seems (no errors at the end)... I am actually running MacPorts through PHPWebStudy (and PHPPWebStudy also has built-in PHP 8.1 - 8.3 capabilities or MacPorts - I used MacPorts integration and chose php 8.1 and that installed ) -- at least it says installed successfully - not sure if it did or not and then installed MySQL 8.0.x without issue...

Unfortunately, I need PHP 7.4 and not PHP 8 or newer ;(

Sincerely,

Emmanuel.

comment:8 in reply to:  6 Changed 7 weeks ago by ryandesign (Ryan Carsten Schmidt)

Replying to exlemor:

Replying to ryandesign:

Can you see if macOS generated a crash log for this crash, probably a crash of the php or php74 process, probably in /Library/Logs/DiagnosticReports, and if so attach it?

Gladly, but what would that log file have for a name - lots of files in that folder structure :/

The log file name starts with the name of the executable (php) followed by a date and time and ending with .ips. Less urgent now that I found the crash logs on the build machine; I bet yours say more or less the same thing.

Replying to exlemor:

Actually MacPorts php8.1 installed fine it seems (no errors at the end)...

Right, we saw that on our build machine as well, but the question was whether it works or not, and I suspected that it does not. I have now installed php81, php82, and php83 on another machine with macOS 15 using binaries from our build machine and php81 -v crashes while php82 -v and php83 -v work correctly. I then rebuilt php81 from source on that machine and it still crashes.

Unfortunately, I need PHP 7.4 and not PHP 8 or newer ;(

Right, but now that we know the problem exists in php81 and older and is solved in php82 that helps narrow the focus of where we need to look for the fix. It also gives me enough information to file a bug report with the developers of php. They might not have been interested in helping us with problems with php80 or older since those versions have already reached end of life, but php81 is not dead yet so they may help us.

comment:9 Changed 7 weeks ago by ryandesign (Ryan Carsten Schmidt)

In the upstream bug report I have identified the commit that fixed the problem in php 8.2.16 and that backporting it to 8.1.30 fixes the crash. Backporting to 8.0.x and earlier will be more complicated.

comment:10 Changed 7 weeks ago by exlemor (Emmanuel Lemor)

I have faith you can squeeze out a solution for us poor souls in need of PHP 7.4 ;) (hug) lol

comment:11 Changed 6 weeks ago by ryandesign (Ryan Carsten Schmidt)

Keywords: haspatch added

I think we now understand that the previously-identified change avoided this crash but didn't fix the real cause of the problem, which is that PHP's assembly code on x86_64 and i386 is using a syntax for declaring local symbols that is specific to ELF (e.g. Linux) systems. On Mach-O (e.g. macOS) systems, these symbols are not being interpreted as local and so the Clang 16 optimizer thinks it is OK to combine some of them, which causes the crash. The fix is to change the way the symbols are declared so that they are interpreted as local on all systems.

Before this was understood, the developers were suggesting a different change which turned out not to work. I'll wait to see whether they still want to include that change or whether the symbol name fix is sufficient for them. Whichever they decide to go with, I'll apply that to the affected MacPorts php versions.

comment:12 Changed 6 weeks ago by exlemor (Emmanuel Lemor)

Sounds like there is progress :)

comment:13 Changed 6 weeks ago by ryandesign (Ryan Carsten Schmidt)

Port: php73 php74 php82 php83 php84 added
Summary: php80, php81: Segmentation fault when generating phar.phpphp73, php74, php80, php81: Segmentation fault when generating phar.php

The assembly versions of these functions weren't added until php73, so php72 and earlier aren't affected.

php82, php83, and php84, although not affected by the crash because this function isn't inlined anymore, still use the wrong non-local labels and should be fixed.

comment:14 Changed 6 weeks ago by ryandesign (Ryan Carsten Schmidt)

Resolution: fixed
Status: acceptedclosed

In f6c30c5b3a810d4154ab8c85bb23274baa020fe1/macports-ports (master):

php73, php74, php80, php81: Fix crash on macOS 15

Closes: #70987

comment:15 Changed 6 weeks ago by exlemor (Emmanuel Lemor)

Well, it may be supposed to work but it is still not working... ;( (Sequoia 15.0.1)

First I started PhpWebStudy, it said there was an update so I updated it. Then, I tried installing php7.4 from MacPorts and it said during the installation that macports was out of date so after it finished and failed that installation, I did sudo port clean php74 then after that, I did sudo port selfupdate command as requested by the installation process... then sudo port upgrade outdated as I had 2 components that were out of date...

but still...

ld: warning: ignoring duplicate libraries: '-largon2', '-lxml2', '-lz'
Undefined symbols for architecture x86_64:
  "_res_9_dn_expand", referenced from:
      _php_parserr in dns.o
      _php_parserr in dns.o
      _php_parserr in dns.o
      _php_parserr in dns.o
      _php_parserr in dns.o
      _php_parserr in dns.o
      _zif_dns_get_mx in dns.o
      ...
  "_res_9_dn_skipname", referenced from:
      _zif_dns_get_record in dns.o
      _zif_dns_get_mx in dns.o
      _zif_dns_get_mx in dns.o
  "_res_9_init", referenced from:
      _zif_dns_check_record in dns.o
      _zif_dns_get_record in dns.o
      _zif_dns_get_mx in dns.o
  "_res_9_search", referenced from:
      _zif_dns_check_record in dns.o
      _zif_dns_get_record in dns.o
      _zif_dns_get_mx in dns.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [sapi/cli/php] Error 1
make: *** Waiting for unfinished jobs....
ld: warning: ignoring duplicate libraries: '-largon2', '-lxml2', '-lz'
Undefined symbols for architecture x86_64:
  "_res_9_dn_expand", referenced from:
      _php_parserr in dns.o
      _php_parserr in dns.o
      _php_parserr in dns.o
      _php_parserr in dns.o
      _php_parserr in dns.o
      _php_parserr in dns.o
      _zif_dns_get_mx in dns.o
      ...
  "_res_9_dn_skipname", referenced from:
      _zif_dns_get_record in dns.o
      _zif_dns_get_mx in dns.o
      _zif_dns_get_mx in dns.o
  "_res_9_init", referenced from:
      _zif_dns_check_record in dns.o
      _zif_dns_get_record in dns.o
      _zif_dns_get_mx in dns.o
  "_res_9_search", referenced from:
      _zif_dns_check_record in dns.o
      _zif_dns_get_record in dns.o
      _zif_dns_get_mx in dns.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [sapi/phpdbg/phpdbg] Error 1
make: Leaving directory `/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_lang_php/php74/work/php-7.4.33'
Command failed:  cd "/opt/local/var/macports/build/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_lang_php/php74/work/php-7.4.33" && /usr/bin/make -j12 -w all 
Exit code: 2
Error: Failed to build php74: command execution failed
Error: See /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_macports_release_tarballs_ports_lang_php/php74/main.log for details.
Error: Follow https://guide.macports.org/#project.tickets if you believe there is a bug.
Error: Processing of port php74 failed

Any thoughts ;(

Last edited 6 weeks ago by ryandesign (Ryan Carsten Schmidt) (previous) (diff)

comment:16 in reply to:  15 Changed 6 weeks ago by ryandesign (Ryan Carsten Schmidt)

Replying to exlemor:

Undefined symbols for architecture x86_64:
  "_res_9_dn_expand", referenced from:

So far I've only fixed #70987 (the segmentation fault). I haven't fixed #70468 (the undefined symbols) yet so the workaround for that issue that you're already familiar with from comment:1 is still needed:

sudo port clean php74
sudo port install php74 configure.cflags="-Os -Wno-error=implicit-int"
Note: See TracTickets for help on using tickets.