<div dir="ltr">Hello Richard Smith,<div><br></div><div>This makes a lot of sense. This is definitely the approach I will follow. Thank you!</div><div><br></div><div>If you know any source that you think it will help me to accomplish two-pass system efficiently other than clang source code, I will be happy to hear that. Thanks again! </div><div><br></div><div>Anil</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Oct 5, 2016 at 2:21 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="">On Tue, Oct 4, 2016 at 6:57 PM, Anil Altinay via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hi Vedant,<span class="m_4127017475896674014gmail-"><div><br></div><div><b><span style="font-size:12.8px">What kind of transformation are you interested in, and what kind of programs</span><br style="font-size:12.8px"><span style="font-size:12.8px">are you looking to transform?</span></b><br></div><div><span style="font-size:12.8px"><br></span></div></span><div>I am trying to change the layout of fields(randomize) in a struct in a c program. I already figured out how to change the layout of fields in a struct but there are structs that I should not touch like structs defined in libraries. So if I randomize a struct in one compilation unit and then realize that actually, I shouldn't have randomized it when clang was working on another compilation unit, there is no way to go back and revert the layout of the struct that I already randomized in previous translation unit because it is already over. So what I am thinking is I should look all the translation units in AST level before they create llvm IR and decide which structs I should randomize, then randomize the structs I have decided to randomize, then let clang to create llvm IR using modified ASTs.</div><div><br></div><div>I am trying to transform programs like apache.</div></div></blockquote><div><br></div></span><div>This problem falls within a category of related problems, where you want cross-source-file analysis in order to determine how to make per-source-file changes. The way we usually solve those kinds of problems is with a two-pass system: the first pass processes one translation unit at a time, and performs a local analysis to determine what to do under what circumstances. The local analysis results are then merged to determine what transformations to perform. Then a second pass over all translation units performs the actual code changes.</div><div><br></div><div>In your specific case, perhaps you could form a list for each TU of the functions defined locally, and the functions to which each potentially-reorderable type is passed. Then merge to form a complete list of function definitions controlled by the program, and determine whether a type is non-reorderable based on whether it's passed to a function that's not in your list.</div><div><br></div><div>In addition to not requiring a whole-program AST, this approach also parallelizes naturally (see <a href="http://www.hyrumwright.org/papers/icsm2013.pdf" target="_blank">http://www.hyrumwright.<wbr>org/papers/icsm2013.pdf</a> for more on how we use this kind of approach at Google).</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div class="h5"><div dir="ltr"><span class="m_4127017475896674014gmail-"><div><b><span style="font-size:12.8px">By 'AST of whole program', do you mean AST's for the source from all libraries</span><br style="font-size:12.8px"><span style="font-size:12.8px">linked into the program?</span></b><br></div><div><br></div></span><div>I am not sure if I understand your question but I will try to explain what I meant. For each translation unit, AST gets created. The problem is I can only see AST of current translation unit. I cannot see AST of next translation unit because clang works on one translation unit at a time. Maybe I should dump AST of each translation unit to the disk, decide which structs can be randomized, change the AST on the disk and start compilation from modified ASTs. But this may be so slow and I do not really know how I can do this.</div><div><br></div><div>Also I am not sure about one thing. Can I make sure that a struct is defined in a library or in the source code of the program by looking only one translation unit without any false flag? If I can, then there is no need for what I am asking for.</div><div><br></div><div>I hope that I explained what I am trying to do clearly. If you have any suggestion how I should do this, I would really appreciate hearing your opinion. Thank you very much for your quick response.</div><div><br></div><div>Anil </div><div><br></div><div><br></div><div><br></div></div><div class="m_4127017475896674014gmail-HOEnZb"><div class="m_4127017475896674014gmail-h5"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 4, 2016 at 5:58 PM, Vedant Kumar <span dir="ltr"><<a href="mailto:vsk@apple.com" target="_blank">vsk@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">- llvm-dev, + cfe-dev<br>
<br>
Hi,<br>
<br>
What kind of transformation are you interested in, and what kind of programs<br>
are you looking to transform?<br>
<br>
By 'AST of whole program', do you mean AST's for the source from all libraries<br>
linked into the program?<br>
<br>
vedant<br>
<div><div class="m_4127017475896674014gmail-m_1519029985652404574h5"><br>
<br>
> On Oct 4, 2016, at 5:50 PM, Anil Altinay via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
> Hello,<br>
><br>
> I would like to do transformations on AST of a c program but I need to have access to all ASTs created for the program to do right changes. LLVM processes one translation unit at a time and because of it, I do not have access to AST of all the translation units at the same time. Do you have any suggestion how I can access all the ASTs created for a program, do analysis on the ASTs and do modifications on the ASTs?<br>
><br>
> As a summary:<br>
><br>
> • I need to have access to ASTs of the program at the same time.<br>
> • Do analysis on ASTs.<br>
> • Modify ASTs based on my analysis and create llvm IR from modified ASTs.<br>
> Thank you,<br>
> Anil<br>
</div></div>> ______________________________<wbr>_________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
> <a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br>
</blockquote></div><br></div>
</div></div><br></div></div><span class="">______________________________<wbr>_________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-dev</a><br>
<br></span></blockquote></div><br></div></div>
</blockquote></div><br></div>