Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make llvm .bc file executable?

Tags:

llvm

I have created a toy language that generates IR code and writes that code to a binary file with WriteBitcodeToFile (the C API). The result is a my-file.bc file.

In this file I have defined a main() function that takes no arguments and returns an int64 (should I change return type to byte maybe). How do I make this .bc file an executable. I'm running Linux.

Fredrik

like image 500
Fredrik Andersson Avatar asked Sep 11 '15 12:09

Fredrik Andersson


People also ask

How do I run a BC file?

It is possible to execute a bc-file with lli command. However that doesn't create a stand alone executable product. Show activity on this post. There's always the option of using llc to compile to assembly from which you can generate an executable.

What is .bc file LLVM?

Overview. What is commonly known as the LLVM bitcode file format (also, sometimes anachronistically known as bytecode) is actually two things: a bitstream container format and an encoding of LLVM IR into the container format.

Can you use LLVM with C?

Only the C and C++ languages are needed so there's no need to build the other languages for LLVM's purposes. See below for specific version info. Only needed if you want to run the automated test suite in the llvm/test directory.


1 Answers

You can generate an object file with llc and then use GCC to create an executable:

llc -filetype=obj my-file.bc
gcc my-file.o
./a.out

You can read more about llc on http://llvm.org/docs/CommandGuide/llc.html.

like image 154
box Avatar answered Sep 21 '22 09:09

box