diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2014-03-06 22:15:10 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2014-03-06 22:15:10 +0000 |
commit | 060062a433d1c2c5f1f89f6c42858a5d48bef9e1 (patch) | |
tree | 2ee9a296aaf7b4dd183c5ab9c1289362a2a28e4c /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 297febee570230e88334540ce43e7c470d211cbb (diff) | |
download | bcm5719-llvm-060062a433d1c2c5f1f89f6c42858a5d48bef9e1.tar.gz bcm5719-llvm-060062a433d1c2c5f1f89f6c42858a5d48bef9e1.zip |
Use llvm.compiler.used instead of llvm.used for objc symbols.
LLVM currently has a hack (shouldEmitUsedDirectiveFor) that causes it to not
print no_dead_strip for symbols starting with 'l' or 'L'. These are exactly the
ones that the clang's objc codegen is producing. The net result, is that it is
equivalent to llvm.compiler.used.
The need for putting the private symbol in llvm.compiler.used should be clear
(the objc runtime uses them). The reason for also putting the weak symbols in
it is for LTO: ld64 will not ask us to preserve the it.
llvm-svn: 203172
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index f0265b33f57..9b3e32952e1 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -258,7 +258,7 @@ void CodeGenModule::Release() { EmitCtorList(GlobalDtors, "llvm.global_dtors"); EmitGlobalAnnotations(); EmitStaticExternCAliases(); - EmitLLVMUsed(); + emitLLVMUsed(); if (CodeGenOpts.Autolink && (Context.getLangOpts().Modules || !LinkerOptionsMetadata.empty())) { @@ -699,7 +699,7 @@ void CodeGenModule::SetCommonAttributes(const Decl *D, GV->setVisibility(llvm::GlobalValue::DefaultVisibility); if (D->hasAttr<UsedAttr>()) - AddUsedGlobal(GV); + addUsedGlobal(GV); if (const SectionAttr *SA = D->getAttr<SectionAttr>()) GV->setSection(SA->getName()); @@ -776,39 +776,51 @@ void CodeGenModule::SetFunctionAttributes(GlobalDecl GD, llvm::Attribute::NoBuiltin); } -void CodeGenModule::AddUsedGlobal(llvm::GlobalValue *GV) { +void CodeGenModule::addUsedGlobal(llvm::GlobalValue *GV) { assert(!GV->isDeclaration() && "Only globals with definition can force usage."); LLVMUsed.push_back(GV); } -void CodeGenModule::EmitLLVMUsed() { +void CodeGenModule::addCompilerUsedGlobal(llvm::GlobalValue *GV) { + assert(!GV->isDeclaration() && + "Only globals with definition can force usage."); + LLVMCompilerUsed.push_back(GV); +} + +static void emitUsed(CodeGenModule &CGM, StringRef Name, + std::vector<llvm::WeakVH> &List) { // Don't create llvm.used if there is no need. - if (LLVMUsed.empty()) + if (List.empty()) return; - // Convert LLVMUsed to what ConstantArray needs. + // Convert List to what ConstantArray needs. SmallVector<llvm::Constant*, 8> UsedArray; - UsedArray.resize(LLVMUsed.size()); - for (unsigned i = 0, e = LLVMUsed.size(); i != e; ++i) { + UsedArray.resize(List.size()); + for (unsigned i = 0, e = List.size(); i != e; ++i) { UsedArray[i] = - llvm::ConstantExpr::getBitCast(cast<llvm::Constant>(&*LLVMUsed[i]), - Int8PtrTy); + llvm::ConstantExpr::getBitCast(cast<llvm::Constant>(&*List[i]), + CGM.Int8PtrTy); } if (UsedArray.empty()) return; - llvm::ArrayType *ATy = llvm::ArrayType::get(Int8PtrTy, UsedArray.size()); + llvm::ArrayType *ATy = llvm::ArrayType::get(CGM.Int8PtrTy, UsedArray.size()); llvm::GlobalVariable *GV = - new llvm::GlobalVariable(getModule(), ATy, false, + new llvm::GlobalVariable(CGM.getModule(), ATy, false, llvm::GlobalValue::AppendingLinkage, llvm::ConstantArray::get(ATy, UsedArray), - "llvm.used"); + Name); GV->setSection("llvm.metadata"); } +void CodeGenModule::emitLLVMUsed() { + emitUsed(*this, "llvm.used", LLVMUsed); + emitUsed(*this, "llvm.compiler.used", LLVMCompilerUsed); +} + void CodeGenModule::AppendLinkerOptions(StringRef Opts) { llvm::Value *MDOpts = llvm::MDString::get(getLLVMContext(), Opts); LinkerOptionsMetadata.push_back(llvm::MDNode::get(getLLVMContext(), MDOpts)); @@ -3054,7 +3066,7 @@ void CodeGenModule::EmitStaticExternCAliases() { IdentifierInfo *Name = I->first; llvm::GlobalValue *Val = I->second; if (Val && !getModule().getNamedValue(Name->getName())) - AddUsedGlobal(new llvm::GlobalAlias(Val->getType(), Val->getLinkage(), + addUsedGlobal(new llvm::GlobalAlias(Val->getType(), Val->getLinkage(), Name->getName(), Val, &getModule())); } } |