TC-L FAQ

The build failed on my machine

If the following error occurs:

  CXXLD    src/tc
src/.libs/libtc.a(lt14-translator.o):(.rodata._ZTIN4llvm17GetElementPtrInstE[_ZTIN4llvm17GetElementPtrInstE]+0x10): undefined reference to `typeinfo for llvm::Instruction'
src/.libs/libtc.a(lt14-translator.o):(.rodata._ZTIN4llvm8ICmpInstE[_ZTIN4llvm8ICmpInstE]+0x10): undefined reference to `typeinfo for llvm::CmpInst'
src/.libs/libtc.a(lt14-translator.o):(.rodata._ZTIN4llvm7PHINodeE[_ZTIN4llvm7PHINodeE]+0x10): undefined reference to `typeinfo for llvm::Instruction'
collect2: error: ld returned 1 exit status
Makefile:2992: recipe for target 'src/tc' failed
make: *** [src/tc] Error 1

then you are using an old version of LLVM. The version required is 3.8 or more.

If you still want to use LLVM 3.7, then the LLVM build you are using is compiled without RTTI.

In order to make it work, you have two choices:

  • If you are building LLVM 3.7 from the source code, apply this patch to fix the compilation.
  • Build LLVM with RTTI enabled. In order to build LLVM with RTTI enabled, follow these steps, assuming the current directory is the root of LLVM:
    • mkdir _build
    • cd _build
    • cmake .. -DLLVM_REQUIRES_RTTI=ON -DCMAKE_BUILD_TYPE=Release
    • make install

LLVM builds with RTTI disabled by default. They use their own RTTI-like system. Tiger is compiled using RTTI, and actually uses it quite a lot (dynamic_cast). In order to make them work together, LLVM has to emit the vtables of its classes in their own translation unit.

This regression appeared in LLVM 3.7 when a virtual destructor was inlined, so the vtables were emitted in every translation unit. It was the following classes: llvm::GetElementPtrInst, llvm::ICmpInst and llvm::PHINode.

In order to solve the problem, LLVM uses a dedicated member function called anchor, that is going to force the emission to happen in its own translation unit.

As of today, here are some packages of LLVM 3.7 that work/don’t work: - ArchLinux (pacman) - RTTI enabled.

  • OS X (brew) - RTTI enabled.
  • OS X (macports) - RTTI disabled. Does not compile.
  • Ubuntu (apt) - RTTI enabled.
What is a PHI node?

LLVM instructions are represented in the SSA (Static Single Assignment) form.

Let’s take an example:

let
  var v := 10
  var a := 1
  var b := 0
in
  if (v < 10) then
    a := 2;
  b := a
end

The whole point of SSA is to forbid re-assignments, so we cannot assign 2 to a.

In that case, LLVM is going to create two a’s, and the assignment has to pick the desired version.

Using a PHI node, the assignment will depend on the original path of the code, and using that information, it can decide which version of a should be picked.

You can use the opt tool in order to display the control-flow graph.

opt -dot-cfg fact.ll

This generates two files: cfg.tc_main.dot and cfg.fact_18.dot, corresponding to the main function and the fact function.

I don’t understand all the acronyms used in LLVM.
Where can I find their meaning? You can find it in The LLVM Lexicon.
Can I output the LLVM IR of a C/C++ program?

Yes, you can. Clang, A C language family front end for LLVM allows you to do it using the flags -S -emit-llvm.

int main(void)
{
  int a = 1 + 2 * 3;
  return a;
}

File 4.100: clang-example.c

$ clang -m32 -S -emit-llvm -o - clang-example.c
clang: error: no such file or directory: 'clang-example.c'
clang: error: no input files

Example 4.164: clang -m32 -S -emit-llvm -o - clang-example.c

Your compiler crashes when llvm::Linker::linkModules is called

When using --llvm-runtime-display, this behavior can occur when the linker is asked to link two LLVM IR modules that may have been compiled with two different LLVM IR versions.

Since the runtime is compiled with Clang, A C language family front end for LLVM, from C to LLVM IR, you have to make sure that the Clang, A C language family front end for LLVM version and the LLVM version are exactly the same.

This crash currently occurs with Clang, A C language family front end for LLVM 3.6 and LLVM 3.8.