[llvm] r278739 - [ThinLTO] Remove functions resolved to available_externally from comdats

Teresa Johnson via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 15 14:00:04 PDT 2016


Author: tejohnson
Date: Mon Aug 15 16:00:04 2016
New Revision: 278739

URL: http://llvm.org/viewvc/llvm-project?rev=278739&view=rev
Log:
[ThinLTO] Remove functions resolved to available_externally from comdats

Summary:
thinLTOResolveWeakForLinkerModule needs to drop any preempted weak symbols
that were converted to available_externally from comdats, otherwise we
will get a verification failure (since available_externally is a
declaration for the linker, and no declarations can be in a comdat).

Reviewers: mehdi_amini

Subscribers: llvm-commits, mehdi_amini

Differential Revision: https://reviews.llvm.org/D23015

Added:
    llvm/trunk/test/ThinLTO/X86/Inputs/linkonce_resolution_comdat.ll
    llvm/trunk/test/ThinLTO/X86/linkonce_resolution_comdat.ll
Modified:
    llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp

Modified: llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp?rev=278739&r1=278738&r2=278739&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/FunctionImport.cpp Mon Aug 15 16:00:04 2016
@@ -493,6 +493,15 @@ void llvm::thinLTOResolveWeakForLinkerMo
     DEBUG(dbgs() << "ODR fixing up linkage for `" << GV.getName() << "` from "
                  << GV.getLinkage() << " to " << NewLinkage << "\n");
     GV.setLinkage(NewLinkage);
+    // Remove functions converted to available_externally from comdats,
+    // as this is a declaration for the linker, and will be dropped eventually.
+    // It is illegal for comdats to contain declarations.
+    auto *GO = dyn_cast_or_null<GlobalObject>(&GV);
+    if (GO && GO->isDeclarationForLinker() && GO->hasComdat()) {
+      assert(GO->hasAvailableExternallyLinkage() &&
+             "Expected comdat on definition (possibly available external)");
+      GO->setComdat(nullptr);
+    }
   };
 
   // Process functions and global now

Added: llvm/trunk/test/ThinLTO/X86/Inputs/linkonce_resolution_comdat.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/Inputs/linkonce_resolution_comdat.ll?rev=278739&view=auto
==============================================================================
--- llvm/trunk/test/ThinLTO/X86/Inputs/linkonce_resolution_comdat.ll (added)
+++ llvm/trunk/test/ThinLTO/X86/Inputs/linkonce_resolution_comdat.ll Mon Aug 15 16:00:04 2016
@@ -0,0 +1,13 @@
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+$c2 = comdat any
+
+define linkonce_odr i32 @f(i8*) unnamed_addr comdat($c2) {
+    ret i32 41
+}
+
+define i32 @g() {
+    %i = call i32 @f(i8* null)
+    ret i32 %i
+}

Added: llvm/trunk/test/ThinLTO/X86/linkonce_resolution_comdat.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ThinLTO/X86/linkonce_resolution_comdat.ll?rev=278739&view=auto
==============================================================================
--- llvm/trunk/test/ThinLTO/X86/linkonce_resolution_comdat.ll (added)
+++ llvm/trunk/test/ThinLTO/X86/linkonce_resolution_comdat.ll Mon Aug 15 16:00:04 2016
@@ -0,0 +1,23 @@
+; This test ensures that we drop the preempted copy of @f from %t2.bc from its
+; comdat after making it available_externally. If not we would get a
+; verification error.
+; RUN: opt -module-summary %s -o %t1.bc
+; RUN: opt -module-summary %p/Inputs/linkonce_resolution_comdat.ll -o %t2.bc
+; RUN: llvm-lto -thinlto-action=run %t1.bc %t2.bc -exported-symbol=f -exported-symbol=g -disable-inlining
+
+; RUN: llvm-nm -o - < %t1.bc.thinlto.o | FileCheck %s --check-prefix=NM1
+; NM1: W f
+
+; RUN: llvm-nm -o - < %t2.bc.thinlto.o | FileCheck %s --check-prefix=NM2
+; f() would have been turned into available_externally since it is preempted,
+; and inlined into g()
+; NM2-NOT: f
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+$c1 = comdat any
+
+define linkonce_odr i32 @f(i8*) unnamed_addr comdat($c1) {
+    ret i32 43
+}




More information about the llvm-commits mailing list