<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 13, 2016, at 10:27 AM, Tarun Prabhu via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I am trying to use LLVM to get the IR for a whole program. The program's Makefile is somewhat complicated so I have written wrappers which emit LLVM IR at every step in the process instead of ELF object files and executables. My problem is that during linking, I get "multiple definition" errors. Here is a small example:<div class=""><br class=""></div><div class=""><font face="monospace, monospace" class="">file: a.c </font></div><div class=""><font face="monospace, monospace" class="">---------</font></div><div class=""><font face="monospace, monospace" class="">int f_a(int m) { return m + 1; }</font></div><div class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><font face="monospace, monospace" class="">file: b.c</font></div><div class=""><font face="monospace, monospace" class="">----------</font></div><div class=""><font face="monospace, monospace" class="">int f_a(int);</font></div><div class=""><font face="monospace, monospace" class="">int f_b(int n) { return f_a(n); }</font></div><div class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><font face="monospace, monospace" class="">file: driver.c </font></div><div class=""><font face="monospace, monospace" class="">--------------</font></div><div class=""><font face="monospace, monospace" class="">int f_b(int);</font></div><div class=""><font face="monospace, monospace" class="">int main(int argc, char *argv[]) {</font></div><div class=""><font face="monospace, monospace" class=""> return f_b(argc);</font></div><div class=""><font face="monospace, monospace" class="">}</font></div><div class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><font face="monospace, monospace" class=""><br class=""></font></div><div class=""><font face="monospace, monospace" class="">$ clang -flto -Wl,-plugin-opt=emit-llvm -shared -o libA.so a.c</font></div><div class=""><font face="monospace, monospace" class="">$ clang -flto -Wl,-plugin-opt=emit-llvm -shared -o libB.so b.c -L. -lA</font></div><div class=""><font face="monospace, monospace" class="">$ clang -flto -Wl,-plugin-opt=emit-llvm -o driver driver.c -L. -lA -lB</font></div><div class=""><br class=""></div><div class="">All the .so files here are obviously now bitcode files. The last command fails with a "multiple definition" error because both libB.so and libA.so contain a definition for f_a. </div></div></div></blockquote><div><br class=""></div><div>I've never used .so that are bitcode files before, that seems weird to me, since the point of a .so is to stay a separated entity and not being linked into the main executable.</div><div>Any reason you're not using static archives? It seems to correspond more to what you're trying to do (i.e. LTO all the code in a single binary).</div><div><br class=""></div><div><br class=""></div><div>-- </div><div>Mehdi</div><div><br class=""></div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">My question is: Is there a way to have the linker only import the definitions from shared objects when linking the final executable and in all other cases just use the declaration? Or, is there a way to get the linker to pick one of several identical definitions? </div><div class=""><br class=""></div><div class="">Thanks,</div><div class=""><br class=""></div><div class="">Tarun</div><div class=""><br class=""></div></div>
_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></div></blockquote></div><br class=""></body></html>