<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></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 Oct 24, 2017, at 6:41 PM, Andrew Kelley <<a href="mailto:superjoe30@gmail.com" class="">superjoe30@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class="gmail_extra"><div class="gmail_quote">On Tue, Oct 24, 2017 at 9:27 PM, Vedant Kumar <span dir="ltr" class=""><<a href="mailto:vsk@apple.com" target="_blank" class="">vsk@apple.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word" class=""><span class="gmail-"><blockquote type="cite" class="">Unreferenced linkonce globals are allowed to be discarded.</blockquote><div class=""><br class=""></div></span><div class="">Is __udivmodti4 referenced?</div></div></blockquote><div class=""><br class=""></div><div class=""><br class=""></div><div class="">It's referenced by a different .o file, but nothing within the module.</div><div class=""><br class=""></div><div class="">My confusion comes from the missing direct object in the sentence. Referenced by a function local to the module? Referenced by any object in the linker job?</div></div></div></div></div></div></blockquote><div><br class=""></div>Ah I see. I read this as: "Linkonce globals which aren't referenced within their module are allowed to be discarded."</div><div><br class=""></div><div>To your point here:</div><div><blockquote type="cite" class=""><div dir="ltr" class=""><div class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div class="" style="word-wrap: break-word;"><div class=""><div class=""><blockquote type="cite" class=""><div class=""><div class=""><div class="gmail-h5"><div dir="ltr" class=""><div class="">Is there a linkage type that lets the linker merge functions of the same name but does not let the optimizer delete the function?</div></div></div></div></div></blockquote></div></div></div></blockquote></div></div></div></div></blockquote><br class=""></div><div>Does "weak" linkage work for you?</div><div><br class=""></div><div>vedant</div><div><br class=""></div><div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class="gmail_extra"><div class="gmail_quote"><div class=""> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="word-wrap:break-word" class=""><span class="gmail-HOEnZb"><font color="#888888" class=""><div class=""><br class=""></div><div class="">vedant</div></font></span><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class=""><div class="gmail-h5"><div class="">On Oct 24, 2017, at 6:09 PM, Andrew Kelley via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="gmail-m_-1380210676039972302Apple-interchange-newline"></div></div><div class=""><div class=""><div class="gmail-h5"><div dir="ltr" class=""><div class=""><a href="http://llvm.org/docs/LangRef.html#linkage-types" target="_blank" class="">http://llvm.org/docs/LangRef.<wbr class="">html#linkage-types</a> says:</div><div class=""><br class=""></div><div class=""><div class="">Globals with “linkonce” linkage are merged with other globals of the same name when linkage occurs. This can be used to implement some forms of inline functions, templates, or other code which must be generated in each translation unit that uses it, but where the body may be overridden with a more definitive definition later. Unreferenced linkonce globals are allowed to be discarded. Note that linkonce linkage does not actually allow the optimizer to inline the body of this function into callers because it doesn’t know if this definition of the function is the definitive definition within the program or whether it will be overridden by a stronger definition. To enable inlining and other optimizations, use “linkonce_odr” linkage.</div></div><div class=""><br class=""></div><div class="">This makes me think that linkonce globals will not be optimized out of an .o file, but they can be deleted by the linker. Here's some IR I have:</div><div class=""><br class=""></div><div class="">define linkonce i128 @__udivmodti4(i128, i128, i128*) local_unnamed_addr #0 !dbg !264 {</div><div class="">....</div><div class="">}</div><div class=""><br class=""></div><div class="">When I run:<br class=""><br class=""></div><div class="">opt -O3 -S compiler_rt.ll<br class=""></div><div class=""><br class=""></div><div class="">It deletes the function. Is this expected behavior?</div><div class=""><br class=""></div><div class="">Is there a linkage type that lets the linker merge functions of the same name but does not let the optimizer delete the function?</div><div class=""><br class=""></div><div class="">(let me know if providing the entire .ll file would be helpful)</div><div class=""><br class=""></div><div class="">Regards,</div><div class="">Andrew Kelley</div></div></div></div><span class="gmail-">
______________________________<wbr class="">_________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a><br class=""><a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank" class="">http://lists.llvm.org/cgi-bin/<wbr class="">mailman/listinfo/llvm-dev</a><br class=""></span></div></blockquote></div><br class=""></div></div></blockquote></div><br class=""></div></div></div>
</div></blockquote></div><br class=""></body></html>