<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 style="font-size:12.8px">llvm-extract-4.0 code03.ll -func main -S -o extracted_main.ll<br></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="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>