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

generate invalid llir instructions #198

Open
shiyuanxiang opened this issue Feb 26, 2024 · 4 comments
Open

generate invalid llir instructions #198

shiyuanxiang opened this issue Feb 26, 2024 · 4 comments

Comments

@shiyuanxiang
Copy link

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
Copy link

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
Copy link
Contributor

compile command gcc helloworld.c

Please share the output of the command gcc -v.

Thanks!

@bharadwajy
Copy link
Contributor

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
Copy link

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!

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