Skip to content

Update ext/spl dependencies #14544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft

Conversation

petk
Copy link
Member

@petk petk commented Jun 12, 2024

This updates and syncs ext/spl dependencies for the configure phase using the PHP_ADD_EXTENSION_DEP in Autotools and ADD_EXTENSION_DEP on Windows. ZEND_MOD_REQUIRED dependencies are listed so that extensions are properly sorted during runtime.

@Girgias
Copy link
Member

Girgias commented Jun 12, 2024

Seems some CI are failing now?

This updates and syncs ext/spl dependencies for the configure phase
using the PHP_ADD_EXTENSION_DEP in Autotools and ADD_EXTENSION_DEP on
Windows. ZEND_MOD_REQUIRED dependencies are listed so that extensions
are properly sorted during runtime.
@petk petk force-pushed the patch-spl-dependencies branch from 6ec148a to 53a6d5f Compare June 12, 2024 14:31
@petk
Copy link
Member Author

petk commented Jun 12, 2024

Seems some CI are failing now?

Rechecking CI...

@petk
Copy link
Member Author

petk commented Jun 12, 2024

Hm, interesting. Something doesn't work. Then these dependencies are very error prone I'm guessing.

P.S.: It is probably related to the cyclic dependency between ext/standard and ext/spl (ZEND_MOD_REQUIRED("standard)). And also ext/phar is already defining the standard dependency... Yes, this will need to be rechecked further...

@petk petk marked this pull request as draft June 12, 2024 15:31
@petk
Copy link
Member Author

petk commented Jun 12, 2024

Yes, the sorting algorithm in zend_API.c gets into an infinite loop because there are session, spl and standard which all depend on each other in one way or the other and doesn't know how to break out of that yet:

while (b1 < end) {
try_again:
    m = (zend_module_entry*)Z_PTR(b1->val);
    if (!m->module_started && m->deps) {
        const zend_module_dep *dep = m->deps;
        while (dep->name) {
            if (dep->type == MODULE_DEP_REQUIRED || dep->type == MODULE_DEP_OPTIONAL) {
                b2 = b1 + 1;
                while (b2 < end) {
                    r = (zend_module_entry*)Z_PTR(b2->val);
                    if (strcasecmp(dep->name, r->name) == 0) {
                        tmp = *b1;
                        *b1 = *b2;
                        *b2 = tmp;
                        goto try_again;
                    }
                    b2++;
                }
            }
            dep++;
        }
    }
    b1++;
}

Technically cycling dependencies are an architecture error but these could be probably resolved by manually stop sorting them and either the first of the last wins. This should be rethought a bit though.

@Girgias
Copy link
Member

Girgias commented Jun 12, 2024

Hum, I know SPL depends on Standard, but why does it depend on session? or is it standard that depends on session?

@petk
Copy link
Member Author

petk commented Jun 13, 2024

Hum, I know SPL depends on Standard, but why does it depend on session? or is it standard that depends on session?

I'll have to recheck this to properly explain but it is something like this:
this loop goes through all registered extensions that are given in internal_functions*.c file(s) (or loaded dynamically via extension INI directive) and then at the SPL, session and standard it loops infinitely when done like in this PR. Because ext/standard has session dependency and ext/session has spl dependency listed in ZEND_MOD_* and spl has standard listed. Interestingly that session always makes the standard added after the SPL since a couple of PHP versions. I think the solution might be to remove the standard dependency from ext/spl.

Ideal solution would be to fix the sorting algo but it might be very difficult to get this done properly and improve performance here (at least for me :D).

@Girgias
Copy link
Member

Girgias commented Aug 17, 2024

I'm very confused, why is ext/session depending on ext/spl? I can't seem to find any usage of SPL in ext/session...

@petk
Copy link
Member Author

petk commented Aug 17, 2024

I'm very confused, why is ext/session depending on ext/spl? I can't seem to find any usage of SPL in ext/session...

Because of this https://bugs.php.net/53141

@Girgias
Copy link
Member

Girgias commented Aug 17, 2024

I don't see how adding SPL fixes that issue? Is this some unloading ordering issue or what?

@petk
Copy link
Member Author

petk commented Aug 17, 2024

I don't see how adding SPL fixes that issue? Is this some unloading ordering issue or what?

Yes, the ZEND_MOD_OPTIONAL in this case registers the spl extension before the session extension so its functions are available I think. I've even tested this back then on PHP-8.4-dev and was still required to load it before the session.

@Girgias
Copy link
Member

Girgias commented Aug 17, 2024

Erg this is stupid... well I suppose yet another motivation to get back to #8294

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants