[PATCH] Objective-C: fix class_ro layout for non-LP64

Matt Jacobson mhjacobson@me.com
Tue Sep 21 22:29:24 GMT 2021

Fix class_ro layout for non-LP64.  On LP64, the requisite padding is added at a
lower level.  For non-LP64, this fixes binary compatibility with clang-built

Tested by examining the generated assembly for a class_ro in both cases (and in 
the case of clang), for both x86_64 (64-bit pointers) and AVR (16-bit pointers).
Tested by running a program on AVR with a GCC-built class using a clang-built 
Objective-C runtime.  Tested by running a program on x86_64/Darwin with a GCC-
built class and the clang-built system Objective-C runtime.

Patch also available at:

I don't have commit access, so if this patch is suitable, I'd need someone else 
to commit it for me.  Thanks.


2021-09-21  Matt Jacobson  <mhjacobson@me.com>

	* objc-next-runtime-abi-02.c (struct class_ro_t): Remove explicit alignment 
	(build_v2_class_templates): Remove explicit alignment padding.
	(build_v2_class_ro_t_initializer): Adjust initializer.

diff --git a/gcc/objc/objc-next-runtime-abi-02.c b/gcc/objc/objc-next-runtime-abi-02.c
index 42645e22316..c3af369ff0d 100644
--- a/gcc/objc/objc-next-runtime-abi-02.c
+++ b/gcc/objc/objc-next-runtime-abi-02.c
@@ -632,9 +632,7 @@ struct class_ro_t
     uint32_t const flags;
     uint32_t const instanceStart;
     uint32_t const instanceSize;
-#ifdef __LP64__
-    uint32_t const reserved;
+    // [32 bits of reserved space here on LP64 platforms]
     const uint8_t * const ivarLayout;
     const char *const name;
     const struct method_list_t * const baseMethods;
@@ -677,11 +675,6 @@ build_v2_class_templates (void)
   /* uint32_t const instanceSize; */
   add_field_decl (integer_type_node, "instanceSize", &chain);
-  /* This ABI is currently only used on m64 NeXT.  We always
-     explicitly declare the alignment padding.  */
-  /* uint32_t const reserved; */
-  add_field_decl (integer_type_node, "reserved", &chain);
   /* const uint8_t * const ivarLayout; */
   cnst_strg_type = build_pointer_type (unsigned_char_type_node);
   add_field_decl (cnst_strg_type, "ivarLayout", &chain);
@@ -3225,12 +3218,6 @@ build_v2_class_ro_t_initializer (tree type, tree name,
 			  build_int_cst (integer_type_node, instanceSize));
-  /* This ABI is currently only used on m64 NeXT.  We always
-     explicitly declare the alignment padding.  */
-  /* reserved, pads alignment.  */
-			    build_int_cst (integer_type_node, 0));
   /* ivarLayout */
   unsigned_char_star = build_pointer_type (unsigned_char_type_node);
   if (ivarLayout)

More information about the Gcc-patches mailing list