[clang] 8b066a4 - [ObjC] Don't place references to class stubs in __objc_superrefs (#227507)

via cfe-commits cfe-commits at lists.llvm.org
Thu Oct 1 09:56:44 PDT 2026


Author: Akira Hatanaka
Date: 2026-10-01T09:56:37-07:00
New Revision: 8b066a46fcef066dc6d40794cdd79423eb31d311

URL: https://github.com/llvm/llvm-project/commit/8b066a46fcef066dc6d40794cdd79423eb31d311
DIFF: https://github.com/llvm/llvm-project/commit/8b066a46fcef066dc6d40794cdd79423eb31d311.diff

LOG: [ObjC] Don't place references to class stubs in __objc_superrefs (#227507)

Loading a reference to a class stub calls objc_loadClassref, which
updates the reference in place. The __objc_superrefs section is a
constant section, so a reference to a class stub cannot be placed there.
Emit such references without a section instead.

rdar://184656330

Added: 
    

Modified: 
    clang/lib/CodeGen/CGObjCMac.cpp
    clang/test/CodeGenObjC/class-stubs.m

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 5d9781e61c1c4..ae0d4ad1869af 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -8391,7 +8391,11 @@ CGObjCNonFragileABIMac::EmitSuperClassRef(CodeGenFunction &CGF,
                                      llvm::GlobalValue::PrivateLinkage, ClassGV,
                                      "OBJC_CLASSLIST_SUP_REFS_$_");
     Entry->setAlignment(CGF.getPointerAlign().getAsAlign());
-    Entry->setSection(SectionName);
+    // Loading a reference to a class stub calls objc_loadClassref, which
+    // updates the reference in place. We cannot use the __objc_superrefs
+    // section here because it's a constant section.
+    if (!ID->hasAttr<ObjCClassStubAttr>())
+      Entry->setSection(SectionName);
     CGM.addCompilerUsedGlobal(Entry);
   }
 

diff  --git a/clang/test/CodeGenObjC/class-stubs.m b/clang/test/CodeGenObjC/class-stubs.m
index 3995eec9a3578..1609c85305e5f 100644
--- a/clang/test/CodeGenObjC/class-stubs.m
+++ b/clang/test/CodeGenObjC/class-stubs.m
@@ -18,7 +18,7 @@
 // The class is declared with objc_class_stub, so LSB of the class pointer
 // must be set to 1.
 //
-// CHECK-LABEL: @"OBJC_CLASSLIST_SUP_REFS_$_.1" = private global ptr getelementptr (i8, ptr @"OBJC_CLASS_$_Derived", i32 1), section "__DATA,__objc_superrefs,regular,no_dead_strip", align 8
+// CHECK-LABEL: @"OBJC_CLASSLIST_SUP_REFS_$_.1" = private global ptr getelementptr (i8, ptr @"OBJC_CLASS_$_Derived", i32 1), align 8
 
 // -- category list for class stubs goes in __objc_catlist2.
 //


        


More information about the cfe-commits mailing list