<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=""><div><div class="">On Dec 31, 2015, at 5:03 AM, Dimitry Andric via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><blockquote type="cite" class=""><div class="">This thread unfortunately died out without any resolution, so we are now<br class="">nearing 3.8 branching, and the problem is still not fixed.  E.g., the<br class="">only custom patch we have now left in FreeBSD's version of llvm (which<br class="">we would really like to get rid of!) is the reversal of r240144: it is a<br class="">pretty gross workaround, but it works for now.<br class=""><br class="">But is there any way that we can get this resolved before 3.8.0 ships,<br class="">please? :-)<br class=""></div></blockquote></div><div class=""><br class=""></div><div class="">I believe the summary of the thread is that LLVM has a fundamentally unsound transformation: automatically increasing the required alignment of an externally visible global variable.</div><div class=""><br class=""></div><div class="">In enforceKnownAlignment in lib/Transforms/Utils/Local.cpp, it checks isStrongDefinitionForLinker() purportedly to ensure that the "memory we set aside for the global" is "the memory used by the final program.". However, even if said predicate returns true, that condition is NOT guaranteed, at least on ELF platforms, because of copy relocations.</div><div class=""><br class=""></div><div class="">(There's also very similar-looking alignment-fixing code in CodeGenPrepare::optimizeCallInst, too, I'm not sure why it's duplicated there.)</div><div class=""><br class=""></div><div class="">Basically, we need to not modify the alignment if:</div><div style="margin: 0px; font-size: 11px; font-family: Menlo;" class=""><div style="margin: 0px; font-size: 11px;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #34bbc7" class=""><b class="">if</b></span> (Subtarget->isTargetELF() &&</div><div style="margin: 0px; font-size: 11px;" class="">    TM.getRelocationModel() == <span style="font-variant-ligatures: no-common-ligatures; color: #d53bd3" class="">Reloc</span>::PIC_ &&</div><div style="margin: 0px; font-size: 11px;" class="">    GV->hasDefaultVisibility() && !GV->hasLocalLinkage())</div><div style="margin: 0px; font-size: 11px;" class=""><br class=""></div><div class=""><span style="font-family: Helvetica;" class="">The above code snippet appears in X86FastISel.cpp, and equivalent-but-not-identical code appears in several other places, to determine whether a PLT load for the variable is required.</span></div><div class=""><span style="font-family: Helvetica;" class=""><br class=""></span></div><div class=""><span style="font-family: Helvetica;" class="">I'm not sure if isStrongDefinitionForLinker itself ought to be taking that into account, or if there should be a different new predicate for that check. isReallyActuallyTrulyStrongDefinitionForLinker()? :)</span></div></div><div class=""><br class=""></div></body></html>