summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2009-07-03 15:10:14 +0000
committerFariborz Jahanian <fjahanian@apple.com>2009-07-03 15:10:14 +0000
commitbacbed9d7534d243d36285f6f8bb3e493aa8aa38 (patch)
treeee3bc180c4315858c95bd545105a09bdd0bf191f /clang/lib/CodeGen
parenta6f54b3a404b1cba1be992fe63df6ea2941ea7fd (diff)
downloadbcm5719-llvm-bacbed9d7534d243d36285f6f8bb3e493aa8aa38.tar.gz
bcm5719-llvm-bacbed9d7534d243d36285f6f8bb3e493aa8aa38.zip
This fixes the case where the wrong symbol is emitted leading to linking errors when you reference a class before defining it (GNU runtime).
Patch by David Chisnall. llvm-svn: 74772
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGObjCGNU.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CGObjCGNU.cpp b/clang/lib/CodeGen/CGObjCGNU.cpp
index 1e2218f8099..6554da9cf98 100644
--- a/clang/lib/CodeGen/CGObjCGNU.cpp
+++ b/clang/lib/CodeGen/CGObjCGNU.cpp
@@ -180,7 +180,7 @@ void CGObjCGNU::EmitClassRef(const std::string &className){
std::string symbolName = "__objc_class_name_" + className;
llvm::GlobalVariable *ClassSymbol = TheModule.getGlobalVariable(symbolName);
if (!ClassSymbol) {
- ClassSymbol = new llvm::GlobalVariable(LongTy, false,
+ ClassSymbol = new llvm::GlobalVariable(LongTy, false,
llvm::GlobalValue::ExternalLinkage, 0, symbolName, &TheModule);
}
new llvm::GlobalVariable(ClassSymbol->getType(), true,
@@ -859,9 +859,14 @@ void CGObjCGNU::GenerateClass(const ObjCImplementationDecl *OID) {
std::string ClassName = ClassDecl->getNameAsString();
// Emit the symbol that is used to generate linker errors if this class is
// referenced in other modules but not declared.
- new llvm::GlobalVariable(LongTy, false, llvm::GlobalValue::ExternalLinkage,
- llvm::ConstantInt::get(LongTy, 0), "__objc_class_name_" + ClassName,
- &TheModule);
+ std::string classSymbolName = "__objc_class_name_" + ClassName;
+ if (llvm::GlobalVariable *symbol =
+ TheModule.getGlobalVariable(classSymbolName)) {
+ symbol->setInitializer(llvm::ConstantInt::get(LongTy, 0));
+ } else {
+ new llvm::GlobalVariable(LongTy, false, llvm::GlobalValue::ExternalLinkage,
+ llvm::ConstantInt::get(LongTy, 0), classSymbolName, &TheModule);
+ }
// Get the size of instances.
int instanceSize = Context.getASTObjCImplementationLayout(OID).getSize() / 8;
OpenPOWER on IntegriCloud