Skip to content

Commit e7dfc77

Browse files
committed
JIT: add missing endbr
PR php#8774 added IBT support for jitted code and passed all built-in tests in "ext/opcache/tests/jit". However, we found several "missing ENDBR" issues recently when running some real world workloads. Such workloads introduce new code path and thus more "indirect branch target" are in jited code. This fix adds missing endbr correspondingly. Signed-off-by: PeterYang12 <yuhan.yang@intel.com> Reviewed-by: chen-hu-97 <hu1.chen@intel.com> Reviewed-by: bjzhjing <cathy.zhang@intel.com>
1 parent 3b75f07 commit e7dfc77

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,8 +1640,14 @@ static size_t tsrm_tls_offset;
16401640

16411641
#if defined (__CET__) && (__CET__ & 1) != 0
16421642
# define ENDBR_PADDING 4
1643+
/* Keep 16 exit points in a single code block */
1644+
# define ZEND_JIT_EXIT_POINTS_SPACING 8 // endbr + push byte + short jmp = bytes
1645+
# define ZEND_JIT_EXIT_POINTS_PER_GROUP 16 // number of continuous exit points
16431646
#else
16441647
# define ENDBR_PADDING 0
1648+
/* Keep 32 exit points in a single code block */
1649+
# define ZEND_JIT_EXIT_POINTS_SPACING 4 // push byte + short jmp = bytes
1650+
# define ZEND_JIT_EXIT_POINTS_PER_GROUP 32 // number of continuous exit points
16451651
#endif
16461652

16471653
static bool reuse_ip = 0;
@@ -2605,18 +2611,16 @@ static int zend_jit_trace_escape_stub(dasm_State **Dst)
26052611
return 1;
26062612
}
26072613

2608-
/* Keep 32 exit points in a single code block */
2609-
#define ZEND_JIT_EXIT_POINTS_SPACING 4 // push byte + short jmp = bytes
2610-
#define ZEND_JIT_EXIT_POINTS_PER_GROUP 32 // number of continuous exit points
2611-
26122614
static int zend_jit_trace_exit_group_stub(dasm_State **Dst, uint32_t n)
26132615
{
26142616
uint32_t i;
26152617

26162618
for (i = 0; i < ZEND_JIT_EXIT_POINTS_PER_GROUP - 1; i++) {
2619+
| ENDBR
26172620
| push byte i
2618-
| .byte 0xeb, (4*(ZEND_JIT_EXIT_POINTS_PER_GROUP-i)-6) // jmp >1
2621+
| .byte 0xeb, (ZEND_JIT_EXIT_POINTS_SPACING*(ZEND_JIT_EXIT_POINTS_PER_GROUP-i)-ZEND_JIT_EXIT_POINTS_SPACING -2) // jmp >1
26192622
}
2623+
| ENDBR
26202624
| push byte i
26212625
|// 1:
26222626
| add aword [r4], n
@@ -3126,6 +3130,7 @@ static int zend_jit_set_ip(dasm_State **Dst, const zend_op *opline)
31263130

31273131
static int zend_jit_set_ip_ex(dasm_State **Dst, const zend_op *opline, bool set_ip_reg)
31283132
{
3133+
| ENDBR
31293134
if (last_valid_opline == opline) {
31303135
zend_jit_use_last_valid_opline();
31313136
} else if (GCC_GLOBAL_REGS && last_valid_opline) {
@@ -3214,6 +3219,7 @@ static int zend_jit_check_exception_undef_result(dasm_State **Dst, const zend_op
32143219

32153220
static int zend_jit_trace_begin(dasm_State **Dst, uint32_t trace_num, zend_jit_trace_info *parent, uint32_t exit_num)
32163221
{
3222+
| ENDBR
32173223
zend_regset regset = ZEND_REGSET_SCRATCH;
32183224

32193225
#if ZTS
@@ -15026,13 +15032,15 @@ static int zend_jit_switch(dasm_State **Dst, const zend_op *opline, const zend_o
1502615032
} while (count);
1502715033
|.code
1502815034
|3:
15035+
| ENDBR
1502915036
} else {
1503015037
| LOAD_ADDR FCARG1a, jumptable
1503115038
| EXT_CALL zend_hash_index_find, r0
1503215039
if (!zend_jit_hash_jmp(Dst, opline, op_array, ssa, jumptable, default_b, default_label, next_opline, trace_info)) {
1503315040
return 0;
1503415041
}
1503515042
|3:
15043+
| ENDBR
1503615044
}
1503715045
}
1503815046
} else if (opline->opcode == ZEND_SWITCH_STRING) {
@@ -15074,6 +15082,7 @@ static int zend_jit_switch(dasm_State **Dst, const zend_op *opline, const zend_o
1507415082
return 0;
1507515083
}
1507615084
|3:
15085+
| ENDBR
1507715086
}
1507815087
} else if (opline->opcode == ZEND_MATCH) {
1507915088
if (op1_info & (MAY_BE_LONG|MAY_BE_STRING)) {

0 commit comments

Comments
 (0)