From 8e873329a1dbe298a861f79a0696fdb64f9cc25f Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Wed, 4 Jun 2014 21:04:54 +0000 Subject: Don't emit structors for available_externally globals (PR19933) We would previously assert here when trying to figure out the section for the global. This makes us handle the situation more gracefully since the IR isn't malformed. Differential Revision: http://reviews.llvm.org/D4022 llvm-svn: 210215 --- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'llvm/lib/CodeGen') diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index 6c6d0dae9e7..49c2ee20c20 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1349,9 +1349,14 @@ void AsmPrinter::EmitXXStructorList(const Constant *List, bool isCtor) { const TargetLoweringObjectFile &Obj = getObjFileLowering(); const MCSymbol *KeySym = nullptr; const MCSection *KeySec = nullptr; - if (S.ComdatKey) { - KeySym = getSymbol(S.ComdatKey); - KeySec = getObjFileLowering().SectionForGlobal(S.ComdatKey, *Mang, TM); + if (GlobalValue *GV = S.ComdatKey) { + if (GV->hasAvailableExternallyLinkage()) + // If the associated variable is available_externally, some other TU + // will provide its dynamic initializer. + continue; + + KeySym = getSymbol(GV); + KeySec = getObjFileLowering().SectionForGlobal(GV, *Mang, TM); } const MCSection *OutputSection = (isCtor ? Obj.getStaticCtorSection(S.Priority, KeySym, KeySec) -- cgit v1.2.3