-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using C++ files for rtlib #8
Comments
I've never done it, but if I did, I would probably use |
Well I'll give that a try. |
It worked! Thank you. |
Woohoo! |
And I world like to share my experiment. (base) fdse@ubuntu:~/luorong/LLVM/test/llvm-pass-skeleton$ ls
build CMakeLists.txt example.cpp LICENSE README.md rtlib.cpp skeleton
(base) fdse@ubuntu:~/luorong/LLVM/test/llvm-pass-skeleton$ g++ -c rtlib.cpp
(base) fdse@ubuntu:~/luorong/LLVM/test/llvm-pass-skeleton$ clang++ -flegacy-pass-manager -Xclang -load -Xclang build/skeleton/libSkeletonPass.so -c example.cpp
(base) fdse@ubuntu:~/luorong/LLVM/test/llvm-pass-skeleton$ ls
build example.cpp LICENSE rtlib.cpp skeleton
CMakeLists.txt example.o README.md rtlib.o
(base) fdse@ubuntu:~/luorong/LLVM/test/llvm-pass-skeleton$ g++ example.o rtlib.o
example.o: In function `main':
example.cpp:(.text+0x35): undefined reference to `logop'
collect2: error: ld returned 1 exit status Yes, it cannot find
So I changed the Hope it's helpful. |
If I were writing a run-time library in C++, I would use |
Thank you for your reply! I don't understand And another problem: My application is to analyse C++ by using LLVM pass. So, will Thank you!😉 |
I unfortunately can't help walk through the mechanics here, but the relevant term to Google is "C++ name mangling". An |
Hi, I still have some primary problems about using extern "C" void logvar(int i, char* name) {
std::cout << "Num: " << i << "; Name: " << name << std::endl;
} And pass.cpp // Get the function to call from our runtime library.
LLVMContext &Ctx = F.getContext();
std::vector<Type*> paramTypes = { // Param Types
Type::getInt32Ty(Ctx),
Type::getInt8PtrTy(Ctx)
};
Type *retType = Type::getVoidTy(Ctx);
FunctionType *logFuncType = FunctionType::get(retType, paramTypes, false);
FunctionCallee logFunc = F.getParent()->getOrInsertFunction("logvar", logFuncType); Insert logvar in pass.cpp // for store instruction
void insertLogvar(StoreInst *inst, BasicBlock &B, FunctionCallee logFunc, LLVMContext &Ctx) {
IRBuilder<> builder(inst);
builder.SetInsertPoint(&B, ++builder.GetInsertPoint());
Value *argi = inst->getOperand(0); // integer
if (auto constant_int = dyn_cast<ConstantInt>(argi)) {
Value* argstr = ??? // HERE
Value* args[] = {argi, argstr};
builder.CreateCall(logFunc, args);
} else {
errs() << "store inst has no instance number" << "\n";
}
} My question is how to accomplish Best wishes! |
I found the solution |
Did you ever attempt to use C++ for calling a runtime library, or was the mangling too big of an issue to overcome?
The text was updated successfully, but these errors were encountered: