public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r10-10806] [PATCH] Objective-C: NeXT runtime fixes.
@ 2022-05-31 18:32 Iain D Sandoe
  0 siblings, 0 replies; only message in thread
From: Iain D Sandoe @ 2022-05-31 18:32 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:5f75e80ecb3b99587ae588820b3872a14a71c21e

commit r10-10806-g5f75e80ecb3b99587ae588820b3872a14a71c21e
Author: Iain Sandoe <iain@sandoe.co.uk>
Date:   Thu Oct 1 10:58:58 2020 +0100

    [PATCH] Objective-C: NeXT runtime fixes.
    
    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.

Diff:
---
 gcc/c-family/c-opts.c                  |  4 ++--
 gcc/config/darwin-sections.def         |  1 +
 gcc/config/darwin.c                    |  2 ++
 gcc/objc/objc-gnu-runtime-abi-01.c     | 32 ++++++--------------------------
 gcc/objc/objc-next-metadata-tags.h     |  2 ++
 gcc/objc/objc-next-runtime-abi-01.c    |  9 +--------
 gcc/objc/objc-next-runtime-abi-02.c    | 29 ++++++++++++++---------------
 gcc/objc/objc-runtime-shared-support.c |  9 ++-------
 8 files changed, 30 insertions(+), 58 deletions(-)

diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
index 3a96cbe596e..17c9c722d48 100644
--- a/gcc/c-family/c-opts.c
+++ b/gcc/c-family/c-opts.c
@@ -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;
 
diff --git a/gcc/config/darwin-sections.def b/gcc/config/darwin-sections.def
index 65bf5ad37a0..aa7e7081c2b 100644
--- a/gcc/config/darwin-sections.def
+++ b/gcc/config/darwin-sections.def
@@ -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)
diff --git a/gcc/config/darwin.c b/gcc/config/darwin.c
index 39391986788..20d89a18443 100644
--- a/gcc/config/darwin.c
+++ b/gcc/config/darwin.c
@@ -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')
diff --git a/gcc/objc/objc-gnu-runtime-abi-01.c b/gcc/objc/objc-gnu-runtime-abi-01.c
index 3dd95219feb..9a26f52a520 100644
--- a/gcc/objc/objc-gnu-runtime-abi-01.c
+++ b/gcc/objc/objc-gnu-runtime-abi-01.c
@@ -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++)
     {
diff --git a/gcc/objc/objc-next-metadata-tags.h b/gcc/objc/objc-next-metadata-tags.h
index 3058fab07d1..b91befe659a 100644
--- a/gcc/objc/objc-next-metadata-tags.h
+++ b/gcc/objc/objc-next-metadata-tags.h
@@ -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
diff --git a/gcc/objc/objc-next-runtime-abi-01.c b/gcc/objc/objc-next-runtime-abi-01.c
index be2e55e28b6..e457903ccdb 100644
--- a/gcc/objc/objc-next-runtime-abi-01.c
+++ b/gcc/objc/objc-next-runtime-abi-01.c
@@ -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);
diff --git a/gcc/objc/objc-next-runtime-abi-02.c b/gcc/objc/objc-next-runtime-abi-02.c
index c2513712a9f..aac1eb39405 100644
--- a/gcc/objc/objc-next-runtime-abi-02.c
+++ b/gcc/objc/objc-next-runtime-abi-02.c
@@ -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.  */
diff --git a/gcc/objc/objc-runtime-shared-support.c b/gcc/objc/objc-runtime-shared-support.c
index 16d4d63c86f..78825893ee2 100644
--- a/gcc/objc/objc-runtime-shared-support.c
+++ b/gcc/objc/objc-runtime-shared-support.c
@@ -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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-31 18:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-31 18:32 [gcc r10-10806] [PATCH] Objective-C: NeXT runtime fixes Iain D Sandoe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).