microsoft / llvm-mctoll

llvm-mctoll
Other
816 stars 125 forks source link

generate invalid llir instructions #198

Open shiyuanxiang opened 9 months ago

shiyuanxiang commented 9 months ago

source code helloworld.c

#include<stdio.h>

int main(){
printf("helloworld!");
return 0;
}

compile command gcc helloworld.c

execute command llvm-mctoll -d a.out -I /usr/include/stdio.h

generated a.out-dis.ll

execute command cat a.out-dis.ll

output

ModuleID = 'a.out'
source_filename = "a.out"

@rodata_18 = private unnamed_addr constant [16 x i8] c"\01\00\02\00helloworld!\00", align 4, !ROData_SecInfo !0

declare dso_local i32 @printf(ptr, ...)

define dso_local i32 @main() {
entry:
  %RSP_P.0 = alloca i64, align 1
  store i64 3735928559, ptr %RSP_P.0, align 8
  %RBP = ptrtoint ptr %RSP_P.0 to i64
  %EAX = call i32 (ptr, ...) @printf(ptr getelementptr inbounds ([16 x i8], ptr @rodata_18, i32 0, i32 4))
  ret i32 0
}

!0 = !{i64 8192}

execute command llvm-as a.out-dis.ll -o a.out-dis.bc

errors

error: '@rodata_18' defined with type '[16 x i8]*' but expected 'i8*'
  %EAX = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], i8* @rodata_18, i32 0, i32 4))

a.out-dis.ll:6:31: error: expected type
declare dso_local i32 @printf(ptr, ...)
hushenwei2000 commented 5 months ago

I met the same problem. But I encouter "expected type" error, seems like the compiler don't know the type definition

bash-4.2$ clang switch4-dis.ll
switch4-dis.ll:7:19: error: expected type
  %tos = ptrtoint ptr %stktop_8 to i64
                  ^
1 error generated.
bharadwajy commented 5 months ago

compile command gcc helloworld.c

Please share the output of the command gcc -v.

Thanks!

bharadwajy commented 5 months ago

I met the same problem. But I encouter "expected type" error, seems like the compiler don't know the type definition

bash-4.2$ clang switch4-dis.ll
switch4-dis.ll:7:19: error: expected type
  %tos = ptrtoint ptr %stktop_8 to i64
                  ^
1 error generated.

Please share the sources of the binary used as input to llvm-mctoll that resulted in switch-dis.ll, the compiler version and any additional compiler options used to build the binary.

Thanks!

hushenwei2000 commented 4 months ago

I met the same problem. But I encouter "expected type" error, seems like the compiler don't know the type definition

bash-4.2$ clang switch4-dis.ll
switch4-dis.ll:7:19: error: expected type
  %tos = ptrtoint ptr %stktop_8 to i64
                  ^
1 error generated.

Please share the sources of the binary used as input to llvm-mctoll that resulted in switch-dis.ll, the compiler version and any additional compiler options used to build the binary.

Thanks!

I found the problem is that I was using LLVM 13 before, and after I changed to LLVM 16, the opaque pointer could be compiled correctly. Thank you!