<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><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">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>