Legacy LLVM

Warning

This section is kept available for information purposes, it is no longer relevant to the current implementation. They are still worth to mention and somehow describes what interesting can happen with RTTI.

Here are a few interesting errors that happened in the past:

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.

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.