八大处网站建设,营销型网站建设成为企业发展新趋势,成都网站建设开发价,南京外贸网站建设公司sudo usermod -a -G vboxsf nowind nowind是你的虚拟机登录的用户名解决virtualbox 虚拟机共享文件夹不能使用的问题
第一种#xff1a;源码内实现pass#xff1a;
实现EncodeFunctionName 的pass#xff0c;核心代码如下
相关文件的修改#xff1a; 因为后面同样用到…sudo usermod -a -G vboxsf nowind nowind是你的虚拟机登录的用户名解决virtualbox 虚拟机共享文件夹不能使用的问题
第一种源码内实现pass
实现EncodeFunctionName 的pass核心代码如下
相关文件的修改 因为后面同样用到ollvm所以我已经放到一起了资源下载
https://download.csdn.net/download/ahjxly/88609122
因为全部都是修改llvm目录下的文件替换include和lib文件夹
替换完成后 cd cd llvm/llvm-project-9.0.1/llvm/cmake-build-debug/,执行ninja -j8,重新编译下。这次编译会快很多。
然后单独执行 ninja LLVMEncodeFunctionName,生成so文件进行使用。
使用方式和之前的文章一样执行
opt -load /home/nowind/llvm/llvm-project-9.0.1/llvm/cmake-build-release/lib/LLVMEncodeFunctionName.so -encode hello_clang.ll -o hello_clang_encode.bc
clang hello_clang_encode.bc -o hello_clang_encode
第二种在源码外实现EncodeFunctionName2修改根目录下的CMakeList.txt
set(LLVM_DIR /home/nowind/llvm/llvm-project-9.0.1/llvm/cmake-build-debug/lib/cmake/llvm/)这里为你自己的路径
执行结果如下
/home/nowind/llvm/CLion-2023.3/clion-2023.3/bin/cmake/linux/x64/bin/cmake -DCMAKE_BUILD_TYPEDebug -DCMAKE_MAKE_PROGRAM/usr/bin/ninja -G Ninja -S /home/nowind/llvm/pro/pro2/outPass -B /home/nowind/llvm/pro/pro2/outPass/cmake-build-debug
-- Linker detection: GNU ld
-- Configuring done (0.0s)
-- Generating done (0.0s)
-- Build files have been written to: /home/nowind/llvm/pro/pro2/outPass/cmake-build-debug[Finished]
/home/nowind/llvm/CLion-2023.3/clion-2023.3/bin/cmake/linux/x64/bin/cmake --build /home/nowind/llvm/pro/pro2/outPass/cmake-build-debug --target all -j 6
[2/2] Linking CXX shared module EncodeFunctionName2/LLVMEncodeFunctionName2.soBuild finished
生成的文件在
/home/nowind/llvm/pro/pro2/outPass/cmake-build-debug/EncodeFunctionName2/LLVMEncodeFunctionName2.so
使用opt 命令
opt -load /home/nowind/llvm/pro/pro2/outPass/cmake-build-debug/EncodeFunctionName2/LLVMEncodeFunctionName2.so -encode2 hello_clang.ll
WARNING: Youre attempting to print out a bitcode file.
This is inadvisable as it may cause display problems. If
you REALLY want to taste LLVM bitcode first-hand, you
can force output with the -f option.EncodeFunctionName22: test_hello1 - 9c119247aefaa12cdd417eb3d57d5b2a
EncodeFunctionName22: main - main
EncodeFunctionName22: test_hello2 - af0aaac8b98b759ace7b9eacbd2238a6得到同样的结果。
clang使用自定义的pass生成可执行文件 clang -Xclang -load -Xclang /home/nowind/llvm/pro/pro2/outPass/cmake-build-release/EncodeFunctionName2/LLVMEncodeFunctionName2.so -encode2 hello_clang.ll -o hello_clang_encode3 -Wno-unused-command-line-argument第三种EncodeFunctionName注册到clang中
/home/nowind/llvm/llvm-project-9.0.1/llvm/lib/Transforms/IPO/PassManagerBuilder.cpp populateModulePassManager方法中增加 MPM.add(createEncodeFunctionName());
重新编译clang: 这里用的release因此PATH要改
ninja clang
export PATH/home/nowind/llvm/llvm-project-9.0.1/llvm/cmake-build-release/bin:$PATH
clang -mllvm -encode_function_name hello_clang.bc
切换到debug
修改EncodeFunction中CMakeLists.txt set(LLVM_DIR /home/nowind/llvm/llvm-project-9.0.1/llvm/cmake-build-debug/lib/cmake/llvm/)
cd cmake-build-debug
ninja opt 重新编译opt
opt -load /home/nowind/llvm/pro/pro2/outPass/cmake-build-debug/EncodeFunctionName2/LLVMEncodeFunctionName2.so -encode2 hello_clang.ll -o hello_clang_encode.bc
注意pass不能重名
opt 断点
OutPass中配置EncodeFunctionName2的opt为
/home/nowind/llvm/llvm-project-9.0.1/llvm/cmake-build-debug/bin/opt
参数配置为
-load /home/nowind/llvm/pro/pro2/outPass/cmake-build-debug/EncodeFunctionName2/LLVMEncodeFunctionName2.so -encode2 /home/nowind/llvm/pro/pro2/hello_clang.ll -o /home/nowind/llvm/pro/pro2/hello_clang_encode.bc
但这样配置完毕后发现一个问题就是日志在clion控制台中看不到只有换行勾选了
Emulate terminal in the output console才能看到奇怪的很但也不影响什么