]> granicus.if.org Git - clang/commitdiff
This fixes the case where the wrong symbol is emitted leading to linking errors when...
authorFariborz Jahanian <fjahanian@apple.com>
Fri, 3 Jul 2009 15:10:14 +0000 (15:10 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Fri, 3 Jul 2009 15:10:14 +0000 (15:10 +0000)
Patch by David Chisnall.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@74772 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGObjCGNU.cpp

index 1e2218f8099c4823bbd6edb5adcd78f5ee778349..6554da9cf98c92bc47f6a41b906aa7ea65336b98 100644 (file)
@@ -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;