Skip to content

Commit

Permalink
i#2417 AArch64: Make stolen-reg test more reliable (#6878)
Browse files Browse the repository at this point in the history
The test client prints a message for any load/store that uses the stolen
register as the index, assuming only the two instructions in the test
app will be found.

I have seen in at least one case the test outputs an extra line because
it found an additional instruction that used the stolen register as the
index. Presumably this instruction came from a system library so this
problem is OS dependent.

I have made the test more robust by changing the client to look for
    mov <stolen_register>, #0
before the load/store which is present in the test app but unlikely to
appear before matching load/stores in system libraries.

Issue: #2417
  • Loading branch information
jackgallagher-arm authored Jul 17, 2024
1 parent ef2b2f5 commit 6e17111
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions suite/tests/client-interface/stolen-reg-index.dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,15 @@ insert_get_addr(void *drcontext, instrlist_t *ilist, instr_t *instr, opnd_t mref
return true;
}

static bool
prev_is_mov_0(instr_t *inst, reg_id_t dst_reg)
{
instr_t *prev = instr_get_prev(inst);
ptr_int_t value = ~0;
return prev != NULL && instr_is_mov_constant(prev, &value) && value == 0 &&
opnd_get_reg(instr_get_dst(prev, 0)) == dst_reg;
}

static dr_emit_flags_t
event_app_instruction(void *drcontext, void *tag, instrlist_t *bb, instr_t *inst,
bool for_trace, bool translating, void *user_data)
Expand All @@ -128,9 +137,11 @@ event_app_instruction(void *drcontext, void *tag, instrlist_t *bb, instr_t *inst
if (instr_writes_memory(inst)) {
opnd = instr_get_dst(inst, 0);
if (opnd_is_memory_reference(opnd) && opnd_is_base_disp(opnd)) {
if (opnd_get_index(opnd) == stolen && opnd_get_base(opnd) == DR_REG_X0)
if (opnd_get_index(opnd) == stolen && opnd_get_base(opnd) == DR_REG_X0 &&
prev_is_mov_0(inst, stolen))
dr_printf("store memref with index reg X28\n");
if (opnd_get_index(opnd) == DR_REG_W28 && opnd_get_base(opnd) == DR_REG_X0)
if (opnd_get_index(opnd) == DR_REG_W28 && opnd_get_base(opnd) == DR_REG_X0 &&
prev_is_mov_0(inst, DR_REG_W28))
dr_printf("store memref with index reg W28\n");
if (insert_get_addr(drcontext, bb, inst, instr_get_dst(inst, 0)))
return DR_EMIT_DEFAULT;
Expand All @@ -145,9 +156,11 @@ event_app_instruction(void *drcontext, void *tag, instrlist_t *bb, instr_t *inst
if (instr_reads_memory(inst)) {
opnd = instr_get_src(inst, 0);
if (opnd_is_memory_reference(opnd) && opnd_is_base_disp(opnd)) {
if (opnd_get_index(opnd) == stolen && opnd_get_base(opnd) == DR_REG_X0)
if (opnd_get_index(opnd) == stolen && opnd_get_base(opnd) == DR_REG_X0 &&
prev_is_mov_0(inst, stolen))
dr_printf("load memref with index reg X28\n");
if (opnd_get_index(opnd) == DR_REG_W28 && opnd_get_base(opnd) == DR_REG_X0)
if (opnd_get_index(opnd) == DR_REG_W28 && opnd_get_base(opnd) == DR_REG_X0 &&
prev_is_mov_0(inst, DR_REG_W28))
dr_printf("load memref with index reg W28\n");
if (insert_get_addr(drcontext, bb, inst, instr_get_src(inst, 0)))
return DR_EMIT_DEFAULT;
Expand Down

0 comments on commit 6e17111

Please sign in to comment.