Comments (11)
Thank you, sir! 😁😁 Today, I finnally understand what you told me.
(Because I am a green hand in C and C++, so I didn't understand what extern "C"
means the other day.)
Hope it will help other students like me :)
from llvm-pass-skeleton.
I've never done it, but if I did, I would probably use extern "C"
to avoid mangling in the run-time hooks. (You can of course still call into general C++ from there.)
from llvm-pass-skeleton.
Well I'll give that a try.
from llvm-pass-skeleton.
It worked! Thank you.
from llvm-pass-skeleton.
Woohoo!
from llvm-pass-skeleton.
And I world like to share my experiment.
I changed content of rtlib.c
and example.c
from c to cpp.
Then I run:
(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 logop
. So I check the difference between the ll file of rtlib.c
and that of rtlib.cpp
.
rtlib.c 's ll
define dso_local void @logop(i32 %0) #0 !dbg !9
rtlib.cpp 's ll
define dso_local void @_Z5logopi(i32 %0) #0 !dbg !9
So I changed the Skeleton.cpp
from F.getParent()->getOrInsertFunction("logop", logFuncType);
to F.getParent()->getOrInsertFunction("_Z5logopi", logFuncType);
. And then it worked.
Hope it's helpful.
from llvm-pass-skeleton.
If I were writing a run-time library in C++, I would use extern "C"
to export a non-mangled name.
from llvm-pass-skeleton.
If I were writing a run-time library in C++, I would use
extern "C"
to export a non-mangled name.
Thank you for your reply! I don't understand export a non-mangled name
. What is a non-mangled name
? My translator told me it means 'an unchanged name'. Does it mean that if I use extern C, the name of functions in LLVM IR won't change
? For example, in rtlib.cpp's ll file
, the function name logop
is still logop
?
And another problem: My application is to analyse C++ by using LLVM pass. So, will extern "c"
destroy other functions of C++?
Thank you!😉
from llvm-pass-skeleton.
I unfortunately can't help walk through the mechanics here, but the relevant term to Google is "C++ name mangling".
An extern "C"
runtime function should not prevent you from instrumenting C++ programs.
from llvm-pass-skeleton.
Hi, I still have some primary problems about using string
in llvm pass.
I wanna use string as argument, like that:
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 such as store i32 0, i32* %retval, align 4
// 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 argstr
? To match string type.
Best wishes!
from llvm-pass-skeleton.
I found the solution Value *argstr = builder.CreateGlobalString(arg2ins->getName());
😁
from llvm-pass-skeleton.
Related Issues (20)
- Running annotation module HOT 1
- Fatal Error For Attributes.gen HOT 6
- Unable to run the program HOT 3
- Compile error in the rtlib branch HOT 1
- Error while running the program HOT 7
- Error while making rtlib example HOT 6
- Error while compiling HOT 1
- Support for iOS in XCODE HOT 2
- Getting error : undefined symbol: _ZN4llvm23EnableABIBreakingChecksE HOT 1
- llvm instrumentation HOT 3
- pass has no effect HOT 1
- instrumentation: Linking With a Runtime Library HOT 1
- error: clang frontend command failed due to signal (use -v to see invocation) HOT 1
- Cmake for the "mutate" branch needs C++ 14 support
- Clang 14.0.5 unable to execute command: Aborted HOT 1
- fixes for version 15? HOT 1
- Now Make the Pass Do Something Mildly Interesting HOT 1
- ModulePasses with Auto Registration HOT 31
- The imported target "LLVMSupport" references the file "/usr/lib/libLLVMSupport.a" Error HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from llvm-pass-skeleton.