Hi,
I am trying to implement a runtime to an existant LLVM FunctionPass. I followed your design and instrumented the code with call to a runtime function but this function seems to be undefined. Let me be more specific:
- I added a function in asan_rtl.cc with quite nothing in it (I am not even sure what Report does but I though it might print something... the point is to call this function with instrumentation):
void __bounds_init() {
Report("Runtime Library accessed!");
}
- I added an doInitialization function to my FunctionPass in order to retrieve a pointer to the __bounds_init function:
bool BoundsChecking::doInitialization(Module &M) {
if (runTimeEnabled) return false;
runTimeEnabled = true;
errs() << "Initialization of the FunctionPass...\n";
std::tie(ctor_func, init_func) =
createSanitizerCtorAndInitFunctions(
M, "", "__bounds_init",
/*InitArgTypes=*/{}, /*InitArgs=*/{}, "check_v1");
if(init_func) errs() << "Initialization succeded!\n";
return true;
}
Maybe the call to createSanitizerCtorAndInitFunctions isn't correctly done? It seems that the function only needs a init name. As I don't need a constructor I let the name empty... I didn't know what to put into the check version argument so I put a random name "check_v1"
- Then I made the call generation with the following for each function just to try:
IRBuilder<> IRB(&F.front(), F.front().begin());
IRB.CreateCall(init_func, {});
I got no errors when building LLVM with thoses changes but when I generate the executable with clang -fsanitize=bounds (this is the way to call BoundsChecking) the linker (so, after optimizations) fails and gives several " undefined reference to `__bounds_init' ".
I suppose I missed something but I dont know what. I looked at the IR generated with -S -emit-llvm, and there are several calls to __bounds_init and a declaration but no define:
call void @__bounds_init() #3
declare void @__bounds_init()
Anyone knows how I should do to be able to link the function created in asan_rtl.cc to the code being created? Or where to look in asan sources to find an answer? Feel free to ask me details, it's possible I am not being clear in what I exposed to you?
Thanks a lot for you time,
Pierre