<div dir="ltr"><span class="gmail-im" style="font-size:12.8px"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span style="font-size:12.8px">wouldn't you want to extract the string literals along with the function in this case and re-link both later?</span><br style="font-size:12.8px"></blockquote><div><span style="font-size:12.8px"><br></span></div></span><div style="font-size:12.8px"><span style="font-size:12.8px">Yes and no. If a function does not share these string literals with others, it would be fine to extract and </span></div><div style="font-size:12.8px"><span style="font-size:12.8px">re-link both.</span></div><div style="font-size:12.8px"><span style="font-size:12.8px"><br></span></div><div style="font-size:12.8px">But on the application I am working on, these variables may be shared by several extracted functions, </div><div style="font-size:12.8px">thus it is best to keep them on the same place and just have them re-linked to this common variable.</div><div style="font-size:12.8px">This way, I don't have to worry about which function has the correct version.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">- nico</div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-08-30 14:27 GMT-05:00 UE US <span dir="ltr"><<a href="mailto:uexplorer666@gmail.com" target="_blank">uexplorer666@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I'm a bit rusty so forgive me if I'm not making sense, but wouldn't you want to extract the string literals along with the function in this case and re-link both later?<br><div class="gmail_extra"><br clear="all"><div>Gordon Keiser,</div><div>Software Delousing Engineer<br></div>
<br><div class="gmail_quote"><div><div class="h5">On Wed, Aug 30, 2017 at 2:53 PM, Nicolas Agostini via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">After trying different things, I realized that I should modify the visibility of the conflicting<div>variables on the target linked.ll file to hidden, before calling the linker.<div><br></div><div>This can be easily done by calling llvm-extract with the delete option to prepare a file to</div><div>receive the linked function</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"><span><span style="font-size:12.8px">llvm-extract-4.0 code03.ll -func main -S -o extracted_main.ll<br></span></span><span style="font-size:12.8px">lvm-extract-4.0 code03.ll -func main -delete -S -o linked.ll<br></span><span style="font-size:12.8px">llvm-link-4.0 linked.ll -only-needed -override extracted_main.ll -S -o linked_main.ll</span> </blockquote><div><br></div><div>This works great for a single module compilation.</div><div>But what are the effects if I have several modules?</div></div><div><br></div><div>Thanks,</div><div>- nico</div></div><div class="m_-3493761156350339060HOEnZb"><div class="m_-3493761156350339060h5"><div class="gmail_extra"><br><div class="gmail_quote">2017-08-29 17:10 GMT-05:00 Nicolas Agostini <span dir="ltr"><<a href="mailto:n.b.agostini@gmail.com" target="_blank">n.b.agostini@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi all, <div>First post to the list, I hope you can help or guide me on this task.</div><div><br></div><div>I am involved in a project that requires to re-link extracted and edited IR code<div><br></div><div>Thus I want to know if these tools can be used in this way?</div><div><br></div><div>clang++-4.0 code03.cpp -emit-llvm -S -o code03.ll</div><div><div>llvm-extract-4.0 code03.ll -func main -S -o extracted_main.ll</div></div><div><div>llvm-link-4.0 code03.ll -only-needed -override extracted_main.ll -S -o linked_main.ll</div><div>clang++-4.0 linked_main.ll -o main.out<br></div><div><br></div><div><br></div><div>where code03.cpp is:</div><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">#include <iostream><br>using namespace std;<br>int main()<br>{<br>  cout << "First Message\n ";<br>  cout << "Second Message\n ";<br>  cout << "Third Message\n ";<br>  return 0;<br>}</blockquote></div><div><br></div><div><br></div><div>I have been trying to extract a function's llvm IR, modify it preserving its signature (or not), and re-insert this function back to the original IR file, however I am getting an error during the compilation step ( clang++-4.0 linked_main.ll -o main.out ):</div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">main.ll:(.text+0x14): undefined reference to `.str'<br>main.ll:(.text+0x34): undefined reference to `.str.1'<br>main.ll:(.text+0x51): undefined reference to `.str.2'</blockquote><div><br></div><div> and linked_main.ll file has this section:</div></div><div><br></div><div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">@.str.4 = private unnamed_addr constant [16 x i8] c"First Message\0A \00", align 1<br>@.str.1.6 = private unnamed_addr constant [17 x i8] c"Second Message\0A \00", align 1<br>@.str.2.8 = private unnamed_addr constant [16 x i8] c"Third Message\0A \00", align 1<br>@.str = external hidden unnamed_addr constant [16 x i8], align 1<br>@.str.1 = external hidden unnamed_addr constant [17 x i8], align 1<br>@.str.2 = external hidden unnamed_addr constant [16 x i8], align 1</blockquote></div><div><br></div><div><br></div><div>But the function does not use the correct versions of the strings as the linked "extracted_main" keeps making calls to .str, .str.1, .str.2? Am I not supposed to do it this way?</div><div><br></div><div>Thank you in advance</div><div><br></div><div>- nico</div><div><br></div></div><div><br></div></div></div>
</blockquote></div><br></div>
</div></div><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>
</blockquote></div><br></div>