ollvm編譯中遇到的問題

ollvm的作用是對(duì)c/c++代碼進(jìn)行混淆。
本文主要記錄ollvm的編譯步驟以及遇到的編譯問題的解決。

根據(jù)該項(xiàng)目的官方wiki https://github.com/obfuscator-llvm/obfuscator/wiki/Installation

ollvm的編譯大致步驟如下:

  1. checkout 最新的分支
    git clone -b llvm-4.0 https://github.com/obfuscator-llvm/obfuscator.git
  2. 創(chuàng)建一個(gè)目錄專門用于保存編譯的中間文件和最終的目標(biāo)文件
    mkdir build
  3. cd build
  4. 對(duì)cmake 項(xiàng)目生成makefile
    cmake -DCMAKE_BUILD_TYPE=Release ../obfuscator/
  5. make -j7

遇到的問題:

  1. 首先在第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

  1. 編譯 obfuscator/tools/clang/lib/CodeGen/CGOpenMPRuntime.cpp時(shí)出錯(cuò),提示:

lambda parameter ‘CGF’ previously declared as a capture
解決辦法:
找到錯(cuò)誤提示的那幾行,分別修改如下(即將&CGF刪掉):


image.png
  1. 編譯 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) {

另外

  1. 在前期可以make -j參數(shù)調(diào)用多進(jìn)程加速編譯。當(dāng)你遇到問題時(shí), 建議將 -j參數(shù)去掉。避免干擾
  2. 可以使用 make VERBOSE=1來打印編譯中使用的具體gcc/g++的編譯參數(shù)
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

友情鏈接更多精彩內(nèi)容