Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ php
/ext/*/configure.ac
/ext/*/run-tests.php

# Generated by ./configure if libc might be musl
/ext/gettext/tests/locale/en_US

# ------------------------------------------------------------------------------
# Generated by Windows build system
# ------------------------------------------------------------------------------
Expand Down
12 changes: 12 additions & 0 deletions ext/gettext/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ if test "$PHP_GETTEXT" != "no"; then
[AC_CHECK_LIB([c], [bindtextdomain], [
GETTEXT_LIBS=
GETTEXT_CHECK_IN_LIB=c

dnl If libintl.h is provided by libc, it's possible that libc is musl.
dnl The gettext family of functions under musl ignores the codeset
dnl suffix on directories like "en_US.UTF-8"; instead they look only
dnl in "en_US". To accomodate that, we symlink some test data from one
dnl to the other.
AC_MSG_NOTICE([symlinking en_US.UTF-8 messages to en_US in case you are on musl])
_linkdest="${srcdir%/}"/ext/gettext/tests/locale/en_US
AS_IF([test ! -e "${_linkdest}"],[
ln -s en_US.UTF-8 "${_linkdest}"
])

],
[AC_MSG_FAILURE([Unable to find required intl library for gettext.])])])

Expand Down
13 changes: 11 additions & 2 deletions ext/gettext/gettext.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ PHP_FUNCTION(dcgettext)
PHP_FUNCTION(bindtextdomain)
{
zend_string *domain, *dir = NULL;
char *retval, dir_name[MAXPATHLEN];
char *retval, dir_name[MAXPATHLEN], *btd_result;

ZEND_PARSE_PARAMETERS_START(1, 2)
Z_PARAM_STR(domain)
Expand All @@ -191,7 +191,16 @@ PHP_FUNCTION(bindtextdomain)
PHP_GETTEXT_DOMAIN_LENGTH_CHECK(1, ZSTR_LEN(domain))

if (dir == NULL) {
RETURN_STRING(bindtextdomain(ZSTR_VAL(domain), NULL));
btd_result = bindtextdomain(ZSTR_VAL(domain), NULL);
if (btd_result == NULL) {
/* POSIX-compliant implementations can return
* NULL if an error occured. On musl you will
* also get NULL if the domain is not yet
* bound, because musl has no default directory
* to return in that case. */
RETURN_FALSE;
}
RETURN_STRING(btd_result);
}

if (ZSTR_LEN(dir) != 0 && !zend_string_equals_literal(dir, "0")) {
Expand Down
28 changes: 19 additions & 9 deletions ext/gettext/tests/bug53251.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,28 @@ if (getenv('SKIP_REPEAT')) die('skip gettext leaks global state across requests'
?>
--FILE--
<?php
var_dump(is_string(bindtextdomain('foo', null)));
$results[] = is_string(bindtextdomain('foo', null));
$dir = bindtextdomain('foo', '.');
var_dump(bindtextdomain('foo', null) === $dir);
$results[] = bindtextdomain('foo', null) === $dir;
$results[] = bind_textdomain_codeset('foo', null);
$results[] = bind_textdomain_codeset('foo', 'UTF-8');
$results[] = bind_textdomain_codeset('foo', null);

var_dump(bind_textdomain_codeset('foo', null));
var_dump(bind_textdomain_codeset('foo', 'UTF-8'));
var_dump(bind_textdomain_codeset('foo', null));
$expected = [true, true, false, "UTF-8", "UTF-8"];

// musl's bindtextdomain() has no default directory to return when
// "foo" is unbound, so in the first call, you will get false instead
// of a string.
//
// bind_textdomain_codeset() always returns false on musl
// because musl only supports UTF-8. For more information:
//
// * https://github.com/php/doc-en/issues/4311,
// * https://github.com/php/php-src/issues/17163
//
$expected_musl = [false, true, false, false, false];

var_dump($results === $expected || $results === $expected_musl);
?>
--EXPECT--
bool(true)
bool(true)
bool(false)
string(5) "UTF-8"
string(5) "UTF-8"
12 changes: 10 additions & 2 deletions ext/gettext/tests/gettext_bind_textdomain_codeset-retval.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,22 @@ gettext
} catch (ValueError $e) {
echo $e->getMessage() . PHP_EOL;
}
var_dump(bind_textdomain_codeset('messages', "UTF-8"));

// bind_textdomain_codeset() always returns false on musl
// because musl only supports UTF-8. For more information:
//
// * https://github.com/php/doc-en/issues/4311,
// * https://github.com/php/php-src/issues/17163
//
$result = bind_textdomain_codeset('messages', "UTF-8");
var_dump($result === false || $result === "UTF-8");

echo "Done\n";
?>
--EXPECT--
bind_textdomain_codeset(): Argument #1 ($domain) must not be empty
bind_textdomain_codeset(): Argument #1 ($domain) must not be empty
string(5) "UTF-8"
bool(true)
Done
--CREDITS--
Florian Holzhauer [email protected]
Expand Down
11 changes: 9 additions & 2 deletions ext/opcache/jit/ir/ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ static ir_ref ir_next_const(ir_ctx *ctx)

static void ir_grow_top(ir_ctx *ctx)
{
ir_ref old_insns_limit = ctx->insns_limit;
ir_insn *buf = ctx->ir_base - ctx->consts_limit;

if (ctx->insns_limit < 1024 * 4) {
Expand All @@ -341,6 +342,12 @@ static void ir_grow_top(ir_ctx *ctx)
}
buf = ir_mem_realloc(buf, (ctx->consts_limit + ctx->insns_limit) * sizeof(ir_insn));
ctx->ir_base = buf + ctx->consts_limit;

if (ctx->use_lists) {
ctx->use_lists = ir_mem_realloc(ctx->use_lists, ctx->insns_limit * sizeof(ir_use_list));
memset(ctx->use_lists + old_insns_limit, 0,
(ctx->insns_limit - old_insns_limit) * sizeof(ir_use_list));
}
}

static ir_ref ir_next_insn(ir_ctx *ctx)
Expand Down Expand Up @@ -1152,7 +1159,7 @@ void ir_build_def_use_lists(ir_ctx *ctx)
ir_ref n, i, j, *p, def;
ir_insn *insn;
uint32_t edges_count;
ir_use_list *lists = ir_mem_calloc(ctx->insns_count, sizeof(ir_use_list));
ir_use_list *lists = ir_mem_calloc(ctx->insns_limit, sizeof(ir_use_list));
ir_ref *edges;
ir_use_list *use_list;

Expand Down Expand Up @@ -1207,7 +1214,7 @@ void ir_build_def_use_lists(ir_ctx *ctx)
ir_ref n, i, j, *p, def;
ir_insn *insn;
size_t linked_lists_size, linked_lists_top = 0, edges_count = 0;
ir_use_list *lists = ir_mem_calloc(ctx->insns_count, sizeof(ir_use_list));
ir_use_list *lists = ir_mem_calloc(ctx->insns_limit, sizeof(ir_use_list));
ir_ref *edges;
ir_use_list *use_list;
ir_ref *linked_lists;
Expand Down
44 changes: 31 additions & 13 deletions ext/opcache/jit/ir/ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,12 @@ void ir_strtab_free(ir_strtab *strtab);
#define IR_OPT_INLINE (1<<16)
#define IR_OPT_FOLDING (1<<17)
#define IR_OPT_CFG (1<<18) /* merge BBs, by remove END->BEGIN nodes during CFG construction */
#define IR_OPT_CODEGEN (1<<19)
#define IR_GEN_NATIVE (1<<20)
#define IR_GEN_CODE (1<<21) /* C or LLVM */
#define IR_OPT_MEM2SSA (1<<19)
#define IR_OPT_CODEGEN (1<<20)
#define IR_GEN_NATIVE (1<<21)
#define IR_GEN_CODE (1<<22) /* C or LLVM */

#define IR_GEN_CACHE_DEMOTE (1<<22) /* Demote the generated code from closest CPU caches */
#define IR_GEN_CACHE_DEMOTE (1<<23) /* Demote the generated code from closest CPU caches */

/* debug related */
#ifdef IR_DEBUG
Expand Down Expand Up @@ -751,13 +752,15 @@ ir_ref ir_binding_find(const ir_ctx *ctx, ir_ref ref);
/* Def -> Use lists */
void ir_build_def_use_lists(ir_ctx *ctx);

/* SSA Construction */
int ir_mem2ssa(ir_ctx *ctx);

/* CFG - Control Flow Graph (implementation in ir_cfg.c) */
int ir_build_cfg(ir_ctx *ctx);
int ir_remove_unreachable_blocks(ir_ctx *ctx);
int ir_build_dominators_tree(ir_ctx *ctx);
int ir_find_loops(ir_ctx *ctx);
int ir_schedule_blocks(ir_ctx *ctx);
void ir_build_prev_refs(ir_ctx *ctx);
void ir_reset_cfg(ir_ctx *ctx);

/* SCCP - Sparse Conditional Constant Propagation (implementation in ir_sccp.c) */
int ir_sccp(ir_ctx *ctx);
Expand Down Expand Up @@ -929,7 +932,7 @@ IR_ALWAYS_INLINE void *ir_jit_compile(ir_ctx *ctx, int opt_level, size_t *size)
}

return ir_emit_code(ctx, size);
} else if (opt_level == 1 || opt_level == 2) {
} else if (opt_level > 0) {
if (!(ctx->flags & IR_OPT_FOLDING)) {
// IR_ASSERT(0 && "IR_OPT_FOLDING must be set in ir_init() for -O1 and -O2");
return NULL;
Expand All @@ -938,14 +941,29 @@ IR_ALWAYS_INLINE void *ir_jit_compile(ir_ctx *ctx, int opt_level, size_t *size)

ir_build_def_use_lists(ctx);

if (opt_level == 2
&& !ir_sccp(ctx)) {
return NULL;
if (ctx->flags & IR_OPT_MEM2SSA) {
if (!ir_build_cfg(ctx)
|| !ir_build_dominators_tree(ctx)
|| !ir_mem2ssa(ctx)) {
return NULL;
}
}

if (!ir_build_cfg(ctx)
|| !ir_build_dominators_tree(ctx)
|| !ir_find_loops(ctx)
if (opt_level > 1) {
ir_reset_cfg(ctx);
if (!ir_sccp(ctx)) {
return NULL;
}
}

if (!ctx->cfg_blocks) {
if (!ir_build_cfg(ctx)
|| !ir_build_dominators_tree(ctx)) {
return NULL;
}
}

if (!ir_find_loops(ctx)
|| !ir_gcm(ctx)
|| !ir_schedule(ctx)
|| !ir_match(ctx)
Expand Down
7 changes: 5 additions & 2 deletions ext/opcache/jit/ir/ir_aarch64.dasc
Original file line number Diff line number Diff line change
Expand Up @@ -1095,6 +1095,8 @@ binop_fp:
}
}
return IR_SKIPPED | IR_NOP;
case IR_NOP:
return IR_SKIPPED | IR_NOP;
default:
break;
}
Expand Down Expand Up @@ -5603,7 +5605,8 @@ static void ir_allocate_unique_spill_slots(ir_ctx *ctx)
} else if (def_flags & IR_USE_MUST_BE_IN_REG) {
if (insn->op == IR_VLOAD
&& ctx->live_intervals[ctx->vregs[i]]
&& ctx->live_intervals[ctx->vregs[i]]->stack_spill_pos != -1) {
&& ctx->live_intervals[ctx->vregs[i]]->stack_spill_pos != -1
&& ir_is_same_mem_var(ctx, i, ctx->ir_base[insn->op2].op3)) {
/* pass */
} else if (insn->op != IR_PARAM) {
reg = ir_get_free_reg(insn->type, available);
Expand Down Expand Up @@ -5704,7 +5707,7 @@ static void ir_allocate_unique_spill_slots(ir_ctx *ctx)
if (reg != IR_REG_NONE && IR_REGSET_IN(available, reg)) {
IR_REGSET_EXCL(available, reg);
ctx->regs[i][j] = reg | IR_REG_SPILL_LOAD;
} else if (j > 1 && input == insn->op1 && ctx->regs[i][1] != IR_REG_NONE) {
} else if (IR_IS_FOLDABLE_OP(insn->op) && j > 1 && input == insn->op1 && ctx->regs[i][1] != IR_REG_NONE) {
ctx->regs[i][j] = ctx->regs[i][1];
} else if (use_flags & IR_USE_MUST_BE_IN_REG) {
reg = ir_get_free_reg(ctx->ir_base[input].type, available);
Expand Down
42 changes: 36 additions & 6 deletions ext/opcache/jit/ir/ir_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include "ir.h"
#include "ir_private.h"

static int ir_remove_unreachable_blocks(ir_ctx *ctx);

IR_ALWAYS_INLINE void _ir_add_successors(const ir_ctx *ctx, ir_ref ref, ir_worklist *worklist)
{
ir_use_list *use_list = &ctx->use_lists[ref];
Expand Down Expand Up @@ -57,6 +59,24 @@ IR_ALWAYS_INLINE void _ir_add_predecessors(const ir_insn *insn, ir_worklist *wor
}
}

void ir_reset_cfg(ir_ctx *ctx)
{
ctx->cfg_blocks_count = 0;
ctx->cfg_edges_count = 0;
if (ctx->cfg_blocks) {
ir_mem_free(ctx->cfg_blocks);
ctx->cfg_blocks = NULL;
if (ctx->cfg_edges) {
ir_mem_free(ctx->cfg_edges);
ctx->cfg_edges = NULL;
}
if (ctx->cfg_map) {
ir_mem_free(ctx->cfg_map);
ctx->cfg_map = NULL;
}
}
}

int ir_build_cfg(ir_ctx *ctx)
{
ir_ref n, *p, ref, start, end;
Expand Down Expand Up @@ -330,11 +350,15 @@ static void ir_remove_merge_input(ir_ctx *ctx, ir_ref merge, ir_ref from)
}
}
i--;
for (j = i + 1; j <= n; j++) {
ir_insn_set_op(insn, j, IR_UNUSED);
}
if (i == 1) {
insn->op = IR_BEGIN;
insn->inputs_count = 1;
use_list = &ctx->use_lists[merge];
if (use_list->count > 1) {
n++;
for (k = 0, p = &ctx->use_edges[use_list->refs]; k < use_list->count; k++, p++) {
use = *p;
use_insn = &ctx->ir_base[use];
Expand All @@ -347,22 +371,24 @@ static void ir_remove_merge_input(ir_ctx *ctx, ir_ref merge, ir_ref from)
if (ir_bitset_in(life_inputs, j - 1)) {
use_insn->op1 = ir_insn_op(use_insn, j);
} else if (input > 0) {
ir_use_list_remove_all(ctx, input, use);
ir_use_list_remove_one(ctx, input, use);
}
}
use_insn->op = IR_COPY;
use_insn->op2 = IR_UNUSED;
use_insn->op3 = IR_UNUSED;
use_insn->inputs_count = 1;
for (j = 2; j <= n; j++) {
ir_insn_set_op(use_insn, j, IR_UNUSED);
}
ir_use_list_remove_all(ctx, merge, use);
}
}
}
} else {
insn->inputs_count = i;

n++;
use_list = &ctx->use_lists[merge];
if (use_list->count > 1) {
n++;
for (k = 0, p = &ctx->use_edges[use_list->refs]; k < use_list->count; k++, p++) {
use = *p;
use_insn = &ctx->ir_base[use];
Expand All @@ -378,9 +404,13 @@ static void ir_remove_merge_input(ir_ctx *ctx, ir_ref merge, ir_ref from)
}
i++;
} else if (input > 0) {
ir_use_list_remove_all(ctx, input, use);
ir_use_list_remove_one(ctx, input, use);
}
}
use_insn->inputs_count = i - 1;
for (j = i; j <= n; j++) {
ir_insn_set_op(use_insn, j, IR_UNUSED);
}
}
}
}
Expand All @@ -390,7 +420,7 @@ static void ir_remove_merge_input(ir_ctx *ctx, ir_ref merge, ir_ref from)
}

/* CFG constructed after SCCP pass doesn't have unreachable BBs, otherwise they should be removed */
int ir_remove_unreachable_blocks(ir_ctx *ctx)
static int ir_remove_unreachable_blocks(ir_ctx *ctx)
{
uint32_t b, *p, i;
uint32_t unreachable_count = 0;
Expand Down
4 changes: 4 additions & 0 deletions ext/opcache/jit/ir/ir_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ bool ir_check(const ir_ctx *ctx)
break;
}
}
if (count == 0 && (insn->op == IR_END || insn->op == IR_LOOP_END)) {
/* Dead block */
break;
}
fprintf(stderr, "ir_base[%d].op (%s) must have 1 successor (%d)\n",
i, ir_op_name[insn->op], count);
ok = 0;
Expand Down
Loading
Loading