<div dir="ltr">"weak" linkage was the solution. Thanks for the tip.<br><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 24, 2017 at 10:01 PM, Andrew Kelley <span dir="ltr"><<a href="mailto:superjoe30@gmail.com" target="_blank">superjoe30@gmail.com</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">"weak" worked on linux. I'm waiting to see if tests pass for<div><br><div> * MacOS: <a href="https://travis-ci.org/zig-lang/zig/jobs/292392617" target="_blank">https://travis-ci.org/zig-<wbr>lang/zig/jobs/292392617</a></div><div> * Windows: <a href="https://ci.appveyor.com/project/andrewrk/zig-d3l86/build/1.0.478" target="_blank">https://ci.appveyor.<wbr>com/project/andrewrk/zig-<wbr>d3l86/build/1.0.478</a></div><div><br></div><div>I'll report back when they're done.</div><div><br></div></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Oct 24, 2017 at 9:49 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><br><div><span><blockquote type="cite"><div>On Oct 24, 2017, at 6:41 PM, Andrew Kelley <<a href="mailto:superjoe30@gmail.com" target="_blank">superjoe30@gmail.com</a>> wrote:</div><br class="m_-3232462959182330521m_-1664691715368816930Apple-interchange-newline"><div><div dir="ltr"><div><div class="gmail_extra"><div class="gmail_quote">On Tue, Oct 24, 2017 at 9:27 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"><div style="word-wrap:break-word"><span class="m_-3232462959182330521m_-1664691715368816930gmail-"><blockquote type="cite">Unreferenced linkonce globals are allowed to be discarded.</blockquote><div><br></div></span><div>Is __udivmodti4 referenced?</div></div></blockquote><div><br></div><div><br></div><div>It's referenced by a different .o file, but nothing within the module.</div><div><br></div><div>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></div></span>Ah I see. I read this as: "Linkonce globals which aren't referenced within their module are allowed to be discarded."</div><div><br></div><div>To your point here:</div><span><div><blockquote type="cite"><div dir="ltr"><div><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 style="word-wrap:break-word"><div><div><blockquote type="cite"><div><div><div class="m_-3232462959182330521m_-1664691715368816930gmail-h5"><div dir="ltr"><div>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></div></span><div>Does "weak" linkage work for you?</div><span class="m_-3232462959182330521HOEnZb"><font color="#888888"><div><br></div><div>vedant</div></font></span><span><div><br></div><div><br><blockquote type="cite"><div><div dir="ltr"><div><div class="gmail_extra"><div class="gmail_quote"><div> </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"><span class="m_-3232462959182330521m_-1664691715368816930gmail-HOEnZb"><font color="#888888"><div><br></div><div>vedant</div></font></span><div><br><div><blockquote type="cite"><div><div class="m_-3232462959182330521m_-1664691715368816930gmail-h5"><div>On Oct 24, 2017, at 6:09 PM, Andrew Kelley via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="m_-3232462959182330521m_-1664691715368816930gmail-m_-1380210676039972302Apple-interchange-newline"></div></div><div><div><div class="m_-3232462959182330521m_-1664691715368816930gmail-h5"><div dir="ltr"><div><a href="http://llvm.org/docs/LangRef.html#linkage-types" target="_blank">http://llvm.org/docs/LangRef.h<wbr>tml#linkage-types</a> says:</div><div><br></div><div><div>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><br></div><div>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><br></div><div>define linkonce i128 @__udivmodti4(i128, i128, i128*) local_unnamed_addr #0 !dbg !264 {</div><div>....</div><div>}</div><div><br></div><div>When I run:<br><br></div><div>opt -O3 -S compiler_rt.ll<br></div><div><br></div><div>It deletes the function. Is this expected behavior?</div><div><br></div><div>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><br></div><div>(let me know if providing the entire .ll file would be helpful)</div><div><br></div><div>Regards,</div><div>Andrew Kelley</div></div></div></div><span class="m_-3232462959182330521m_-1664691715368816930gmail-">
______________________________<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" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br></span></div></blockquote></div><br></div></div></blockquote></div><br></div></div></div>
</div></blockquote></div><br></span></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div></div>