ollvm的作用是對(duì)c/c++代碼進(jìn)行混淆。
本文主要記錄ollvm的編譯步驟以及遇到的編譯問題的解決。
根據(jù)該項(xiàng)目的官方wiki https://github.com/obfuscator-llvm/obfuscator/wiki/Installation
ollvm的編譯大致步驟如下:
- checkout 最新的分支
git clone -b llvm-4.0 https://github.com/obfuscator-llvm/obfuscator.git - 創(chuàng)建一個(gè)目錄專門用于保存編譯的中間文件和最終的目標(biāo)文件
mkdir build - cd build
- 對(duì)cmake 項(xiàng)目生成makefile
cmake -DCMAKE_BUILD_TYPE=Release ../obfuscator/ - make -j7
遇到的問題:
- 首先在第4步生成makefile的時(shí)候就會(huì)出錯(cuò)
CMake Error at cmake/modules/AddLLVM.cmake:1163 (add_custom_target):
add_custom_target cannot create target "check-llvm-bindings-ocaml" because
another target with the same name already exists. The existing target is a
custom target created in source directory
很多人遇到這個(gè)問題,根據(jù)這個(gè)issue: https://github.com/obfuscator-llvm/obfuscator/issues/71
需要將cmake的命令行參數(shù)調(diào)整為:
cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_INCLUDE_TESTS=OFF ../obfuscator/
如果重新生成makefile還是遇到問題,則先在build目錄rm -rf *,再重新cmake
- 編譯 obfuscator/tools/clang/lib/CodeGen/CGOpenMPRuntime.cpp時(shí)出錯(cuò),提示:
lambda parameter ‘CGF’ previously declared as a capture
解決辦法:
找到錯(cuò)誤提示的那幾行,分別修改如下(即將&CGF刪掉):
image.png
- 編譯 tools/lli/lli.cpp 時(shí)報(bào)錯(cuò)
could not convert '((llvm::orc::remote::OrcRemoteTargetClient<ChannelT>*)this)->callB<llvm::orc::remote::OrcRemoteTargetRPCAPI::ReadMem>(Src, Size)'
from 'Expected<vector<unsigned char,allocator<unsigned char>>>'
to 'Expected<vector<char,allocator<char>>>'
return callB<ReadMem>(Src, Size);
找到出錯(cuò)的 include/llvm/ExecutionEngine/Orc/OrcRemoteTargetClient.h的那一行
修改前:
Expected<std::vector<char>> readMem(char *Dst, JITTargetAddress Src, uint64_t Size) {
修改后:
Expected<std::vector<uint8_t>> readMem(char *Dst, JITTargetAddress Src, uint64_t Size) {
另外
- 在前期可以make -j參數(shù)調(diào)用多進(jìn)程加速編譯。當(dāng)你遇到問題時(shí), 建議將 -j參數(shù)去掉。避免干擾
- 可以使用 make VERBOSE=1來打印編譯中使用的具體gcc/g++的編譯參數(shù)
