-
-
[原创]【笔记】LLVM编译及XCode集成
-
发表于: 2022-9-7 11:18 17678
-
一.下载
二. 安装
1 2 3 4 5 6 7 8 | cd [项目根目录] #解压.zip unzip llvm_project_12. 0.0 . zip #创建构建目录 mkdir llvm_project_build cd 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 return
orcould not build module **
- 点击
other c flags
,追加-DNS_FORMAT_ARGUMENT(A)= -D_Nullable_result=_Nullable
,重新进行编译
- 点击
- 成功后会打印123456789101112131415
Hello: \
001
+
[OMGameHandle shared]
Hello: _dispatch_once
Hello: __22
+
[GHandle shared]_block_invoke
Hello: \
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]
- 编译出错
赞赏
看原图
赞赏
雪币:
留言: