developing an llvm pass with cmake out of llvm source directory

社会主义新天地 提交于 2020-01-21 02:27:35

问题


I am trying to develop an llvm pass under my project directory. For that, I follow the info in http://llvm.org/docs/CMake.html#developing-llvm-pass-out-of-source. I create my CMakeFiles appropriately as in this link and my final project directory is like;

|-- src
|   |-- CMakeLists.txt
|   |-- bigForPass
|   |   |-- CMakeLists.txt
|   |   |-- bigForPass.cpp
|   |   |-- merged.bc
|   |-- build

I also linked my source files with llvm root directory without any problem. Finally I make the build under the 'build' folder and my shared library is created successfully with no problems (under build/bin folder) with the name LLVMHello1.dylib. However, when I try to run my pass over merged.bc file (which contains my llvm code) with the command

opt -load ../build/bin/LLVMHello1.dylib -bishe_insert <merged.bc> final.bc

I keep getting the error;

Error opening '../build/bin/LLVMHello1.dylib': dlopen(../build/bin/LLVMHello1.dylib, 9): Symbol not found: __ZTIN4llvm10ModulePassE
  Referenced from: ../build/bin/LLVMHello1.dylib
  Expected in: flat namespace
 in ../build/bin/LLVMHello1.dylib
  -load request ignored.

Any ideas and suggestions on this appreciated ?

Thanks a lot in advance.


回答1:


from http://www.jiang925.com/node/28

Undefined Symbol: _ZTIN4llvm12FunctionPassE There is an inconsistency between LLVM main build system and the cmake support for building out-of-source. The LLVM binaries are built without runtime type info "-fno-rtti". Therefore, the out-of-source passes have to be built the same way otherwise opt will complain that symbol "_ZTIN4llvm12FunctionPassE" is undefined.

To solve this problem, LLVM must be compile with RTTI enabled. Add "-DLLVM_REQUIRES_RTTI=1" to cmake, or add "REQUIRES_RTTI=1" to make.

So I added SET(CMAKE_CXX_FLAGS "-Wall -fno-rtti") to CMakeLists.txt of my pass library and then it's working.



来源:https://stackoverflow.com/questions/17225956/developing-an-llvm-pass-with-cmake-out-of-llvm-source-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!