[LLVMdev] question about Insert callInst to call a function in library.

Chris Lattner sabre at nondot.org
Sun Oct 17 14:25:04 PDT 2004


On Sun, 17 Oct 2004, Zhang Qiuyu wrote:

> Hi,
>
> Thanks Chris. Following your suggestion, I wrote the code to hide the
> visible string. Thanks again. Finially, I just realized my LLVM still is
> 1.2, not 1.3. Now I update it to 1.3.

ok.

> > > > 5. Insert the for loop that translates the string when main runs.
> > > >
> > > > For #5, write the for loop you want, compile it with llvmgcc, then figure
> > > > out how to generate it at compile time.  Alternatively, you could put the
> > > > 'decryption' routine in a library and just insert a call to the library.
>
> For decode part. I can write a pass to decode the hide-string bytecode(
> after hide string pass, I create a globalvariable to store the Key for
> decode routine. And on the decode pass, I use this Key to recover the
> orignal bytecode.

Sure.

> It seems not good way to decode. The better way should be to embed the
> decode routine into the bytecode in the entry of main. So the question
> is how to do it?

That's fine, take a look at how the profiling instrumentation code works
in lib/Transforms/Instrumentation.  That should give you examples of how
to insert function calls.  grep for 'new CallInst'.

> What I can do is that,
>     I can create call instruction and insert it into entry BB of main.
> And this call function is able to call the a function of the external
> library which I could create as I want( just using C style). And I can
> write decode pass, but I don't know how to build a library as the way
> you mentioned. Actually, I was thinking the pass I wrote is a dynamic
> library as libdecode.so. So could I use it? if not, how to build the
> library you mentioned? I thought the library you mentioned should be
> similar with the pass. However, I have no idea how combine them?

Yes, this is no problem.  The profiling instrumentation inserts function
calls which get resolved to the llvm/runtime/libprofile library.  Please
look at how that works and you can pattern off of that.

-Chris

-- 
http://llvm.org/
http://nondot.org/sabre/




More information about the llvm-dev mailing list