Skip to content
Advertisement

Compiling the PHP stack with Clang

Is it possible yet to compile a full PHP stack – say Apache, PHP, Postgres and enough of the more commonly used libraries to cover ninety percent of sites – with Clang into LLVM bitcode? If so, are there any instructions available on how to do it starting with an out-of-the-box Ubuntu setup?

Advertisement

Answer

Apache, PHP and Postgres can be compiled by Clang, which means they can also be compiled into LLVM bitcode. I can’t give you particular steps to achieve this, since it depends on build system. Anyway, this involves adding -femit-llvm flag to compilation line and, probably, using llvm-link as linker.

Be aware that at least PHP have inline assembly code, on which your analyzer may choke.

UPDATE:

Nice tool to compile code using arbitrary build systems to LLVM IR is gllvm. In short, you just use gclang/gclang++ instead of gcc/g++ and then running get-bc on the resulting binary.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement