[LLVMdev] mixing static/dynamic code

Paul Martin srucnoc at gmail.com
Sun May 24 13:29:50 PDT 2009


Nick,
Thanks for the quick answer.
Dereferencing the pointer does yield the same result in both cases but
that's not what I want to do. I want to instrument the program dynamically
and keep track of certain memory locations which is a problem if the same
variable has different addresses for the static/dynamic code - as far I see
this is what it's happening but I have no clue why.

Paul

On Sun, May 24, 2009 at 10:15 PM, Nick Lewycky <nicholas at mxc.ca> wrote:

> Paul Martin wrote:
> > Hi,
> > I have the following code, the lines preceded by `>` being added at
> > runtime (the snipped was also printed at runtime)
> >
> > define i32 @myfunc(i32 %pi) {
> > entry:
> >         %pi_addr = alloca i32           ; <i32*> [#uses=3]
> >         %retval = alloca i32            ; <i32*> [#uses=2]
> >         %tmp = alloca i32               ; <i32*> [#uses=2]
> >  >       %ptr32 = alloca i32             ; <i32*> [#uses=2]
> >         %"alloca point" = bitcast i32 0 to i32          ; <i32> [#uses=0]
> >
> >  >       store i32 %pi, i32* %ptr32
> >  >       %ptr8 = bitcast i32* %ptr32 to i8*              ; <i8*>
> [#uses=1]
> >  >       call void @roc( i8* %ptr8 )
> >
> >         store i32 %pi, i32* %pi_addr
> >         %pi_addr1 = bitcast i32* %pi_addr to i8*                ; <i8*>
> > [#uses=1]
> >         call void @roc( i8* %pi_addr1 )
> > ...
> >
> > void roc(void*) is a function that only prints its argument as an
> integer.
>
> So it's printing the pointer.
>
> > I was expecting for the program to print the same thing twice (the
> > address of the myfunc argument) because the code added at runtime looks
> > to me identical with the code that was compiled (3 lines each).
> > However, that was not the case; what I got was:
> >
> > 147156320
> > 147117168
> >
> > What am I missing?
>
> Make roc() dereference the pointers it's given and print that instead.
>
> Nick
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090524/3a4f7735/attachment.html>


More information about the llvm-dev mailing list