Having LLVM IR library how to crosscompile it to iOS, Android, Windows and Mac from Ubuntu? Having LLVM IR library how to crosscompile it to iOS, Android, Windows and Mac from Ubuntu? ios ios

Having LLVM IR library how to crosscompile it to iOS, Android, Windows and Mac from Ubuntu?


Using the LLVM static compiler (llc), you can compile the LLVM IR into object files for a specific target triple. Though the target triples are not documented very well, the LLVM infrastructure is all open source, so a quick search through the source code will lead you here.

Unfortunately, there is no documentation for a discrete list of possible target triples you can use. However, if you know exactly what system you're targeting, constructing a triple is fairly easy. Taken from the target triple documentation, you can see :

The triple has the general format <arch><sub>-<vendor>-<sys>-<abi>, where:

  • arch = x86_64, i386, arm, thumb, mips, etc.
  • sub = for ex. on ARM: v5, v6m, v7a, v7m, etc.
  • vendor = pc, apple, nvidia, ibm, etc.
  • sys = none, linux, win32, darwin, cuda, etc.
  • abi = eabi, gnu, android, macho, elf, etc.

Once you figure out what target triple you're using, you specify it as a string using the -mtriple flag. Here are some examples:

  • Windows: -mtriple=i686-pc-win32-gnu
  • Linux: -mtriple=i686-pc-linux-gnu
  • IOS: -mtriple=armv7-apple-ios
  • Android: -mtriple=arm-linux-androideabi

Next, you need to specify that you want to compile an object file using the filetype flag:

-filetype=obj

This should be enough if I understand your question correctly.

If you're expecting to use a single file on all platforms and operating systems, while this is possible, it would take a lot of work and I wouldn't expect an answer regarding that here on stackoverflow.


From this link, There is a Variable LLVM_TARGETS_TO_BUILD and the definition says that

A semicolon delimited list controlling which targets will be built and linked into llc. This is equivalent to the --enable-targets option in the configure script. The default list is defined as LLVM_ALL_TARGETS, and can be set to include out-of-tree targets. The default value includes: AArch64, AMDGPU, ARM, BPF, Hexagon, Mips, MSP430, NVPTX, PowerPC, Sparc, SystemZ, X86, XCore.

You should add the X86 and ARM is present in it. you need to add support for 64 and Apple

From this link

It is possible to cross compile

The example command looks like

% cmake -G "Ninja" -DCMAKE_OSX_ARCHITECTURES="armv7;armv7s;arm64"  -DCMAKE_TOOLCHAIN_FILE=<PATH_TO_LLVM>/cmake/platforms/iOS.cmake  -DCMAKE_BUILD_TYPE=Release -DLLVM_BUILD_RUNTIME=Off -DLLVM_INCLUDE_TESTS=Off  -DLLVM_INCLUDE_EXAMPLES=Off -DLLVM_ENABLE_BACKTRACES=Off [options]  <PATH_TO_LLVM>

Also I would like to share this link. It says

The basic option is to define the target architecture. For that, use -target . If you don’t specify the target, CPU names won’t match (since Clang assumes the host triple), and the compilation will go ahead, creating code for the host platform, which will break later on when assembling or linking.

The triple has the general format <arch><sub>-<vendor>-<sys>-<abi>, where:

arch = x86_64, i386, arm, thumb, mips, etc.sub = for ex. on ARM: v5, v6m, v7a, v7m, etc.vendor = pc, apple, nvidia, ibm, etc.sys = none, linux, win32, darwin, cuda, etc.abi = eabi, gnu, android, macho, elf, etc.