<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 8, 2016 at 11:22 AM, Teresa Johnson <span dir="ltr"><<a href="mailto:tejohnson@google.com" target="_blank">tejohnson@google.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"><br><div class="gmail_extra"><br><div class="gmail_quote"><span class="">On Mon, Feb 8, 2016 at 11:06 AM, David Blaikie <span dir="ltr"><<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@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">I couldn't quite follow the test - but wouldn't removing things (or in any way modifyidng) from a COMDAT cause problems? (the COMDAT would no longer match between objects, etc?)</div></blockquote><div><br></div></span><div>The comdat will not be emitted in the importing module if we import its definitions as available_externally, since any such imported defs will be removed from the comdat with this patch. Any non-imported members remained decls and are not part of a comdat in the importing module either.</div></div></div></div></blockquote><div><br></div><div>Ah, right - thanks! (the available_externally helps me understand)<br><br>Though perhaps we should remove the comdats, to be safe? Once we're adding/removing things from them they're no longer accurate anyway. Is there any benefit to keeping them? Seems like they're just likely to be a trap/misleading thing to keep them around.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><div class="h5"><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 8, 2016 at 10:47 AM, Teresa Johnson via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: tejohnson<br>
Date: Mon Feb 8 12:47:20 2016<br>
New Revision: 260122<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=260122&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=260122&view=rev</a><br>
Log:<br>
[ThinLTO] Remove imported available externally defs from comdats.<br>
<br>
Summary:<br>
Available externally definitions are considered declarations for the<br>
linker and eventually dropped. As such they are not allowed to be<br>
in comdats. Remove any such imported functions from comdats.<br>
<br>
Reviewers: rafael<br>
<br>
Subscribers: davidxl, llvm-commits, joker.eph<br>
<br>
Differential Revision: <a href="http://reviews.llvm.org/D16120" rel="noreferrer" target="_blank">http://reviews.llvm.org/D16120</a><br>
<br>
Added:<br>
llvm/trunk/test/Linker/Inputs/funcimport_comdat.ll<br>
llvm/trunk/test/Linker/funcimport_comdat.ll<br>
Modified:<br>
llvm/trunk/lib/Linker/LinkModules.cpp<br>
<br>
Modified: llvm/trunk/lib/Linker/LinkModules.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=260122&r1=260121&r2=260122&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=260122&r1=260121&r2=260122&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)<br>
+++ llvm/trunk/lib/Linker/LinkModules.cpp Mon Feb 8 12:47:20 2016<br>
@@ -722,9 +722,21 @@ void ThinLTOGlobalProcessing::processGlo<br>
GV.setVisibility(GlobalValue::HiddenVisibility);<br>
if (isModuleExporting())<br>
NewExportedValues.insert(&GV);<br>
- return;<br>
+ } else<br>
+ GV.setLinkage(getLinkage(&GV));<br>
+<br>
+ // Remove functions imported as available externally defs from comdats,<br>
+ // as this is a declaration for the linker, and will be dropped eventually.<br>
+ // It is illegal for comdats to contain declarations.<br>
+ auto *GO = dyn_cast_or_null<GlobalObject>(&GV);<br>
+ if (GO && GO->isDeclarationForLinker() && GO->hasComdat()) {<br>
+ // The IRMover should not have placed any imported declarations in<br>
+ // a comdat, so the only declaration that should be in a comdat<br>
+ // at this point would be a definition imported as available_externally.<br>
+ assert(GO->hasAvailableExternallyLinkage() &&<br>
+ "Expected comdat on definition (possibly available external)");<br>
+ GO->setComdat(nullptr);<br>
}<br>
- GV.setLinkage(getLinkage(&GV));<br>
}<br>
<br>
void ThinLTOGlobalProcessing::processGlobalsForThinLTO() {<br>
<br>
Added: llvm/trunk/test/Linker/Inputs/funcimport_comdat.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/Inputs/funcimport_comdat.ll?rev=260122&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/Inputs/funcimport_comdat.ll?rev=260122&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/Linker/Inputs/funcimport_comdat.ll (added)<br>
+++ llvm/trunk/test/Linker/Inputs/funcimport_comdat.ll Mon Feb 8 12:47:20 2016<br>
@@ -0,0 +1,4 @@<br>
+define i32 @main() #0 {<br>
+entry:<br>
+ ret i32 0<br>
+}<br>
<br>
Added: llvm/trunk/test/Linker/funcimport_comdat.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/funcimport_comdat.ll?rev=260122&view=auto" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/funcimport_comdat.ll?rev=260122&view=auto</a><br>
==============================================================================<br>
--- llvm/trunk/test/Linker/funcimport_comdat.ll (added)<br>
+++ llvm/trunk/test/Linker/funcimport_comdat.ll Mon Feb 8 12:47:20 2016<br>
@@ -0,0 +1,28 @@<br>
+; Do setup work for all below tests: generate bitcode and combined index<br>
+; RUN: llvm-as -function-summary %s -o %t.bc<br>
+; RUN: llvm-as -function-summary %p/Inputs/funcimport_comdat.ll -o %t2.bc<br>
+; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc<br>
+<br>
+; Ensure linking of comdat containing external linkage global and function<br>
+; removes the imported available_externally defs from comdat.<br>
+; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=comdat1_func1:%t.bc -S | FileCheck %s --check-prefix=IMPORTCOMDAT<br>
+; IMPORTCOMDAT-NOT: $comdat1 = comdat any<br>
+; IMPORTCOMDAT-NOT: comdat($comdat1)<br>
+<br>
+; Ensure linking of comdat containing internal linkage function with alias<br>
+; removes the imported and promoted available_externally defs from comdat.<br>
+; RUN: llvm-link %t2.bc -functionindex=%t3.thinlto.bc -import=comdat2_func1:%t.bc -S | FileCheck %s --check-prefix=IMPORTCOMDAT2<br>
+; IMPORTCOMDAT2-NOT: $comdat2 = comdat any<br>
+; IMPORTCOMDAT2-NOT: comdat($comdat2)<br>
+<br>
+$comdat1 = comdat any<br>
+@comdat1_glob = global i32 0, comdat($comdat1)<br>
+define void @comdat1_func1() comdat($comdat1) {<br>
+ ret void<br>
+}<br>
+<br>
+$comdat2 = comdat any<br>
+@comdat2_alias = alias void (), void ()* @comdat2_func1<br>
+define internal void @comdat2_func1() comdat($comdat2) {<br>
+ ret void<br>
+}<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div>
</div></div></blockquote></div></div></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div><span style="font-family:Times;font-size:medium"><table cellspacing="0" cellpadding="0"><tbody><tr style="color:rgb(85,85,85);font-family:sans-serif;font-size:small"><td nowrap style="border-top-style:solid;border-top-color:rgb(213,15,37);border-top-width:2px">Teresa Johnson |</td><td nowrap style="border-top-style:solid;border-top-color:rgb(51,105,232);border-top-width:2px"> Software Engineer |</td><td nowrap style="border-top-style:solid;border-top-color:rgb(0,153,57);border-top-width:2px"> <a href="mailto:tejohnson@google.com" target="_blank">tejohnson@google.com</a> |</td><td nowrap style="border-top-style:solid;border-top-color:rgb(238,178,17);border-top-width:2px"> <a href="tel:408-460-2413" value="+14084602413" target="_blank">408-460-2413</a></td></tr></tbody></table></span></div>
</font></span></div></div>
</blockquote></div><br></div></div>