[cfe-commits] r74772 - /cfe/trunk/lib/CodeGen/CGObjCGNU.cpp

Fariborz Jahanian fjahanian at apple.com
Fri Jul 3 08:10:17 PDT 2009


Author: fjahanian
Date: Fri Jul  3 10:10:14 2009
New Revision: 74772

URL: http://llvm.org/viewvc/llvm-project?rev=74772&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/CodeGen/CGObjCGNU.cpp

Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=74772&r1=74771&r2=74772&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Fri Jul  3 10:10:14 2009
@@ -180,7 +180,7 @@
   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 @@
   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;





More information about the cfe-commits mailing list