Preserve the linkage for objc* intrinsics as clang will set them to weak_external in some cases

Clang uses weak linkage for objc runtime functions when they are not available on the platform.

The intrinsic has this linkage so we just need to pass that on to the runtime call.

llvm-svn: 349559
diff --git a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
index 3689dab..b0e9ac0 100644
--- a/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
+++ b/llvm/lib/CodeGen/PreISelIntrinsicLowering.cpp
@@ -66,12 +66,15 @@
   // program already contains a function with this name.
   Module *M = F.getParent();
   Constant* FCache = M->getOrInsertFunction(NewFn, F.getFunctionType());
-  
-  // If we have Native ARC, set nonlazybind attribute for these APIs for
-  // performance.
-  if (setNonLazyBind)
-    if (Function* Fn = dyn_cast<Function>(FCache))
+
+  if (Function* Fn = dyn_cast<Function>(FCache)) {
+    Fn->setLinkage(F.getLinkage());
+    if (setNonLazyBind && !Fn->isWeakForLinker()) {
+      // If we have Native ARC, set nonlazybind attribute for these APIs for
+      // performance.
       Fn->addFnAttr(Attribute::NonLazyBind);
+    }
+  }
 
   for (auto I = F.use_begin(), E = F.use_end(); I != E;) {
     auto *CI = dyn_cast<CallInst>(I->getUser());