Building autotooled software to LLVM bitcode

后端 未结 1 1653
天命终不由人
天命终不由人 2021-02-20 11:08

I would like to compile software using the autotools build system to LLVM bitcode; that is, I would like the executables obtained at the end to be LLVM bitcode, not actual machi

1条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-20 11:43

    There are some methods like this. But for simple builds where intermediate static libraries are not used, then you can do something simpler. The list of things you will need are

    1. llvm, configured with gold plugin support. Refer to this
    2. clang
    3. dragonegg, if you need front-end for fortran, go, etc.

    The key is to enable '-flto' for either clang or dragonegg(front-end), both at compile time and link time. It is straightforward for clang:

    CC = clang
    CLINKER = clang
    CFLAGS = -flto -c
    CLINKFLAGS = -flto -Wl,-plugin-opt=also-emit-llvm
    

    If needed, add additional '-plugin-opt' option to specify llvm-specific codegen option:

    -Wl,-plugin-opt=also-emit-llvm,-plugin-opt=-disable-fp-elim
    

    The dumped whole problem bytecode would be sitting along with your final executable.

    Two additional things are needed when using dragonegg.

    First, the dragonegg is not aware of the location of llvm gold plugin, it needs to be specified in the linker flags like this -Wl,-plugin=/path/to/LLVMgold.so,-plugin-opt=...

    Second, dragonegg is only able to dump IR rather than bytecode. You need a wrapper script for that purpose. I created one here. Works fine for me.

    0 讨论(0)
提交回复
热议问题