[llvm] r180202 - Don't produce an empty llvm.compiler.used in LTO.
Rafael Espindola
rafael.espindola at gmail.com
Wed Apr 24 10:54:36 PDT 2013
Author: rafael
Date: Wed Apr 24 12:54:35 2013
New Revision: 180202
URL: http://llvm.org/viewvc/llvm-project?rev=180202&view=rev
Log:
Don't produce an empty llvm.compiler.used in LTO.
LTO was always creating an empty llvm.compiler.used. With this patch we
now first check if there is anything to be added first.
Unfortunately, there is no good way to test libLTO in isolation as it needs gold
or ld64, but there are bots doing LTO builds that found this problem.
Modified:
llvm/trunk/tools/lto/LTOCodeGenerator.cpp
Modified: llvm/trunk/tools/lto/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOCodeGenerator.cpp?rev=180202&r1=180201&r2=180202&view=diff
==============================================================================
--- llvm/trunk/tools/lto/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/tools/lto/LTOCodeGenerator.cpp Wed Apr 24 12:54:35 2013
@@ -287,9 +287,7 @@ static void findUsedValues(GlobalVariabl
SmallPtrSet<GlobalValue*, 8> &UsedValues) {
if (LLVMUsed == 0) return;
- ConstantArray *Inits = dyn_cast<ConstantArray>(LLVMUsed->getInitializer());
- if (Inits == 0) return;
-
+ ConstantArray *Inits = cast<ConstantArray>(LLVMUsed->getInitializer());
for (unsigned i = 0, e = Inits->getNumOperands(); i != e; ++i)
if (GlobalValue *GV =
dyn_cast<GlobalValue>(Inits->getOperand(i)->stripPointerCasts()))
@@ -326,23 +324,25 @@ void LTOCodeGenerator::applyScopeRestric
if (LLVMCompilerUsed)
LLVMCompilerUsed->eraseFromParent();
- llvm::Type *i8PTy = llvm::Type::getInt8PtrTy(_context);
- std::vector<Constant*> asmUsed2;
- for (SmallPtrSet<GlobalValue*, 16>::const_iterator i = asmUsed.begin(),
- e = asmUsed.end(); i !=e; ++i) {
- GlobalValue *GV = *i;
- Constant *c = ConstantExpr::getBitCast(GV, i8PTy);
- asmUsed2.push_back(c);
- }
-
- llvm::ArrayType *ATy = llvm::ArrayType::get(i8PTy, asmUsed2.size());
- LLVMCompilerUsed =
- new llvm::GlobalVariable(*mergedModule, ATy, false,
- llvm::GlobalValue::AppendingLinkage,
- llvm::ConstantArray::get(ATy, asmUsed2),
- "llvm.compiler.used");
+ if (!asmUsed.empty()) {
+ llvm::Type *i8PTy = llvm::Type::getInt8PtrTy(_context);
+ std::vector<Constant*> asmUsed2;
+ for (SmallPtrSet<GlobalValue*, 16>::const_iterator i = asmUsed.begin(),
+ e = asmUsed.end(); i !=e; ++i) {
+ GlobalValue *GV = *i;
+ Constant *c = ConstantExpr::getBitCast(GV, i8PTy);
+ asmUsed2.push_back(c);
+ }
+
+ llvm::ArrayType *ATy = llvm::ArrayType::get(i8PTy, asmUsed2.size());
+ LLVMCompilerUsed =
+ new llvm::GlobalVariable(*mergedModule, ATy, false,
+ llvm::GlobalValue::AppendingLinkage,
+ llvm::ConstantArray::get(ATy, asmUsed2),
+ "llvm.compiler.used");
- LLVMCompilerUsed->setSection("llvm.metadata");
+ LLVMCompilerUsed->setSection("llvm.metadata");
+ }
passes.add(createInternalizePass(mustPreserveList));
More information about the llvm-commits
mailing list