Bug 274011 - lang/php83: ifunc support is disabled
Summary: lang/php83: ifunc support is disabled
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Muhammad Moinur Rahman
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-09-21 23:53 UTC by Thomas Hurst
Modified: 2023-09-23 11:18 UTC (History)
0 users

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


Attachments
Patch for lang/php81 (2.81 KB, patch)
2023-09-22 14:43 UTC, Thomas Hurst
bofh: maintainer-approval-
Details | Diff
Patch for lang/php83 (2.83 KB, patch)
2023-09-23 01:22 UTC, Thomas Hurst
tom: maintainer-approval?
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Hurst 2023-09-21 23:53:37 UTC
In the process of looking at how projects handle ifunc support, I came across this in PHP's configure.ac:

https://github.com/php/php-src/blob/edd72da03abc7dc1f2ae51825201488045f6ef37/configure.ac#L568-L569

  dnl At least some versions of FreeBSD seem to have buggy ifunc support, see
  dnl bug #77284. Conservatively don't use ifuncs on FreeBSD.

The referenced bug from late 2018: https://bugs.php.net/bug.php?id=77284

Suggestion there is it's fixed in FreeBSD 12, and the associated bugs in the thread point at a few other fixes that may or may not be relevant.

Either way, with this disabled FreeBSD will be lacking SIMD versions of, er, whatever PHP has SIMD versions of, so perhaps some effort should be made to re-enable it and see what happens?
Comment 1 Muhammad Moinur Rahman freebsd_committer freebsd_triage 2023-09-22 05:53:39 UTC
Thanks for the updates. I will try to enable this on next php83 release. However it will take some times to land into php81/php82 if it works on php83. It will not go into php80 at all anymore. And I will actually need some test results as I am no longer working for the company I used to where they used to heavy lift php works.
Comment 2 Thomas Hurst 2023-09-22 14:36:03 UTC
Testing with php81 I also run into:

  checking for __builtin_cpu_init... no

This is also a prerequisite for ifunc support in PHP.

Looking at the test in build/php.m4:

  return __builtin_cpu_init()? 1 : 0;

That's an interesting thing to be doing with void __builtin_cpu_init(void)!

I replaced with:

  __builtin_cpu_init();return 1;

And now:

❯ ./php-ifunc addslash.php
10000000 iterations in 0.454 seconds
❯ ./php-no-ifunc addslash.php
10000000 iterations in 2.501 seconds
❯ ./php-ifunc base64.php
10000000 iterations in 0.580 seconds
❯ ./php-no-ifunc base64.php
10000000 iterations in 2.044 seconds
Comment 3 Thomas Hurst 2023-09-22 14:43:02 UTC
Created attachment 245119 [details]
Patch for lang/php81
Comment 4 Muhammad Moinur Rahman freebsd_committer freebsd_triage 2023-09-22 19:39:46 UTC
I think I didn't clarify in details. But at this moment this patch will not go into php81/php82. As around in 2 months we are going to change the default version to php82 from php81 and there are lots of work in between as we will have to go through exp-run and etc. I will consider adding these to php81/php82 sometimes around next year as this is still experimental and needs thorough testing before throwing it into the tiger den. So please update the patches for php83.
Comment 5 Thomas Hurst 2023-09-22 21:46:31 UTC
You were perfectly clear, the patch is purely informational - that's why I didn't flag it for maintainer-approval.

I have a PR upstream for the __builtin_cpu_init check (https://github.com/php/php-src/issues/12273) so hopefully that bit shouldn't be needed for long.
Comment 6 Thomas Hurst 2023-09-23 01:22:46 UTC
Created attachment 245132 [details]
Patch for lang/php83

Same patch for lang/php83 (minus a superfluous return statement).

Passes the same very light tests with the same sort of performance improvements.  I also tried it in Apache with a ZTS build successfully:

mod_php81-8.1.23_2:
  addslashes: 10000000 iterations in 2.749 seconds
      base64: 10000000 iterations in 2.338 seconds

mod_php83-8.3.0.r2_1:
  addslashes: 10000000 iterations in 0.557 seconds
      base64: 10000000 iterations in 0.637 seconds

My two tiny PHP apps also seem to still work.
Comment 7 Muhammad Moinur Rahman freebsd_committer freebsd_triage 2023-09-23 09:35:52 UTC
Thanks. Running build tests.
Comment 8 commit-hook freebsd_committer freebsd_triage 2023-09-23 11:15:29 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=13b9ae91576775f52d9ea7ebc026b690f0a743ca

commit 13b9ae91576775f52d9ea7ebc026b690f0a743ca
Author:     Thomas Hurst <tom@hur.st>
AuthorDate: 2023-09-23 11:11:12 +0000
Commit:     Muhammad Moinur Rahman <bofh@FreeBSD.org>
CommitDate: 2023-09-23 11:15:05 +0000

    lang/php83: Reintroduce ifunc support

    SIMD functions were disabled prior to 12 and it was never chased
    upstream. However now it supports ifunc or it has improved. So let's
    test and see how well it works.

    There is an upstream PR:
    https://github.com/php/php-src/pull/12274

    PR:             274011

 lang/php83/Makefile                       |  1 +
 lang/php83/files/patch-build_php.m4 (new) | 11 +++++++++++
 lang/php83/files/patch-configure.ac       | 19 ++++++++++++++-----
 3 files changed, 26 insertions(+), 5 deletions(-)
Comment 9 Muhammad Moinur Rahman freebsd_committer freebsd_triage 2023-09-23 11:18:22 UTC
Let's test this and see how it goes. If it goes well I will introduce it into php81/php82 after this year.