mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-01-25 20:11:01 +00:00
tcg: Return success from patch_reloc
This will move the assert for success from within (subroutines of) patch_reloc into the callers. It will also let new code do something different when a relocation is out of range. For the moment, all backends are trivially converted to return true. Backports commit 6ac1778676f4259c10b0629ccd9df319a5d1baeb from qemu
This commit is contained in:
parent
294573899f
commit
46189d87b3
|
@ -94,7 +94,7 @@ static inline void reloc_pc19(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||||
*code_ptr = deposit32(*code_ptr, 5, 19, offset);
|
*code_ptr = deposit32(*code_ptr, 5, 19, offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void patch_reloc(tcg_insn_unit *code_ptr, int type,
|
static inline bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||||
intptr_t value, intptr_t addend)
|
intptr_t value, intptr_t addend)
|
||||||
{
|
{
|
||||||
tcg_debug_assert(addend == 0);
|
tcg_debug_assert(addend == 0);
|
||||||
|
@ -109,6 +109,7 @@ static inline void patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||||
default:
|
default:
|
||||||
tcg_abort();
|
tcg_abort();
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TCG_CT_CONST_AIMM 0x100
|
#define TCG_CT_CONST_AIMM 0x100
|
||||||
|
|
|
@ -193,7 +193,7 @@ static inline void reloc_pc24(tcg_insn_unit *code_ptr, tcg_insn_unit *target)
|
||||||
*code_ptr = (*code_ptr & ~0xffffff) | (offset & 0xffffff);
|
*code_ptr = (*code_ptr & ~0xffffff) | (offset & 0xffffff);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void patch_reloc(tcg_insn_unit *code_ptr, int type,
|
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||||
intptr_t value, intptr_t addend)
|
intptr_t value, intptr_t addend)
|
||||||
{
|
{
|
||||||
tcg_debug_assert(addend == 0);
|
tcg_debug_assert(addend == 0);
|
||||||
|
@ -229,6 +229,7 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||||
} else {
|
} else {
|
||||||
g_assert_not_reached();
|
g_assert_not_reached();
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TCG_CT_CONST_ARM 0x100
|
#define TCG_CT_CONST_ARM 0x100
|
||||||
|
|
|
@ -174,7 +174,7 @@ static bool have_lzcnt;
|
||||||
# define have_lzcnt 0
|
# define have_lzcnt 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void patch_reloc(tcg_insn_unit *code_ptr, int type,
|
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||||
intptr_t value, intptr_t addend)
|
intptr_t value, intptr_t addend)
|
||||||
{
|
{
|
||||||
value += addend;
|
value += addend;
|
||||||
|
@ -198,6 +198,7 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||||
default:
|
default:
|
||||||
tcg_abort();
|
tcg_abort();
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if TCG_TARGET_REG_BITS == 64
|
#if TCG_TARGET_REG_BITS == 64
|
||||||
|
|
|
@ -168,12 +168,13 @@ static inline void reloc_26(tcg_insn_unit *pc, tcg_insn_unit *target)
|
||||||
*pc = deposit32(*pc, 0, 26, reloc_26_val(pc, target));
|
*pc = deposit32(*pc, 0, 26, reloc_26_val(pc, target));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void patch_reloc(tcg_insn_unit *code_ptr, int type,
|
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||||
intptr_t value, intptr_t addend)
|
intptr_t value, intptr_t addend)
|
||||||
{
|
{
|
||||||
tcg_debug_assert(type == R_MIPS_PC16);
|
tcg_debug_assert(type == R_MIPS_PC16);
|
||||||
tcg_debug_assert(addend == 0);
|
tcg_debug_assert(addend == 0);
|
||||||
reloc_pc16(code_ptr, (tcg_insn_unit *)value);
|
reloc_pc16(code_ptr, (tcg_insn_unit *)value);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define TCG_CT_CONST_ZERO 0x100
|
#define TCG_CT_CONST_ZERO 0x100
|
||||||
|
|
|
@ -513,7 +513,7 @@ static const uint32_t tcg_to_isel[] = {
|
||||||
[TCG_COND_GTU] = ISEL | BC_(7, CR_GT),
|
[TCG_COND_GTU] = ISEL | BC_(7, CR_GT),
|
||||||
};
|
};
|
||||||
|
|
||||||
static void patch_reloc(tcg_insn_unit *code_ptr, int type,
|
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||||
intptr_t value, intptr_t addend)
|
intptr_t value, intptr_t addend)
|
||||||
{
|
{
|
||||||
tcg_insn_unit *target;
|
tcg_insn_unit *target;
|
||||||
|
@ -548,6 +548,7 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||||
default:
|
default:
|
||||||
g_assert_not_reached();
|
g_assert_not_reached();
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tcg_out_mem_long(TCGContext *s, int opi, int opx, TCGReg rt,
|
static void tcg_out_mem_long(TCGContext *s, int opi, int opx, TCGReg rt,
|
||||||
|
|
|
@ -372,7 +372,7 @@ static tcg_insn_unit *tb_ret_addr;
|
||||||
|
|
||||||
uint64_t s390_facilities;
|
uint64_t s390_facilities;
|
||||||
|
|
||||||
static void patch_reloc(tcg_insn_unit *code_ptr, int type,
|
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||||
intptr_t value, intptr_t addend)
|
intptr_t value, intptr_t addend)
|
||||||
{
|
{
|
||||||
intptr_t pcrel2;
|
intptr_t pcrel2;
|
||||||
|
@ -399,6 +399,7 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||||
default:
|
default:
|
||||||
g_assert_not_reached();
|
g_assert_not_reached();
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* parse target specific constraints */
|
/* parse target specific constraints */
|
||||||
|
|
|
@ -293,7 +293,7 @@ static inline int check_fit_i32(int32_t val, unsigned int bits)
|
||||||
# define check_fit_ptr check_fit_i32
|
# define check_fit_ptr check_fit_i32
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void patch_reloc(tcg_insn_unit *code_ptr, int type,
|
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||||
intptr_t value, intptr_t addend)
|
intptr_t value, intptr_t addend)
|
||||||
{
|
{
|
||||||
uint32_t insn = *code_ptr;
|
uint32_t insn = *code_ptr;
|
||||||
|
@ -319,6 +319,7 @@ static void patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||||
}
|
}
|
||||||
|
|
||||||
*code_ptr = insn;
|
*code_ptr = insn;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* parse target specific constraints */
|
/* parse target specific constraints */
|
||||||
|
|
|
@ -63,7 +63,7 @@
|
||||||
static void tcg_target_init(TCGContext *s);
|
static void tcg_target_init(TCGContext *s);
|
||||||
static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode);
|
static const TCGTargetOpDef *tcg_target_op_def(TCGOpcode);
|
||||||
static void tcg_target_qemu_prologue(TCGContext *s);
|
static void tcg_target_qemu_prologue(TCGContext *s);
|
||||||
static void patch_reloc(tcg_insn_unit *code_ptr, int type,
|
static bool patch_reloc(tcg_insn_unit *code_ptr, int type,
|
||||||
intptr_t value, intptr_t addend);
|
intptr_t value, intptr_t addend);
|
||||||
|
|
||||||
/* The CIE and FDE header definitions will be common to all hosts. */
|
/* The CIE and FDE header definitions will be common to all hosts. */
|
||||||
|
@ -219,7 +219,8 @@ static void tcg_out_reloc(TCGContext *s, tcg_insn_unit *code_ptr, int type,
|
||||||
/* FIXME: This may break relocations on RISC targets that
|
/* FIXME: This may break relocations on RISC targets that
|
||||||
modify instruction fields in place. The caller may not have
|
modify instruction fields in place. The caller may not have
|
||||||
written the initial value. */
|
written the initial value. */
|
||||||
patch_reloc(code_ptr, type, l->u.value, addend);
|
bool ok = patch_reloc(code_ptr, type, l->u.value, addend);
|
||||||
|
tcg_debug_assert(ok);
|
||||||
} else {
|
} else {
|
||||||
/* add a new relocation entry */
|
/* add a new relocation entry */
|
||||||
r = tcg_malloc(s, sizeof(TCGRelocation));
|
r = tcg_malloc(s, sizeof(TCGRelocation));
|
||||||
|
@ -239,7 +240,8 @@ static void tcg_out_label(TCGContext *s, TCGLabel *l, tcg_insn_unit *ptr)
|
||||||
tcg_debug_assert(!l->has_value);
|
tcg_debug_assert(!l->has_value);
|
||||||
|
|
||||||
for (r = l->u.first_reloc; r != NULL; r = r->next) {
|
for (r = l->u.first_reloc; r != NULL; r = r->next) {
|
||||||
patch_reloc(r->ptr, r->type, value, r->addend);
|
bool ok = patch_reloc(r->ptr, r->type, value, r->addend);
|
||||||
|
tcg_debug_assert(ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
l->has_value = 1;
|
l->has_value = 1;
|
||||||
|
|
Loading…
Reference in a new issue