From 197d33ce212271ffd8fe647fb21ff17ce93d9887 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 19 Jan 2006 00:40:39 +0000 Subject: [PATCH] Don't internalize llvm.global[cd]tor unless there are uses of it. This unbreaks front-ends that don't use __main (like the new CFE). llvm-svn: 25429 --- lib/Transforms/IPO/Internalize.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/Transforms/IPO/Internalize.cpp b/lib/Transforms/IPO/Internalize.cpp index 427545e4de1..d583d888684 100644 --- a/lib/Transforms/IPO/Internalize.cpp +++ b/lib/Transforms/IPO/Internalize.cpp @@ -109,7 +109,7 @@ bool InternalizePass::runOnModule(Module &M) { // Never internalize the llvm.used symbol. It is used to implement // attribute((used)). ExternalNames.insert("llvm.used"); - + // Never internalize anchors used by the debugger, else the debugger won't // find them. ExternalNames.insert("llvm.dbg.translation_units"); @@ -125,13 +125,19 @@ bool InternalizePass::runOnModule(Module &M) { // the list if it's empty. // if (I->hasAppendingLinkage() && (I->getName() == "llvm.global_ctors" || - I->getName() == "llvm.global_dtors")) + I->getName() == "llvm.global_dtors")) { I->setConstant(true); + + // If the global ctors/dtors list has no uses, do not internalize it, as + // there is no __main in this program, so the asmprinter should handle + // it. + if (I->use_empty()) continue; + } I->setLinkage(GlobalValue::InternalLinkage); Changed = true; ++NumGlobals; - DEBUG(std::cerr << "Internalizing gvar " << I->getName() << "\n"); + DEBUG(std::cerr << "Internalized gvar " << I->getName() << "\n"); } return Changed;