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

Wrong lifting results for simple programs #1138

Open
Qiuye-Hua opened this issue Mar 14, 2023 · 0 comments
Open

Wrong lifting results for simple programs #1138

Qiuye-Hua opened this issue Mar 14, 2023 · 0 comments

Comments

@Qiuye-Hua
Copy link

I was trying retdec's ability to rise from ARM64 to C. Firstly I wrote the following (most simple) assembly code asmadd.s:

.arch armv8-a
.text
.global	asmadd
.type	asmadd, %function
asmadd:
	add	w0, w0, w1
	ret

The assembly and lifting are done by the following commands:

aarch64-linux-gnu-as asmadd.s -o asmadd.o
retdec-decompiler asmadd.o -a arm64

I was expecting the result to be something like:

int32_t asmadd(int32_t a, int32_t b)
{
    return a + b;
}

Instead, I got:

// Address range: 0x0 - 0x8
int32_t asmadd(int32_t a1) {
    int32_t result = a1; // 0x0
    bool v1; // 0x0
    if (false == !v1) {
        result = (int32_t)*(char *)12;
    }
    // 0x40008
    return result;
}

which is obviously wrong.

Is there something missing in the above steps? Or is there a way that I can "tell" RetDec how to do the lifting correctly?


BTW, here is the emitted LLVM IR. It seems that IR is wrong already.

source_filename = "test"
target datalayout = "e-p:32:32:32-f80:32:32"

define i32 @asmadd(i32 %arg1) local_unnamed_addr {
dec_label_pc_0:
  %0 = alloca i1
  %r0.0.reg2mem = alloca i32, !insn.addr !0
  %1 = load i1, i1* %0
  %2 = load i1, i1* %0
  %3 = load i1, i1* %0
  %.not = icmp ne i1 %2, true
  %4 = icmp ne i1 %3, %1, !insn.addr !1
  %or.cond = icmp eq i1 %4, %.not
  store i32 %arg1, i32* %r0.0.reg2mem, !insn.addr !0
  br i1 %or.cond, label %5, label %dec_label_pc_40008, !insn.addr !0

; <label>:5:                                      ; preds = %dec_label_pc_0
  %6 = load i8, i8* inttoptr (i32 12 to i8*), align 4, !insn.addr !1
  %7 = zext i8 %6 to i32, !insn.addr !1
  store i32 %7, i32* %r0.0.reg2mem, !insn.addr !1
  br label %dec_label_pc_40008, !insn.addr !1

dec_label_pc_40008:                               ; preds = %dec_label_pc_0, %5
  %r0.0.reload = load i32, i32* %r0.0.reg2mem
  ret i32 %r0.0.reload, !insn.addr !1

; uselistorder directives
  uselistorder i32* %r0.0.reg2mem, { 0, 2, 1 }
  uselistorder i1* %0, { 2, 1, 0 }
  uselistorder i32 1, { 1, 0 }
  uselistorder label %dec_label_pc_40008, { 1, 0 }
}

!0 = !{i64 0}
!1 = !{i64 4}
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

1 participant