Skip to content

3) Compile IR to EXE

Tim B edited this page Aug 5, 2017 · 1 revision

IR -> EXE

In this chapter we want to create a exe from IR Code.

IR -> OBJ

For this step you need a compiler. LLC is part of the LLVM Infrastructure. Sadly it is not delivered in the LLVM Setup. Why? I don't know.

Getting LLC

You have two options to get LLC for Windows

  1. Trust me and download my precompiled binary from : https://github.com/TimBo93/LLVM-Windows/releases/tag/v4.0.1

  2. Download LLVM Sources for Windows and follow the steps to build LLC on your own.

Using LLC to create a obj file

llc -filetype=obj main.ll

now you have a linkable object file.

OBJ -> EXE

This is a little bit tricky. You need a linker. You can use LINK.exe from Visual Studio or you can use lld from LLVM. I recommend you to use lld for windows (lld-link).

lld-link -out:b.exe -defaultlib:libcmt "-libpath:C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\lib\\amd64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.15063.0\\ucrt\\x64" "-libpath:C:\\Program Files (x86)\\Windows Kits\\10\\Lib\\10.0.15063.0\\um\\x64" -nologo main.obj

this creates a b.exe which is ready to be executed.

lld-link parameters

Where does the parameter come from? I looked how clang links object files using lld. Just execute clang -fuse-ld=lld -v main.cpp and inspect the parameters for lld-link.

Clone this wiki locally