Closed tianboh closed 4 months ago
Well, I guess maybe the default gcc compiler is too old. I use clang 14.0 to generate the .out file and then run mctoll, it can successfully generate LLVM IR file.
However, I am still curious how mctoll handles pointer type.
I figured it out. tried following toy example
#include <stdlib.h>
double* dptradd(double* a, double* b){
double* c = malloc(sizeof(double));
*c = *a + *b;
return c;
}
int main(){
double a = 1.0;
double b = 2.0;
double* c = dptradd(&a, &b);
return 0;
}
And generated ll file as below
; ModuleID = 'a.out'
source_filename = "a.out"
@rodata_15 = private unnamed_addr constant [24 x i8] c"\01\00\02\00\00\00\00\00\00\00\00\00\00\00\00@\00\00\00\00\00\00\F0?", align 8, !ROData_SecInfo !0
declare dso_local ptr @malloc(i64)
define dso_local i64 @dptradd(i64 %arg1, i64 %arg2) {
entry:
%stktop_8 = alloca i8, i32 40, align 1
%tos = ptrtoint ptr %stktop_8 to i64
%0 = add i64 %tos, 16
%RBP_N.24 = inttoptr i64 %0 to ptr
%1 = add i64 %tos, 24
%RBP_N.16 = inttoptr i64 %1 to ptr
%2 = add i64 %tos, 32
%RBP_N.8 = inttoptr i64 %2 to ptr
%3 = add i64 %tos, 0
%RSP_P.0 = inttoptr i64 %3 to ptr
store i64 3735928559, ptr %RSP_P.0, align 8
%RBP = ptrtoint ptr %RSP_P.0 to i64
store i64 %arg1, ptr %RBP_N.8, align 1
store i64 %arg2, ptr %RBP_N.16, align 1
%4 = zext i32 8 to i64
%5 = call ptr @malloc(i64 %4)
%RAX = ptrtoint ptr %5 to i64
store i64 %RAX, ptr %RBP_N.24, align 1
%memload = load i64, ptr %RBP_N.8, align 1
%6 = inttoptr i64 %memload to ptr
%memload1 = load double, ptr %6, align 1
%memload2 = load i64, ptr %RBP_N.16, align 1
%7 = inttoptr i64 %memload2 to ptr
%memload3 = load double, ptr %7, align 1
%XMM0 = fadd double %memload1, %memload3
%memload4 = load i64, ptr %RBP_N.24, align 1
%8 = inttoptr i64 %memload4 to ptr
store double %XMM0, ptr %8, align 1
%memload5 = load i64, ptr %RBP_N.24, align 1
ret i64 %memload5
}
define dso_local i32 @main() {
entry:
%stktop_8 = alloca i8, i32 40, align 1
%tos = ptrtoint ptr %stktop_8 to i64
%0 = add i64 %tos, 16
%RBP_N.24 = inttoptr i64 %0 to ptr
%1 = add i64 %tos, 24
%RBP_N.16 = inttoptr i64 %1 to ptr
%2 = add i64 %tos, 36
%RBP_N.4 = inttoptr i64 %2 to ptr
%3 = add i64 %tos, 0
%RSP_P.0 = inttoptr i64 %3 to ptr
store i64 3735928559, ptr %RSP_P.0, align 8
%RBP = ptrtoint ptr %RSP_P.0 to i64
%memload = load double, ptr getelementptr inbounds ([24 x i8], ptr @rodata_15, i32 0, i32 8), align 1, !ROData_Content !1
%memload1 = load double, ptr getelementptr inbounds ([24 x i8], ptr @rodata_15, i32 0, i32 16), align 1, !ROData_Content !2
store i32 0, ptr %RBP_N.4, align 1
store double %memload1, ptr %RBP_N.16, align 1
store double %memload, ptr %RBP_N.24, align 1
%RDI = ptrtoint ptr %RBP_N.16 to i64
%RSI = ptrtoint ptr %RBP_N.24 to i64
%RAX = call i64 @dptradd(i64 %RDI, i64 %RSI)
store i64 %RAX, ptr %stktop_8, align 1
ret i32 0
}
!0 = !{i64 4202496}
!1 = !{ptr getelementptr inbounds ([24 x i8], ptr @rodata_15, i32 0, i32 8)}
!2 = !{ptr getelementptr inbounds ([24 x i8], ptr @rodata_15, i32 0, i32 16)}
The pointer is just an address, it does not matter whether use i64 or other 64 bit type. The real operation that matters is fadd. This is properly handled in the following instruction raise part.
Hi there,
I am trying to disassemble a toy c file.
Then compile as below
Once compiled and successfully generate
a.out
file, I use llvm-mctoll to disassemble it. I used following commands, but failedError log
I checked elf file using llvm-objdump, but cannot find function
__stack_chk_fail
.Am I missing anything? Or maybe mctoll does not support pointer parameters yet? I read
x86FuncPrototypeDiscovery.cpp
, and foundArgTyVec
is treating 64-bit physical register as int64 (instead of checking it may be a pointer).