tcg: Restart TB generation after constant pool overflow

This is part b of relocation overflow handling.

Backports commit 1768987b73fa7e23e58b7844abe5882490ff8e42 from qemu
This commit is contained in:
Richard Henderson 2019-04-30 10:00:51 -04:00 committed by Lioncash
parent 45315fd8ef
commit 196631e0a4
No known key found for this signature in database
GPG key ID: 4E3C3CC1031BA9C7
2 changed files with 12 additions and 9 deletions

View file

@ -121,14 +121,14 @@ static inline void new_pool_l8(TCGContext *s, int rtype, tcg_insn_unit *label,
/* To be provided by cpu/tcg-target.inc.c. */ /* To be provided by cpu/tcg-target.inc.c. */
static void tcg_out_nop_fill(tcg_insn_unit *p, int count); static void tcg_out_nop_fill(tcg_insn_unit *p, int count);
static bool tcg_out_pool_finalize(TCGContext *s) static int tcg_out_pool_finalize(TCGContext *s)
{ {
TCGLabelPoolData *p = s->pool_labels; TCGLabelPoolData *p = s->pool_labels;
TCGLabelPoolData *l = NULL; TCGLabelPoolData *l = NULL;
void *a; void *a;
if (p == NULL) { if (p == NULL) {
return true; return 0;
} }
/* ??? Round up to qemu_icache_linesize, but then do not round /* ??? Round up to qemu_icache_linesize, but then do not round
@ -142,15 +142,17 @@ static bool tcg_out_pool_finalize(TCGContext *s)
size_t size = sizeof(tcg_target_ulong) * p->nlong; size_t size = sizeof(tcg_target_ulong) * p->nlong;
if (!l || l->nlong != p->nlong || memcmp(l->data, p->data, size)) { if (!l || l->nlong != p->nlong || memcmp(l->data, p->data, size)) {
if (unlikely(a > s->code_gen_highwater)) { if (unlikely(a > s->code_gen_highwater)) {
return false; return -1;
} }
memcpy(a, p->data, size); memcpy(a, p->data, size);
a += size; a += size;
l = p; l = p;
} }
patch_reloc(p->label, p->rtype, (intptr_t)a - size, p->addend); if (!patch_reloc(p->label, p->rtype, (intptr_t)a - size, p->addend)) {
return -2;
}
} }
s->code_ptr = a; s->code_ptr = a;
return true; return 0;
} }

View file

@ -440,8 +440,8 @@ void tcg_prologue_init(TCGContext *s)
#ifdef TCG_TARGET_NEED_POOL_LABELS #ifdef TCG_TARGET_NEED_POOL_LABELS
/* Allow the prologue to put e.g. guest_base into a pool entry. */ /* Allow the prologue to put e.g. guest_base into a pool entry. */
{ {
bool ok = tcg_out_pool_finalize(s); int result = tcg_out_pool_finalize(s);
tcg_debug_assert(ok); tcg_debug_assert(result == 0);
} }
#endif #endif
@ -3378,8 +3378,9 @@ int tcg_gen_code(TCGContext *s, TranslationBlock *tb)
} }
#endif #endif
#ifdef TCG_TARGET_NEED_POOL_LABELS #ifdef TCG_TARGET_NEED_POOL_LABELS
if (!tcg_out_pool_finalize(s)) { i = tcg_out_pool_finalize(s);
return -1; if (i < 0) {
return i;
} }
#endif #endif