How to change LLVMPass long opt command to a simple Command

你说的曾经没有我的故事 提交于 2019-12-06 14:26:01

问题


I am working on LLVM obfuscation project. I have written a llvm pass(lets say flow flattening pass) which i am running on source (test.c) with following command:

clang -emit-llvm test.c -c -o test.bc 
opt -load ../../.. LLVMFlattening.so -fla <test.bc>/dev/null

But i have seen that in O-LLVM project they achieved same thing using:

clang -emit-llvm test.c -c -o test.bc -mllvm -fla

Can someone tell me what is -mllvm here and how this changed to a simple command?


回答1:


-mllvm means Additional arguments to forward to LLVM's option processing. Therefore -mllvm -fla will pass -fla to the LLVM's option processing.

Clang and LLVM could run seperately. If you want clang to run llvm, and also have some options which you want llvm to aware. -mllvm is what you need.

Defautly, LLVM does not turn on all the transformation passes. With -fla, LLVM will turn on the pass registered with command line argument fla by call function RegisterPass<typename passName>.

In your command line, opt's -load option is used to load plugin. If you want to use the simple command line as expect. Your pass need to be linked into the opt binary. This could be done in the following two ways:

  1. (Without modify the existing LLVM source tree): Add your only pass's source by adding CMakeLists.txt mentioned in this link
  2. Directly copy your pass source code folder into <LLVM root>/lib/Transform directory. And modify the <LLVM root>/lib/Transform/CMakeLists.txt, add add_subdirectory(<pass name>) line just like others.



回答2:


I'm working on O-LLVM rencently, and came into the same problem. Here is my solution:

1.add static cl::opt<bool> YOUR_FLA("fla", cl::init(false),"info...") to PassManagerBuilder.cpp

2.add function Pass *createYOUR_FLA(bool flag) in your obfuscation pass source code

3.add MPM.add(createYOUR_FLA(YOUR_FLA)); to function populateModulePassManager in PassManagerBuilder.cpp

The solution above works with my simple pass.



来源:https://stackoverflow.com/questions/29946629/how-to-change-llvmpass-long-opt-command-to-a-simple-command

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