r323247 - CodeGen: use `llvm.used` for ObjC protocols

Saleem Abdulrasool via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 23 11:35:51 PST 2018


Author: compnerd
Date: Tue Jan 23 11:35:51 2018
New Revision: 323247

URL: http://llvm.org/viewvc/llvm-project?rev=323247&view=rev
Log:
CodeGen: use `llvm.used` for ObjC protocols

These symbols are supposed to be preserved even by the linker.  Use the
`llvm.used` to ensure that the symbols are not removed by DCE in the
linker.  This should be a no-op change on MachO since the symbols are
annotated as `no_dead_strip`.

Modified:
    cfe/trunk/lib/CodeGen/CGObjCMac.cpp
    cfe/trunk/test/CodeGenObjC/forward-protocol-metadata-symbols.m

Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=323247&r1=323246&r2=323247&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Tue Jan 23 11:35:51 2018
@@ -6399,7 +6399,7 @@ llvm::Value *CGObjCNonFragileABIMac::Gen
   PTGV->setAlignment(Align.getQuantity());
   if (!CGM.getTriple().isOSBinFormatMachO())
     PTGV->setComdat(CGM.getModule().getOrInsertComdat(ProtocolName));
-  CGM.addCompilerUsedGlobal(PTGV);
+  CGM.addUsedGlobal(PTGV);
   return CGF.Builder.CreateAlignedLoad(PTGV, Align);
 }
 
@@ -6843,7 +6843,7 @@ llvm::Constant *CGObjCNonFragileABIMac::
     Protocols[PD->getIdentifier()] = Entry;
   }
   Entry->setVisibility(llvm::GlobalValue::HiddenVisibility);
-  CGM.addCompilerUsedGlobal(Entry);
+  CGM.addUsedGlobal(Entry);
 
   // Use this protocol meta-data to build protocol list table in section
   // __DATA, __objc_protolist
@@ -6862,7 +6862,7 @@ llvm::Constant *CGObjCNonFragileABIMac::
   PTGV->setSection(GetSectionName("__objc_protolist",
                                   "coalesced,no_dead_strip"));
   PTGV->setVisibility(llvm::GlobalValue::HiddenVisibility);
-  CGM.addCompilerUsedGlobal(PTGV);
+  CGM.addUsedGlobal(PTGV);
   return Entry;
 }
 

Modified: cfe/trunk/test/CodeGenObjC/forward-protocol-metadata-symbols.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/forward-protocol-metadata-symbols.m?rev=323247&r1=323246&r2=323247&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/forward-protocol-metadata-symbols.m (original)
+++ cfe/trunk/test/CodeGenObjC/forward-protocol-metadata-symbols.m Tue Jan 23 11:35:51 2018
@@ -23,15 +23,17 @@ int main() {
 // CHECK: @"\01l_OBJC_LABEL_PROTOCOL_$_P0" = weak hidden global
 // CHECK: @"\01l_OBJC_PROTOCOL_REFERENCE_$_P0" = weak hidden global
 
-// CHECK: llvm.compiler.used = appending global [10 x i8*]
+// CHECK: llvm.used = appending global [3 x i8*]
+// CHECK-SAME: "\01l_OBJC_PROTOCOL_$_P0"
+// CHECK-SAME: "\01l_OBJC_LABEL_PROTOCOL_$_P0"
+// CHECK-SAME: "\01l_OBJC_PROTOCOL_REFERENCE_$_P0"
+
+// CHECK: llvm.compiler.used = appending global [7 x i8*]
 // CHECK-SAME: OBJC_CLASS_NAME_
 // CHECK-SAME: OBJC_METH_VAR_NAME_
 // CHECK-SAME: OBJC_METH_VAR_TYPE_
 // CHECK-SAME: "\01l_OBJC_$_CLASS_METHODS_A"
 // CHECK-SAME: "\01l_OBJC_CLASS_PROTOCOLS_$_A"
 // CHECK-SAME: OBJC_CLASS_NAME_.1
-// CHECK-SAME: "\01l_OBJC_PROTOCOL_$_P0"
-// CHECK-SAME: "\01l_OBJC_LABEL_PROTOCOL_$_P0"
-// CHECK-SAME: "\01l_OBJC_PROTOCOL_REFERENCE_$_P0"
 // CHECK-SAME: "OBJC_LABEL_CLASS_$"
 // CHECK-SAME: section "llvm.metadata"




More information about the cfe-commits mailing list