-
-
[原创]【笔记】LLVM编译及XCode集成
-
发表于: 2022-9-7 11:18 18144
-
一.下载
二. 安装
1 2 3 4 5 6 7 8 | cd [项目根目录]#解压.zipunzip llvm_project_12.0.0.zip#创建构建目录mkdir llvm_project_buildcd llvm_project_build#使用XCode模版进行工程编译cmake -S ../llvm-project/llvm -B ./ -G Xcode -DLLVM_ENABLE_PROJECTS="clang" |
三. 编译
- 打开LLVM.xcodeproj
- 选择
Automatically Create Schemes - 创建
Custom Aggregate - 进入
Build Phases - 点击
Dependencies - 添加
opt,clang以及需要编译的pass command+B开始编译
四. 解决Pass无法加载
使用LLVM工程自带实例LLVMHello
路径:根目录/llvm_project/llvm/lib/transforms/Hello/Hello.cpp
- 打开
[CustomPass].cpp - 添加两个头文件12
#include "llvm/IR/LegacyPassManager.h"#include "llvm/Transforms/IPO/PassManagerBuilder.h" 添加自动注册Pass代码
123456static void registerSkeletonPass(const PassManagerBuilder &, legacy::PassManagerBase &PM){PM.add(new Hello());}static RegisterStandardPasses RegisterMyPass(PassManagerBuilder::EP_EarlyAsPossible, registerSkeletonPass);
五. 在XCode中添加Pass
- 打开
Project选择Target - 点击
Build Settings - 添加
User-Defined,命名为CC,值为根目录/llvm_project-build/Debug/bin/clang - 添加
User-Defined,命名为CXX,值为根目录/llvm_project-build/Debug/bin/clang++ - 点击
other c flags,添加-Xclang -load -Xclang /Volumes/T.SSD/LLVM/llvm-project-build/Debug/lib/[Pass名称].dylib - 点击
enable index-while-building funcationality,将属性值改为NO command+B编译- 编译出错
function does not returnorcould not build module **- 点击
other c flags,追加-DNS_FORMAT_ARGUMENT(A)= -D_Nullable_result=_Nullable,重新进行编译
- 点击
- 成功后会打印123456789101112131415
Hello: \001+[OMGameHandle shared]Hello: _dispatch_onceHello: __22+[GHandle shared]_block_invokeHello: \001-[GameHandle setup]Hello: \001-[GameHandle agreeProtocol]Hello: \001-[GameHandle initWithStatus:]Hello: \001-[GameHandle loginWithSuccess:]Hello: \001-[GameHandle loginWithSignout]Hello: \001-[GameHandle loginWithFailure:]Hello: \001-[GameHandle login]Hello: \001-[GameHandle setupBlock]Hello: \001-[GameHandle setSetupBlock:]Hello: \001-[GameHandle vc]Hello: \001-[GameHandle setVc:]Hello: \001-[GameHandle .cxx_destruct]
- 编译出错
赞赏
赞赏
雪币:
留言: