What platform can I compile binaries for, using LLVM (Low Level Virtual Machine)?
Asked Answered
L

4

7

I am interested in using the LLVM's Clang compiler. LLVM claims to be cross-platform however it is not clear which platforms can be targeted. I have done quite a lot of Googling on this but there doesn't seem to be much information about LLVM's supported platforms. The only thing I did find was "this" which is kinda confusing. I am not sure if it means I can compile binaries for those platforms using LLVM or if it just runs on those platforms (or both). Could someone who knows more about the LLVM/Clang compiler tell me which platforms I can target using Clang or any other LLVM front ends? I want specific information (like "It supports Windows 32bit, Windows 64bit, Linux 32bit, Linux 64bit, etc). Thanks!

EDIT:

Ok, I think I am just confused about what LLVM really is. From what I just figured out LLVM is simply a byte-code interpreter. Since LLVM is interpreted how much slower is LLVM binaries compared to executable binaries? So if performance is important LLVM is not the right choice? "Here" I found the architectures it supports but it did not say what operating systems it supports. Does it run on all operating systems if I avoid platform dependent code? I will look for more articles that explain LLVM in more detail if I can find any.

Laresa answered 3/9, 2011 at 21:16 Comment(2)
Are you asking "which platforms have an LLVM bytecode interpreter?" or "which platforms does clang have a code generation backend for?"Sommer
I am more curios about LLVM than Clang. Clang is just the front end I want to use.Laresa
V
1

I'm only answering the edit's question here (it would probably be more appropriate to make a new question).

This is a good architectural overview of LLVM. This page also contains a ton of documentations on all aspects of LLVM.

The short version is that LLVM is the optimizer and backend of a traditionnal compiler. It operates on a bytecode which is essentially it's intermediate representation of the code and is used to optimize and generate the final binary. The LLVM frontends are independent and uses there own internal ASTs to eventually generate bytecode.

LLVM is actually pretty flexible when it comes to when you want to generate the final binary. You can either do it right away or delay it until the program is being installed. I believe you can even use its JIT to generate the final binary during execution (not 100% sure of this). The main advantage of delaying like this is that it can apply optimizations that are specific to the environment it is executing on.

Viscosity answered 4/9, 2011 at 3:31 Comment(0)
D
9

With llvm installed type

llc -version

and you will see something like

  Registered Targets:
    alpha   - Alpha [experimental]
    arm     - ARM
    bfin    - Analog Devices Blackfin [experimental]
    c       - C backend
    cellspu - STI CBEA Cell SPU [experimental]
    cpp     - C++ backend
    mblaze  - MBlaze
    mips    - Mips
    mipsel  - Mipsel
    msp430  - MSP430 [experimental]
    ppc32   - PowerPC 32
    ppc64   - PowerPC 64
    ptx32   - PTX (32-bit) [Experimental]
    ptx64   - PTX (64-bit) [Experimental]
    sparc   - Sparc
    sparcv9 - Sparc V9
    systemz - SystemZ
    thumb   - Thumb
    x86     - 32-bit X86: Pentium-Pro and above
    x86-64  - 64-bit X86: EM64T and AMD64
    xcore   - XCore

Go to github.com and search for mbed_samples to see llvm and clang being used to cross compile for ARM. Somewhere around blinker03 or 04 is where it comes in. LLVM works the same way for any platform, the llc step is where you choose your target, the compiling merging, optimizing, etc are all platform independent (well you might use -m32 for example to choose the int size) then llc gets you to platform dependent assembler.

Dram answered 4/9, 2011 at 3:18 Comment(6)
AFAIK the steps from assembler to object to binary are only the platform you are running on, if you use binutils you can take any of the targets to a binary.Dram
Note that these changed a lot since 2011. For example support for bfin, alpha and systemz has been dropped in with llvm 3.1Lengthy
sure, thus the instructions on how to do it. although we know llvm folks tend to change their command lines over time and leave you stuck with unusable build scripts/makefiles.Dram
and as a result of that, since 2011, to survive, I have switched to building my own llvm/clang toolchain, gnu style, meaning build for that target (from sources), one toolchain per target. A side effect is that you can use the llvm linker and not rely on gnu tools. Still have to figure out what targets they support and now to specify that target in the build.Dram
I dont know when that edit happened relative to my original answer. LLVM/clang is perhaps originally designed/intended as a JIT, just in time deal to take the bytecode at/near runtime and make a binary. And maybe you can try to figure that out, but it can be and I would assume the primary use case, is as a normal toolchain that can complete with gnu binutils/gcc to produce binaries for many targets to be run later.Dram
you should be able to find pre-built native tools for linux on x86, windows this and that, and simply run clang hello_world.c -o hello_world and run it.Dram
R
5

There are many possible applications of LLVM in terms of target machine.

Recusant answered 6/9, 2011 at 20:35 Comment(0)
S
3

According to the clang manual clang can target X86, Arm with partial support for PPC, SPARC and MSP430.

Clang can also generate LLVM bytecode though. LLVM can run on quite a few more platforms.

So if you want native machine code then the list is pretty small. If you want LLVM bytecode you have a broader choice of platforms.

Sommer answered 3/9, 2011 at 21:23 Comment(1)
Thanks. Now I have a better understanding what LLVM really is, and what architecture it supports. But a few things are still a little fuzzy about LLVM (see edit). Thank you!Laresa
V
1

I'm only answering the edit's question here (it would probably be more appropriate to make a new question).

This is a good architectural overview of LLVM. This page also contains a ton of documentations on all aspects of LLVM.

The short version is that LLVM is the optimizer and backend of a traditionnal compiler. It operates on a bytecode which is essentially it's intermediate representation of the code and is used to optimize and generate the final binary. The LLVM frontends are independent and uses there own internal ASTs to eventually generate bytecode.

LLVM is actually pretty flexible when it comes to when you want to generate the final binary. You can either do it right away or delay it until the program is being installed. I believe you can even use its JIT to generate the final binary during execution (not 100% sure of this). The main advantage of delaying like this is that it can apply optimizations that are specific to the environment it is executing on.

Viscosity answered 4/9, 2011 at 3:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.