Andrew Santosa via llvm-dev
2017-Jun-04 02:31 UTC
[llvm-dev] Get elements from a getelementptr constant expression
If what is needed is to simply extract the operands of a getelementptr constant expression, I wrote a simple example here: https://github.com/analysis-examples/gep-expr-example Best, Andrew On Wednesday, 31 May 2017, 19:53, via llvm-dev <llvm-dev at lists.llvm.org> wrote: Message: 8 Date: Tue, 30 May 2017 22:13:09 -0400 From: Damilola Orikogbo via llvm-dev <llvm-dev at lists.llvm.org> To: llvm-dev at lists.llvm.org Subject: [llvm-dev] Get elements from a getelementptr constant expression Message-ID: <CAJJs-5kRu1r1L8zy56Vv1g78Uijj-EoJ4_z689cgXd=2vMugWA at mail.gmail.com> Content-Type: text/plain; charset="utf-8" Hi, I have this instruction, store i32 (...)** bitcast (i8** getelementptr inbounds ([5 x i8*], [5 x i8*]* @_ZTV9Rectangle, i32 0, i32 2) to i32 (...)**), i32 (...)*** %5, align 8 and was wondering how to access the indices of the getelementptr. How would i print out all pointers stored from index 0 to 5. Cheers, Dami -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170530/4bd0d076/attachment-0001.html> ------------------------------ Message: 9 Date: Tue, 30 May 2017 23:20:02 -0400 From: Damilola Orikogbo via llvm-dev <llvm-dev at lists.llvm.org> To: Tim Northover <t.p.northover at gmail.com>, llvm-dev at lists.llvm.org Subject: Re: [llvm-dev] Get elements from a getelementptr constant expression Message-ID: <CAJJs-5=nn1JRNWoENCB3Q2coqmr=V1rDJzcQTMTRQTnF6pg1dg at mail.gmail.com> Content-Type: text/plain; charset="utf-8" Hello, I apologize, I am new to the list-serve (joined on the 25th) and am not quite sure how it works. I didn't reply to Hans because the llvm/ clang distribution I have installed doesn't allow me to use that command line option, I will respond in a bit. And I asked anther question simply because no one replied to my first question. I have been using llvm for about a week, so I am not sure how to ask my question succinctly but I am trying, please bear with me. In reply to your response, I will try that out tomorrow and hopefully be able to make some headway. I have been searching previous emails and have found that some people have cast the getelementptr in the Instruction i posted in this original email thread to a constantexpr or GEPOperator and have been able to get information that way, but I can't quite seem to figure it out. *Ex email thread:* https://groups.google.com/forum/#!topic/llvm-dev/_F-PFACaHbU <https://groups.google.com/forum/#!topic/llvm-dev/_F-PFACaHbU> If anyone has tried this approach and could provide some more information going this route, I would appreciate that as well. Cheers, Dami On Tue, May 30, 2017 at 10:37 PM, Tim Northover <t.p.northover at gmail.com> wrote:> Hi,>> On 30 May 2017 at 19:13, Damilola Orikogbo via llvm-dev> <llvm-dev at lists.llvm.org> wrote:> > store i32 (...)** bitcast (i8** getelementptr inbounds ([5 x i8*], [5 x> > i8*]* @_ZTV9Rectangle, i32 0, i32 2) to i32 (...)**), i32 (...)*** %5,> align> > 8> >> > and was wondering how to access the indices of the getelementptr. How> would> > i print out all pointers stored from index 0 to 5.>> You really need to start replying to your own threads. The one I> noticed this morning was particularly useless compared to your message> from 25th May, and you didn't even clarify your problem for Hans after> he replied.>> That said, if you'd identified a vtable you would insert code to GEP> element N and then pass the result to something like a printf> expecting a %p. Of course you need to know in advance that your vtable> contains 5 entries.>> So you'd create a bunch of instructions looking vaguely like:>> call void @printf(@WHATEVER_FOR_PERCENT_P, bitcast(i8**> getelementptr inbounds([5 x i8*], [5 x i8*]* @_ZTV9Rectangle, i32 0,> i32 N) to i8*)>> The chances are you won't always have a @_ZTV* global as a base though> (that's the entire point of dynamic dispatch). In which case you'd> have to create a bunch of instructions like:>> %tmp = getelementptr inbounds [5 * i8*], [5 x i8*]* %vtable, i32 0,> i32 N> %tmp1 = bitcast i8** %tmp to i8*> call void @printf(@WHATEVER_FOR_PERCENT_P, %tmp1)>> Tim.>-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170530/dafec7d9/attachment-0001.html> ------------------------------ Message: 10 Date: Tue, 30 May 2017 23:23:42 -0400 From: Damilola Orikogbo via llvm-dev <llvm-dev at lists.llvm.org> To: Hans Wennborg <hans at chromium.org>, llvm-dev at lists.llvm.org Subject: Re: [llvm-dev] Dumping the Vtable Message-ID: <CAJJs-5k1+GJPrDanMXE3-VPvFa6dBDhTqSnoJidyxhqyjzMXrw at mail.gmail.com> Content-Type: text/plain; charset="utf-8" Hi Hans, Thanks for the reply. I apologize for the unclear question. I am new to using clang and llvm. I have tried this but the version I have for some reason won't allow me to use this command line option. Furthermore, I am trying to get this information via the IR and writing a pass to get this information to use at a later point. -Dami On Tue, May 30, 2017 at 12:56 PM, Hans Wennborg <hans at chromium.org> wrote:> Hi Damilola,>> On Mon, May 29, 2017 at 5:20 AM, Damilola Orikogbo via llvm-dev> <llvm-dev at lists.llvm.org> wrote:> > Can someone help me with how to dump the vtable and the vptr addresses> > within it?>> I'm not sure if this answers your question exactly, but you can pass> "-Xclang -fdump-vtable-layouts" to ask Clang to dump the layout of> generated vtables. For example:>> $ cat /tmp/a.cc> struct S {> virtual void f() {};> };>> void f(S * s) {> s->f();> }> $ bin/clang++ -c /tmp/a.cc -Xclang -fdump-vtable-layouts> Vtable for 'S' (3 entries).> 0 | offset_to_top (0)> 1 | S RTTI> -- (S, 0) vtable address --> 2 | void S::f()>> VTable indices for 'S' (1 entries).> 0 | void S::f()>>> - Hans>-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20170530/b8cc0e82/attachment-0001.html>