]> granicus.if.org Git - clang/commitdiff
Tweaked selector mangling again (GNU runtime).
authorDavid Chisnall <csdavec@swan.ac.uk>
Sun, 9 May 2010 01:01:43 +0000 (01:01 +0000)
committerDavid Chisnall <csdavec@swan.ac.uk>
Sun, 9 May 2010 01:01:43 +0000 (01:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103368 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGObjCGNU.cpp

index ca9f16c45120583659cd10d748ebff17b9e8d540..da64c6907fa8aed6fc562e91d7002ba83d0c405c 100644 (file)
@@ -237,7 +237,17 @@ static std::string SymbolNameForMethod(const std::string &ClassName, const
 }
 static std::string MangleSelectorTypes(const std::string &TypeString) {
   std::string Mangled = TypeString;
+  // Simple mangling to avoid breaking when we mix JIT / static code.
+  // Not part of the ABI, subject to change without notice.
   std::replace(Mangled.begin(), Mangled.end(), '@', '_');
+  std::replace(Mangled.begin(), Mangled.end(), ':', 'J');
+  std::replace(Mangled.begin(), Mangled.end(), '*', 'e');
+  std::replace(Mangled.begin(), Mangled.end(), '#', 'E');
+  std::replace(Mangled.begin(), Mangled.end(), ':', 'j');
+  std::replace(Mangled.begin(), Mangled.end(), '(', 'g');
+  std::replace(Mangled.begin(), Mangled.end(), ')', 'G');
+  std::replace(Mangled.begin(), Mangled.end(), '[', 'h');
+  std::replace(Mangled.begin(), Mangled.end(), ']', 'H');
   return Mangled;
 }
 
@@ -1670,9 +1680,10 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() {
     llvm::Constant *Idxs[] = {Zeros[0],
       llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), index++), Zeros[0]};
     llvm::Constant *SelPtr = new llvm::GlobalVariable(TheModule, SelStructPtrTy,
-        true, llvm::GlobalValue::LinkOnceODRLinkage,
-        llvm::ConstantExpr::getGetElementPtr(SelectorList, Idxs, 2),
-        ".objc_sel_ptr"+iter->first.first+"."+MangleSelectorTypes(iter->first.second));
+      true, llvm::GlobalValue::LinkOnceODRLinkage,
+      llvm::ConstantExpr::getGetElementPtr(SelectorList, Idxs, 2),
+      MangleSelectorTypes(".objc_sel_ptr"+iter->first.first+"."+
+         iter->first.second));
     // If selectors are defined as an opaque type, cast the pointer to this
     // type.
     if (isSelOpaque) {
@@ -1688,9 +1699,9 @@ llvm::Function *CGObjCGNU::ModuleInitFunction() {
     llvm::Constant *Idxs[] = {Zeros[0],
       llvm::ConstantInt::get(llvm::Type::getInt32Ty(VMContext), index++), Zeros[0]};
     llvm::Constant *SelPtr = new llvm::GlobalVariable(TheModule, SelStructPtrTy,
-        true, llvm::GlobalValue::LinkOnceODRLinkage,
-        llvm::ConstantExpr::getGetElementPtr(SelectorList, Idxs, 2),
-        ".objc_sel_ptr"+iter->getKey());
+      true, llvm::GlobalValue::LinkOnceODRLinkage,
+      llvm::ConstantExpr::getGetElementPtr(SelectorList, Idxs, 2),
+      MangleSelectorTypes(std::string(".objc_sel_ptr")+iter->getKey().str()));
     // If selectors are defined as an opaque type, cast the pointer to this
     // type.
     if (isSelOpaque) {