I need to inline tsan’s instrumentation functions, i.e. for example instead of having a call into __tsan_write4
in my final instrumented executable I want to have the equivalent inline form.
I have tried modifying the definitions of the instrumentation functions in the tsan_interface.inc
[1] file such that they are defined with the inline __attribute__((always_inline))
attribute. For instance:
inline __attribute__((always_inline)) void __tsan_write4(void *addr) {
...
}
I am able to compile this new tsan rtl, but using it in action with clang causes the following linking error:
> undefined reference to `__tsan_write4’
> clang-16: error: linker command failed with exit code 1
I have also tried putting the above function definition in the tsan_interface.h
[2] header file instead, but it results in the same error.
Using the __attribute__((used))
attribute alongside __attribute__((always_inline))
resolves the above linking error, but it creates function calls instead of function inlining.
So if I understand correctly, only using inline __attribute__((always_inline))
makes the linker unable to resolve the function call, while with __attribute__((used))
added the linker is able to resolve the function call but cannot perform function inlining.
Any help is greatly appreciated.
[1] llvm-project/compiler-rt/lib/tsan/rtl/tsan_interface.inc
[2] llvm-project/compiler-rt/lib/tsan/rtl/tsan_interface.h