[erlang-questions] Threaded VM with llvm-gcc

Anthony Ramine n.oxyde@REDACTED
Sat Sep 21 16:56:22 CEST 2013


I read in the installation guide [1] that it is recommended to use GCC 4.2 to build Erlang because CLang and LLVM cannot use jump tables.

There is two problems with this:

- This is not consistent with what the configure scripts actually do: CLang 3 and later use jump tables when compiling Erlang [2].
- There is no reason to not use LLVM 2.7 and later for beam_emu.c because it does compile jump tables efficiently [3].

Feel free to compile the following example code to LLVM-IR with llvm-gcc -s -emit-llvm or clang -s -emit-llvm:

main ()
    __label__ lbl1;
    __label__ lbl2;
    int x = magic();
    static void *jtab[2];

    jtab[0] = &&lbl1;
    jtab[1] = &&lbl2;
    goto *jtab[x];
    return 1;
    return 2;

  return 0;

Unfortunately I have no idea how to fix this, as there is no way to get the LLVM version from any preprocessor macro [4]. Should we just remove the LLVM check from the test and let the snippet of code fail to compile [5]?


[1] http://www.erlang.org/doc/installation_guide/INSTALL.html#Building-a-fast-Erlang-VM-on-Mac-OS-Lion
[2] https://github.com/erlang/otp/blob/589a9ed126d205007e79c22053d1b156a383d99f/aclocal.m4#L217-218
[3] http://blog.llvm.org/2010/01/address-of-label-and-indirect-branches.html
[4] http://stackoverflow.com/questions/1617877/how-to-detect-llvm-and-its-version-through-define-directives
[5] https://github.com/erlang/otp/blob/589a9ed126d205007e79c22053d1b156a383d99f/aclocal.m4#L219-220

Anthony Ramine

More information about the erlang-questions mailing list