]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
[PATCH] Objective-C: NeXT runtime fixes.
authorIain Sandoe <iain@sandoe.co.uk>
Thu, 1 Oct 2020 09:58:58 +0000 (10:58 +0100)
committerIain Sandoe <iain@sandoe.co.uk>
Tue, 31 May 2022 18:27:05 +0000 (19:27 +0100)
The NeXT runtime has changed ABI in detail a number of times over Darwin
revisions from 9 to 21.  For the most part, the tools are tolerant of use
of older ABI revisions - for X86.  However for Arm64 deviations cause
link time errors.  This is small set of updates to match the system tools.

1. Objective-C: Addess a FIXME (NFC).

This removes references to the next runtime from the gnu runtime
implementation.

2. Objective-C, Darwin : Use special string sections for V2 NeXT runtime.

Newer versions of the runtime expect to find strings for class, method
and method types in set-aside sections rather than the general c_strings
one.

3. Ojective-C, Darwin : Adjust category superclass ref names (NFC).

Make the order of the class and superclass match the metadata
order from clang.  Makes it easier to compare produced meta-
data between implementations.

4. Objective-C: Default flag_objc_sjlj_exceptions off for NeXT ABI >= 2.

As per description.

5. Objective-C, NeXT runtime: Correct the default for fobjc-nilcheck.

It is intended that the default for the NeXT runtime at ABI 2 is to
check for nil message receivers.  This updates this to match the
documented behaviour and to match the behaviour of the system tools.

6. Objective-C, NeXT: Reorganise meta-data declarations.

This moves the GTY declaration of the meta-data indentifier
array into the header that enumerates these and provides
shorthand defines for them.  This avoids a problem seen with
a relocatable PCH implementation.

7. Objective-C, NeXT: Adjust symbol marking to match host tools.

Current host tools mark some additional symbols as 'no dead strip' and also
expose one additional group to the linker.  This does not affect older Darwin
versions or x86_64, but omitting these changes results in link errors for
aarch64.

Backported from commits 900c0ca22673ec4d382ce588057de240f887be3a,
a788c4555c6d17a5b37516e28844e6fd6013eb3e,
1174b08b140d1fed6012d7dcf66165fabd49b7e5,
798666392b512a585f0de2983a5d3423e960959e,
de0b250b2badb475f8c09f3cd2c57fd3f9127fe3,
c9419faef0bfaf31e6a6f744baa064892e0d105c and
ecd5727c0a662a8fea6b5f8eac6f3f15bf5ef851

Signed-off-by: Iain Sandoe <iain@sandoe.co.uk>
Signed-off-by: Matt Jacobson <mhjacobson@me.com>
gcc/c-family/ChangeLog:

* c-opts.c (c_common_post_options): Default to
flag_objc_sjlj_exceptions = 1 only when flag_objc_abi < 2.

gcc/ChangeLog:

* config/darwin-sections.def (objc2_class_names_section,
objc2_method_names_section, objc2_method_types_section): New
* config/darwin.c (output_objc_section_asm_op): Output new
sections.  (darwin_objc2_section): Select new sections where
used.
(darwin_label_is_anonymous_local_objc_name): Make
protocol class methods linker-visible.

gcc/objc/ChangeLog:

* objc-next-metadata-tags.h (objc_rt_trees): Declare here.
* objc-next-runtime-abi-01.c: Remove from here.
(generate_static_references): Likewise.
* objc-next-runtime-abi-02.c: Likewise.
(objc_next_runtime_abi_02_init): Warn about and reset
flag_objc_sjlj_exceptions regardless of flag_objc_exceptions.
(next_runtime_02_initialize): Use a checking assert that
flag_objc_sjlj_exceptions is off.
(next_runtime_abi_02_category_decl): Adjust category
superclass name ordering.
(next_runtime_abi_02_init_metadata_attributes): Attach metadata
for the special string sections to class, method and method type
string sections.
(next_runtime_abi_02_protocol_decl): Do not dead-strip the runtime
meta-data symbols.
(build_v2_classrefs_table): Likewise.
(build_v2_protocol_list_address_table): Likewise.
(objc_next_runtime_abi_02_init): Default receiver nilchecks on.
* objc-runtime-shared-support.c: Reorder headers, provide
a GTY declaration the definition of objc_rt_trees.
* objc-gnu-runtime-abi-01.c
(build_shared_structure_initializer): Remove references to
the NeXT runtime.

gcc/c-family/c-opts.c
gcc/config/darwin-sections.def
gcc/config/darwin.c
gcc/objc/objc-gnu-runtime-abi-01.c
gcc/objc/objc-next-metadata-tags.h
gcc/objc/objc-next-runtime-abi-01.c
gcc/objc/objc-next-runtime-abi-02.c
gcc/objc/objc-runtime-shared-support.c

index 3a96cbe596ec3009f4e45685a4ef611f6cf911cc..17c9c722d48e5f6f73ee94fff716323a92ed87ce 100644 (file)
@@ -840,9 +840,9 @@ c_common_post_options (const char **pfilename)
   else if (!flag_gnu89_inline && !flag_isoc99)
     error ("%<-fno-gnu89-inline%> is only supported in GNU99 or C99 mode");
 
-  /* Default to ObjC sjlj exception handling if NeXT runtime.  */
+  /* Default to ObjC sjlj exception handling if NeXT runtime < v2.  */
   if (flag_objc_sjlj_exceptions < 0)
-    flag_objc_sjlj_exceptions = flag_next_runtime;
+    flag_objc_sjlj_exceptions = (flag_next_runtime && flag_objc_abi < 2);
   if (flag_objc_exceptions && !flag_objc_sjlj_exceptions)
     flag_exceptions = 1;
 
index 65bf5ad37a0c378a9f8164b9d3271a5351418120..aa7e7081c2b6d58b89f078e7fe6607fc55d023aa 100644 (file)
@@ -201,6 +201,7 @@ DEF_SECTION (objc2_constant_string_object_section, 0,
 
 /* Additions for compatibility with later runtime conventions especially for
    sections containing strings.  */
+
 DEF_SECTION (objc2_data_section, 0, ".section __DATA, __data", 1)
 
 DEF_SECTION (objc2_ivar_section, 0, ".section __DATA, __objc_ivar", 1)
index 39391986788bcefe4f4ee7262c5d633efdc2d69c..20d89a18443f4aec6aed6358b4d398696c31c2be 100644 (file)
@@ -1939,6 +1939,8 @@ darwin_label_is_anonymous_local_objc_name (const char *name)
     }
   else if (!strncmp ((const char *)p, "ClassMethods", 12))
     return false;
+  else if (!strncmp ((const char *)p, "ClassProtocols", 14))
+    return false;
   else if (!strncmp ((const char *)p, "Instance", 8))
     {
       if (p[8] == 'I' || p[8] == 'M')
index 3dd95219feb07881657329eec85f6e58516bd41a..9a26f52a520b823d3427da59a51a2265efd705ba 100644 (file)
@@ -1547,25 +1547,14 @@ build_shared_structure_initializer (tree type, tree isa, tree super,
       CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, expr);
     }
 
-  /* FIXME: Remove NeXT runtime code.  */
-  if (flag_next_runtime)
-    {
-      ltyp = build_pointer_type (xref_tag (RECORD_TYPE,
-                                          get_identifier ("objc_cache")));
-      /* method_cache = */
-      CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, convert (ltyp, null_pointer_node));
-    }
-  else
-    {
-      /* dtable = */
-      CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, build_int_cst (NULL_TREE, 0));
+  /* dtable = */
+  CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, build_int_cst (NULL_TREE, 0));
 
-      /* subclass_list = */
-      CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, build_int_cst (NULL_TREE, 0));
+  /* subclass_list = */
+  CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, build_int_cst (NULL_TREE, 0));
 
-      /* sibling_class = */
-      CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, build_int_cst (NULL_TREE, 0));
-    }
+  /* sibling_class = */
+  CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, build_int_cst (NULL_TREE, 0));
 
   /* protocol_list = */
   ltyp = build_pointer_type (build_pointer_type (objc_protocol_template));
@@ -1579,11 +1568,6 @@ build_shared_structure_initializer (tree type, tree isa, tree super,
       CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, expr);
     }
 
-  /* FIXME: Remove NeXT runtime code.  */
-  if (flag_next_runtime)
-    /* sel_id = NULL */
-    CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, build_int_cst (NULL_TREE, 0));
-
   /* gc_object_type = NULL */
   CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, build_int_cst (NULL_TREE, 0));
 
@@ -1871,10 +1855,6 @@ generate_static_references (void)
   char buf[BUFSIZE];
   vec<constructor_elt, va_gc> *decls = NULL;
 
-  /* FIXME: Remove NeXT runtime code.  */
-  if (flag_next_runtime)
-    gcc_unreachable ();
-
   for (cl_chain = objc_static_instances, num_class = 0;
        cl_chain; cl_chain = TREE_CHAIN (cl_chain), num_class++)
     {
index 3058fab07d1d80eddab11ec81d20c0fa00b325bb..b91befe659abe91d61ae58c8f11d06fe32386e4e 100644 (file)
@@ -79,6 +79,8 @@ enum objc_runtime_tree_index
   OCTI_RT_META_MAX
 };
 
+extern GTY(()) tree objc_rt_trees[OCTI_RT_META_MAX];
+
 /* Tags for the META data so that the backend can put them in the correct
    sections for targets/runtimes (Darwin/NeXT) that require this.
    This information also survives LTO - which might produce mixed language
index be2e55e28b62d1c82e95835358916e1d153fb312..e457903ccdbf8b374c856bcbaf0f024a3d272ed8 100644 (file)
@@ -54,6 +54,7 @@ along with GCC; see the file COPYING3.  If not see
 
 #include "objc-runtime-hooks.h"
 #include "objc-runtime-shared-support.h"
+#include "objc-next-metadata-tags.h"
 #include "objc-encoding.h"
 
 /* NeXT ABI 0 and 1 private definitions.  */
@@ -98,14 +99,6 @@ along with GCC; see the file COPYING3.  If not see
 
 #define CLS_HAS_CXX_STRUCTORS          0x2000L
 
-/* rt_trees identifiers - shared between NeXT implementations.  These
-   allow the FE to tag meta-data in a manner that survives LTO and can
-   be used when the runtime requires that certain meta-data items
-   appear in particular named sections.  */
-
-#include "objc-next-metadata-tags.h"
-extern GTY(()) tree objc_rt_trees[OCTI_RT_META_MAX];
-
 static void next_runtime_01_initialize (void);
 
 static tree next_runtime_abi_01_super_superclassfield_id (void);
index c2513712a9f38eec32b2b49997bd1a805c650668..aac1eb394055cbb80ffcf03a27163159ee276ecd 100644 (file)
@@ -54,6 +54,7 @@ along with GCC; see the file COPYING3.  If not see
 
 #include "objc-runtime-hooks.h"
 #include "objc-runtime-shared-support.h"
+#include "objc-next-metadata-tags.h"
 #include "objc-encoding.h"
 
 /* ABI 2 Private definitions. */
@@ -179,14 +180,6 @@ enum objc_v2_tree_index
 #define objc_rethrow_exception_decl \
                                objc_v2_global_trees[OCTI_V2_RETHROW_DECL]
 
-/* rt_trees identifiers - shared between NeXT implementations.  These allow
-   the FE to tag meta-data in a manner that survives LTO and can be used when
-   the  runtime requires that certain meta-data items appear in particular
-   named sections.  */
-
-#include "objc-next-metadata-tags.h"
-extern GTY(()) tree objc_rt_trees[OCTI_RT_META_MAX];
-
 /* The OCTI_V2_... enumeration itself is in above.  */
 static GTY(()) tree objc_v2_global_trees[OCTI_V2_MAX];
 
@@ -245,7 +238,7 @@ objc_next_runtime_abi_02_init (objc_runtime_hooks *rthooks)
 {
   extern_names = ggc_cleared_vec_alloc<hash> (SIZEHASHTABLE);
 
-  if (flag_objc_exceptions && flag_objc_sjlj_exceptions)
+  if (flag_objc_sjlj_exceptions)
     {
       inform (UNKNOWN_LOCATION,
              "%<-fobjc-sjlj-exceptions%> is ignored for "
@@ -254,6 +247,10 @@ objc_next_runtime_abi_02_init (objc_runtime_hooks *rthooks)
       flag_objc_sjlj_exceptions = 0;
     }
 
+  /* NeXT ABI 2 is intended to default to checking for nil receivers.  */
+  if (! global_options_set.x_flag_objc_nilcheck)
+    flag_objc_nilcheck = 1;
+
   rthooks->initialize = next_runtime_02_initialize;
   rthooks->default_constant_string_class_name = DEF_CONSTANT_STRING_CLASS_NAME;
   rthooks->tag_getclass = TAG_GETCLASS;
@@ -507,7 +504,7 @@ static void next_runtime_02_initialize (void)
   objc_getPropertyStruct_decl = NULL_TREE;
   objc_setPropertyStruct_decl = NULL_TREE;
 
-  gcc_assert (!flag_objc_sjlj_exceptions);
+  gcc_checking_assert (!flag_objc_sjlj_exceptions);
 
   /* Although we warn that fobjc-exceptions is required for exceptions
      code, we carry on and create it anyway.  */
@@ -1010,9 +1007,9 @@ next_runtime_abi_02_category_decl (tree klass)
 {
   tree decl;
   char buf[BUFSIZE];
-  snprintf (buf, BUFSIZE, "_OBJC_Category_%s_on_%s",
-           IDENTIFIER_POINTER (CLASS_SUPER_NAME (klass)),
-           IDENTIFIER_POINTER (CLASS_NAME (klass)));
+  snprintf (buf, BUFSIZE, "_OBJC_Category_%s_%s",
+           IDENTIFIER_POINTER (CLASS_NAME (klass)),
+           IDENTIFIER_POINTER (CLASS_SUPER_NAME (klass)));
   decl = start_var_decl (objc_v2_category_template, buf);
   OBJCMETA (decl, objc_meta, meta_category);
   return decl;
@@ -1035,6 +1032,7 @@ next_runtime_abi_02_protocol_decl (tree p)
   else
     decl = start_var_decl (objc_v2_protocol_template, buf);
   OBJCMETA (decl, objc_meta, meta_protocol);
+  DECL_PRESERVE_P (decl) = 1;
   return decl;
 }
 
@@ -2113,8 +2111,8 @@ build_v2_classrefs_table (void)
          expr = convert (objc_class_type, build_fold_addr_expr (expr));
        }
       /* The runtime wants this, even if it appears unused, so we must force the
-        output.
-      DECL_PRESERVE_P (decl) = 1; */
+        output.  */
+      DECL_PRESERVE_P (decl) = 1;
       finish_var_decl (decl, expr);
     }
 }
@@ -2316,6 +2314,7 @@ build_v2_protocol_list_address_table (void)
       expr = convert (objc_protocol_type, build_fold_addr_expr (ref->refdecl));
       OBJCMETA (decl, objc_meta, meta_label_protocollist);
       finish_var_decl (decl, expr);
+      DECL_PRESERVE_P (decl) = 1;
     }
 
     /* TODO: delete the vec.  */
index 16d4d63c86f3d6e67bbabbed3010e46afedbe6aa..78825893ee2b4e641d1fca7d9da0a1f0cd337071 100644 (file)
@@ -44,16 +44,11 @@ along with GCC; see the file COPYING3.  If not see
 #include "objc-runtime-hooks.h"
 
 #include "objc-runtime-shared-support.h"
-#include "objc-encoding.h"
-
-/* rt_trees identifiers - shared between NeXT implementations.  These allow
-   the FE to tag meta-data in a manner that survives LTO and can be used when
-   the  runtime requires that certain meta-data items appear in particular
-   named sections.  */
 #include "objc-next-metadata-tags.h"
-extern GTY(()) tree objc_rt_trees[OCTI_RT_META_MAX];
+#include "objc-encoding.h"
 
 /* Rather than repeatedly looking up the identifiers, we save them here.  */
+extern GTY(()) tree objc_rt_trees[OCTI_RT_META_MAX];
 tree objc_rt_trees[OCTI_RT_META_MAX];
 
 /* For building an objc struct.  These might not be used when this file