[LLVMdev] generate a function call to an inlined function of dynamic library

Eric Lu eirc.lew at gmail.com
Mon Sep 15 17:57:36 PDT 2014


Hi,
   I want to instrument some operation in the llvm IR, such as
load/store/call Instructions. When encountering some of these
instructions, I will insert a function call, such as

__checkLoad (i8* bitcast (i32* @f to i8*)
%3 = load i32* @f, align 4, !dbg !30

To reduce the overhead, I try on inline these function calls to __check****.
1) The dynamic library
The __checkLoad functions are compiled into a dynamic shared runtime
library, called libprofruntime.so, in the dynamic library, I defined
the inserted functions with extern inline in a header file, and insert
the header file in some other .c files.
in prof.h
extern  inline __checkLoad(i8*, i64)
{

}

in prof.c
#include"prof.h"

2) Do instrumentation
When instrument main.c, I insert the function declared as:
declare void @__checkLoad(i8*, i64) inlinehint

and the source codes after the instrumentation is like below:
call void @__checkLoad(i8* bitcast (i32* @sum to i8*), i64 4)
inlinehint, !dbg !36
  %12 = load i32* @sum, align 4, !dbg !36

and It seems works until now.

3) compile
a) clang -emit-llvm -c l1.c -o l1.bc
b) Instrument the l1.bc
c) opt -always-inline -inline -load  libinstrument.so -o l1-prof.bc

libinstrument.so has the function to do real analysis and instrumentation.

4) link
clang l1-prof.bc libprofruntime.so -o l1_prof

But when I link these code, it emitted errors like follow:
l1.c:13: undefined reference to `__checkLoad'

What is wrong with the implementation? Any suggestions are appreciated.


Thanks!
Eric




More information about the llvm-dev mailing list