Stream: cranelift

Topic: ✔ Binary format is unknown error when compiling Cranelift IR


view this post on Zulip Lee Wei (Feb 26 2024 at 07:47):

Hello! I'm building my toy compiler with Cranelift as my backend.
I'm getting binary format unknown error with the following command (tried this command on both Linux and MacOS):

$ clif-util compile --target x86_64 -o test.o filetests/main.clif
Error: Backend error: binary format is unknown

Caused by:
    binary format is unknown
// main.clif
test run
target x86_64

function %main() -> i32 {
block0:
    v0 = iconst.i32 42
    return v0
}
; print: %main()
; run: %main() == 4

Can anyone give me some hints for this issue? Both clif-util test and clif-util run can execute perfectly.
Right now, I'm thinking to compile Cranelift IR into object file, and then link it with dynamic library with gcc, so that I can get an executable. Or maybe there are alternatives to achieve this goal? Thanks in advanced!

view this post on Zulip Notification Bot (Feb 26 2024 at 07:52):

Lee Wei has marked this topic as resolved.

view this post on Zulip Notification Bot (Feb 26 2024 at 07:52):

Lee Wei has marked this topic as unresolved.

view this post on Zulip bjorn3 (Feb 26 2024 at 11:17):

You need to specify the full target I think rather than just the architecture. Otherwise it wouldn't know if the correct object file format to use should be ELF, Mach-O or COFF. Try clif-util compile --target x86_64-apple-darwin -o test.o filetests/main.clif if you want a Mach-O object file.

view this post on Zulip bjorn3 (Feb 26 2024 at 11:17):

On linux you did use x86_64-unknown-linux-gnu as target.

view this post on Zulip bjorn3 (Feb 26 2024 at 11:19):

@Lee Wei

view this post on Zulip Lee Wei (Feb 26 2024 at 12:37):

@bjorn3 Thanks! It worked!

view this post on Zulip Notification Bot (Feb 26 2024 at 12:37):

Lee Wei has marked this topic as resolved.


Last updated: Nov 22 2024 at 16:03 UTC