Skip to content
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

Software tracer llvm pass #109

Closed
wants to merge 5 commits into from

Conversation

Pavel-Durov
Copy link

Current issue

I added my Rust function in ykcapi/src/lib.rs (just cause I know that __ykrt_control_point function can be found there from ControlPoint.cpp module pass):

#[no_mangle]
pub extern "C" fn yk_trace_basic_block() -> *const c_void {
    println!("yk_trace_basic_block was called");
    std::ptr::null()
}

In my pass implementation, I'm locating and injecting external function call instruction to the basicblock.
My runOnModule function:

bool runOnModule(Module &M) override {
    for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
      LLVMContext &Context = M.getContext();
      if (externalFunc == NULL) {
        // Locate externally linked function
        FunctionType *FType = FunctionType::get(Type::getVoidTy(Context), {}, false);
        externalFunc = Function::Create(FType, GlobalVariable::ExternalLinkage,
                                        "yk_trace_basic_block", M);
      }
      for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
        for (BasicBlock::iterator BI = BB->begin(), BE = BB->end(); BI != BE; ++BI) {
          // Insert function call instruction
          IRBuilder<> builder(Context);
          builder.SetInsertPoint(&(*BI));
          builder.CreateCall(externalFunc);
        }
      }
    }
    return true;
  }

But when I run it I get an undefined reference error from the linker:

 note: /usr/bin/ld: /yk-fork/target/debug/build/hwtracer-36df6aaa5f152db3/out/libhwtracer_c.a(collect.o): in function `hwt_set_cerr':
          /yk-fork/hwtracer/src/perf/collect.c:172: undefined reference to `yk_trace_basic_block'
          /usr/bin/ld: /yk-fork/hwtracer/src/perf/collect.c:172: undefined reference to `yk_trace_basic_block'
....
collect2: error: ld returned 1 exit status

And when I look at libykcapi.so symbols, I do see my function there:

nm -g -C ./target/debug/deps/libykcapi.so | grep yk_trace_basic_block
0000000000061050 T yk_trace_basic_block

@Pavel-Durov Pavel-Durov self-assigned this Dec 7, 2023
@Pavel-Durov Pavel-Durov closed this Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant