Skip to content

Add function exposing HAVE_GCC_GLOBAL_REGS #8359

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

Merged
merged 3 commits into from
Jun 8, 2022
Merged

Add function exposing HAVE_GCC_GLOBAL_REGS #8359

merged 3 commits into from
Jun 8, 2022

Conversation

joerowell
Copy link
Contributor

@joerowell joerowell commented Apr 13, 2022

What's the problem?

Understanding what's happening during the PHP JIT compilation process is a bit tricky. Some of this complexity is inherent, but the Zend Engine (at present) doesn't make it that easy to gauge what's going on via a debugger like GDB.

For example, consider the following snippet from the JIT compiler:

if (zend_jit_vm_kind == ZEND_VM_KIND_HYBRID) {
const void *handler = zend_get_opcode_handler_func(EG(exception_op));
| ADD_HYBRID_SPAD
| EXT_CALL handler, r0
| JMP_IP
} else {
const void *handler = EG(exception_op)->handler;
if (GCC_GLOBAL_REGS) {
| add r4, SPAD // stack alignment
| EXT_JMP handler, r0
} else {
| mov FCARG1a, FP
| EXT_CALL handler, r0
| mov FP, aword T2 // restore FP
| mov RX, aword T3 // restore IP
| add r4, NR_SPAD // stack alignment
| test eax, eax
| jl >1
| mov r0, 1 // ZEND_VM_ENTER
|1:
| ret
}
}

To understand how this impacts the generated code you need to know at minimum:

  • The VM mode that has been used, and
  • Whether GCC was used to compile the Zend Engine or not.

You can deduce the first of these at runtime using zend_vm_kind:

ZEND_API int zend_vm_kind(void);

But there's no way to know the second of these programatically at present. You can deduce this by looking at the object code in GDB, but that's tedious and not suited to any sort of automated checking.

This PR

This PR just adds a public function called zend_gcc_global_regs that returns 1 if HAVE_GCC_GLOBAL_REGS is set and 0 otherwise. This makes it far simpler to detect what calling convention to expect.

@joerowell joerowell changed the base branch from master to PHP-8.0 April 13, 2022 10:03
@joerowell
Copy link
Contributor Author

Is this PR waiting for something, or can it be merged?

@bwoebi
Copy link
Member

bwoebi commented May 10, 2022

Can you please export that as part of zend_execute.c instead of the VM? We try to leave everything out of the VM which doesn't strictly need to be there.

@ramsey
Copy link
Member

ramsey commented May 23, 2022

Is there a reason this targets the PHP-8.0 branch?

@joerowell
Copy link
Contributor Author

joerowell commented May 23, 2022

Only because I read this:

If you are fixing a bug, then please submit your PR against the lowest actively supported branch of PHP 
that the bug affects...

And since my primary use case is for JIT code I figured I'd put it against the first version that had a JIT (e.g PHP8).
I'm happy to re-aim it at any branch that you'd prefer: I'd actually forgotten that the sentence above applied only to bugs.

@ramsey
Copy link
Member

ramsey commented May 23, 2022

If this isn't fixing a bug in PHP-8.0, please change the base to master. Thanks!

@joerowell joerowell changed the base branch from PHP-8.0 to master May 23, 2022 15:53
@joerowell
Copy link
Contributor Author

Is there something I need to do for this? I.e is there part of the PR process for this feature that I've missed? I had assumed I didn't need to do an RFC for it.

@ramsey ramsey added this to the PHP 8.2 milestone Jun 1, 2022
@Girgias Girgias merged commit 89688b1 into php:master Jun 8, 2022
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.

4 participants