Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Aarch64] float instruction fmov unrecognized, src and dst go wrong,float register value not saved #4408

Closed
Eliana-Xie opened this issue Aug 16, 2020 · 7 comments
Assignees

Comments

@Eliana-Xie
Copy link

Describe the bug
[linux aarch64] cannot recognize fmov instruction,instr_num_srcs and instr_num_dsts result error

To Reproduce
Steps to reproduce the behavior:

  1. test.c
float a = 3.0;
printf("%f", a);

40062c: 1e211000 fmov s0, #3.000000000000000000e+00
400630: bd001fa0 str s0, [x29, #28]
400634: bd401fa0 ldr s0, [x29, #28]
400638: 1e22c000 fcvt d0, s0

  1. ./../bin64/drrun -c bin/libinstrace_simple.so -- ./float_test

modify instrument_instr funtion

    num = instr_num_srcs(where);
    printf(" src: %d ", num);
    for (i = 0; i < num; ++i)
    {
        insert_save_src(drcontext, ilist, where, reg_ptr, reg_tmp, instr_get_src(where, i), i);
    }
    
    num = instr_num_dsts(where);
    printf(" dst: %d ", num);
    for (i = 0; i < num; ++i)
    {
        insert_save_dst(drcontext, ilist, where, reg_ptr, reg_tmp, instr_get_dst(where, i), i);
    }

add insert_save_src function

static void
insert_save_src(void *drcontext, instrlist_t *ilist, instr_t *where, reg_id_t base, reg_id_t scratch, opnd_t opnd, int i)
{
    if(opnd_is_reg(opnd)) {
        reg_id_t regid = opnd_get_reg(opnd);
        if(regid >= DR_REG_S0 && regid <= DR_REG_B31){
            printf("reg:%d\n", regid);
            opnd_t dst_addr = opnd_create_base_disp(base, DR_REG_NULL, 0, offsetof(ins_ref_t, src[i]), reg_get_size(regid));
            instr_t* instr = instr_create_1dst_1src(drcontext, OP_str, dst_addr, opnd);
            char disas_instr[196];
            instr_disassemble_to_buffer(drcontext, instr, disas_instr, 196);
            printf("instruction: %s\n", disas_instr);
            instrlist_meta_preinsert(ilist, where, instr);
        }
    }
}
  1. Exact output or incorrect behavior.

pc: 40062c src: 5 dst: 4
pc: 400630 src: 1 reg:132
instruction: str %s0 -> +0x0c(%x2)[4byte]
dst: 1
pc: 400634 src: 1 dst: 1 reg:132
instruction: str %s0 -> +0x1c(%x2)[4byte]
pc: 400638 src: 1 reg:132
instruction: str %s0 -> +0x0c(%x2)[4byte]
3.000000

0x40062c,xx,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000
0x400630,str,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000
0x400634,ldr,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000
0x400638,fcvt,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000
0x40063c,adrp,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000,0.000000

Expected behavior
A clear and concise description of what you expected to happen.

  1. recognize fmov instruction
  2. save register value to TLS variable, 3.000000
  3. get fmov correct srcs and dst nums;

Versions

  • What version of DynamoRIO are you using? DynamoRIO 8.0.0-1
  • Does the latest build from
    https://github.com/DynamoRIO/dynamorio/wiki/Latest-Build solve the problem?
  • What operating system version are you running on? ("Windows 10" is not sufficient: give the release number.)
  • Is your application 32-bit or 64-bit? 64bit

Additional context
Add any other context about the problem here.

@derekbruening
Copy link
Contributor

@AssadHashmi if you could take a look -- the fmov part may be related to #3044?

@AssadHashmi
Copy link
Contributor

@AssadHashmi if you could take a look -- the fmov part may be related to #3044?

The immediate variants of fmov as described in the sample above are not currently supported in the decoder. I'll add them.
The general purpose register fmovs are supported and should work.

@Eliana-Xie
Copy link
Author

add failed too
Data file /home/xxx/DynamoRIO-AArch64-Linux-8.0.0-1/samples/build/bin/float_trace.float_test.68917.0000.log created
<Internal Error: Failed to encode instruction: 'add %x3 $0x002c -> %x4'

<Application /home/xxx/DynamoRIO-AArch64-Linux-8.0.0-1/samples/build/float_test (68917). Internal Error: DynamoRIO debug check failure: /home/travis/build/DynamoRIO/dynamorio/core/emit.c:360 pc != NULL
(Error occurred @1345 frags)
version 8.0.0, build 1

@derekbruening
Copy link
Contributor

Update: @AssadHashmi has a partial fix completed; due to scheduling the work will be picked up again mid-September.

@derekbruening
Copy link
Contributor

@AssadHashmi : did #4467 fix this? There was no "Fixes" nor "Issue" in its commit description.

@AssadHashmi
Copy link
Contributor

@AssadHashmi : did #4467 fix this? There was no "Fixes" nor "Issue" in its commit description.

Yes @derekbruening, apologies for the tardy commit description :-/

@derekbruening
Copy link
Contributor

Closed by #4467.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants