问题
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:
- (Without modify the existing LLVM source tree): Add your only pass's source by adding
CMakeLists.txt
mentioned in this link - Directly copy your pass source code folder into
<LLVM root>/lib/Transform
directory. And modify the<LLVM root>/lib/Transform/CMakeLists.txt
, addadd_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