]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: tm.texi.in (TARGET_OBJC_DECLARE_UNRESOLVED_CLASS_REFERENCE, [...]): Add...
authorIain Sandoe <iain@codesourcery.com>
Sun, 1 Sep 2013 19:21:33 +0000 (19:21 +0000)
committerIain Sandoe <iains@gcc.gnu.org>
Sun, 1 Sep 2013 19:21:33 +0000 (19:21 +0000)
backport from 4.8
gcc/
* doc/tm.texi.in (TARGET_OBJC_DECLARE_UNRESOLVED_CLASS_REFERENCE,
TARGET_OBJC_DECLARE_CLASS_DEFINITION): Add @hooks.
(ASM_DECLARE_CLASS_REFERENCE, ASM_DECLARE_UNRESOLVED_REFERENCE):
Remove.
* doc/tm.texi: Regenerate.
* config/darwin.h (ASM_OUTPUT_LABELREF): Remove special case for
.objc_class_name_*.
* config/darwin-c.c: Include target.h.
(darwin_objc_declare_unresolved_class_reference): New function.
(darwin_objc_declare_class_definition): New function.
(TARGET_OBJC_DECLARE_UNRESOLVED_CLASS_REFERENCE): Define.
(TARGET_OBJC_DECLARE_CLASS_DEFINITION): Define.

c-family/
* c-target.def (objc_declare_unresolved_class_reference,
objc_declare_class_definition): Add new hooks.

objc/
* objc-next-runtime-abi-01.c: Do not include tm.h and output.h.
Include c-family/c-target.h.
(handle_next_class_ref): Rewrite to emit top-level asm statements.
(handle_next_impent): Likewise.
* objc/Make-lang.in: Fix dependencies for objc-next-runtime-abi-01.o.

From-SVN: r202155

gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-target.def
gcc/config/darwin-c.c
gcc/config/darwin.h
gcc/doc/tm.texi
gcc/doc/tm.texi.in
gcc/objc/ChangeLog
gcc/objc/Make-lang.in
gcc/objc/objc-next-runtime-abi-01.c

index bffb96151effeea3141d402da17b2bb089e6b37f..072edb46fa0d71df28a861ffc95e1891ea5fd617 100644 (file)
@@ -2,6 +2,24 @@
 
        * config/pa/pa.md: Allow "const 0" operand 1 in "scc" insns.
 
+2013-09-01  Iain Sandoe  <iain@codesourcery.com>
+
+       Backported from 4.8
+       2012-06-19  Steven Bosscher  <steven@gcc.gnu.org>
+
+       * doc/tm.texi.in (TARGET_OBJC_DECLARE_UNRESOLVED_CLASS_REFERENCE,
+       TARGET_OBJC_DECLARE_CLASS_DEFINITION): Add @hooks.
+       (ASM_DECLARE_CLASS_REFERENCE, ASM_DECLARE_UNRESOLVED_REFERENCE):
+       Remove.
+       * doc/tm.texi: Regenerate.
+       * config/darwin.h (ASM_OUTPUT_LABELREF): Remove special case for
+       .objc_class_name_*.
+       * config/darwin-c.c: Include target.h.
+       (darwin_objc_declare_unresolved_class_reference): New function.
+       (darwin_objc_declare_class_definition): New function.
+       (TARGET_OBJC_DECLARE_UNRESOLVED_CLASS_REFERENCE): Define.
+       (TARGET_OBJC_DECLARE_CLASS_DEFINITION): Define.
+
 2013-09-01  Iain Sandoe  <iain@codesourcery.com>
 
        Backport from mainline:
index da704f5cc5952cb39d9cf68da1d938a38f4e8548..f09b3a61f9d607fcd85b8e4bdb794c9a059a6748 100644 (file)
@@ -1,3 +1,11 @@
+2013-09-01  Iain Sandoe  <iain@codesourcery.com>
+
+       Backported from 4.8
+       2012-06-19  Steven Bosscher  <steven@gcc.gnu.org>
+
+       * c-target.def (objc_declare_unresolved_class_reference,
+       objc_declare_class_definition): Add new hooks.
+
 2013-04-11  Release Manager
 
        * GCC 4.7.3 released.
index 356fe26680a92dccdedc61231ca2ac6c3cdd6b82..c5ebdf14ac4445d26b7bca5220ea6415e3c09d10 100644 (file)
@@ -59,7 +59,21 @@ DEFHOOK
  common-format string object when the target provides one.",
  tree, (tree string),
  NULL)
+
+DEFHOOK
+(objc_declare_unresolved_class_reference,
+ "Declare that Objective C class @var{classname} is referenced\
+  by the current TU.",
+ void, (const char *classname),
+ NULL)
+
+DEFHOOK
+(objc_declare_class_definition,
+ "Declare that Objective C class @var{classname} is defined\
+  by the current TU.",
+ void, (const char *classname),
+ NULL)
+
 DEFHOOK
 (string_object_ref_type_p,
  "If a target implements string objects then this hook should return\
index 08de2f8ef6c3f2d2a5bf80c0c4dc962d80ab12c7..211d141a645acddeac6d5d32717e73108212e82d 100644 (file)
@@ -25,6 +25,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tm.h"
 #include "cpplib.h"
 #include "tree.h"
+#include "target.h"
 #include "incpath.h"
 #include "c-family/c-common.h"
 #include "c-family/c-pragma.h"
@@ -36,6 +37,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "prefix.h"
 #include "c-family/c-target.h"
 #include "c-family/c-target-def.h"
+#include "cgraph.h"
 
 /* Pragmas.  */
 
@@ -711,13 +713,60 @@ EXPORTED_CONST format_kind_info darwin_additional_format_types[] = {
   }
 };
 
-#undef TARGET_HANDLE_C_OPTION
+
+/* Support routines to dump the class references for NeXT ABI v1, aka
+   32-bits ObjC-2.0, as top-level asms.
+   The following two functions should only be called from
+   objc/objc-next-runtime-abi-01.c.  */
+
+static void
+darwin_objc_declare_unresolved_class_reference (const char *name)
+{
+  const char *lazy_reference = ".lazy_reference\t";
+  const char *hard_reference = ".reference\t";
+  const char *reference = MACHOPIC_INDIRECT ? lazy_reference : hard_reference;
+  size_t len = strlen (reference) + strlen(name) + 2;
+  char *buf = (char *) alloca (len);
+
+  gcc_checking_assert (!strncmp (name, ".objc_class_name_", 17));
+
+  snprintf (buf, len, "%s%s", reference, name);
+  cgraph_add_asm_node (build_string (strlen (buf), buf));
+}
+
+static void
+darwin_objc_declare_class_definition (const char *name)
+{
+  const char *xname = targetm.strip_name_encoding (name);
+  size_t len = strlen (xname) + 7 + 5;
+  char *buf = (char *) alloca (len);
+
+  gcc_checking_assert (!strncmp (name, ".objc_class_name_", 17)
+                      || !strncmp (name, "*.objc_category_name_", 21));
+
+  /* Mimic default_globalize_label.  */
+  snprintf (buf, len, ".globl\t%s", xname);
+  cgraph_add_asm_node (build_string (strlen (buf), buf));
+
+  snprintf (buf, len, "%s = 0", xname);
+  cgraph_add_asm_node (build_string (strlen (buf), buf));
+}
+
+#undef  TARGET_HANDLE_C_OPTION
 #define TARGET_HANDLE_C_OPTION handle_c_option
 
-#undef TARGET_OBJC_CONSTRUCT_STRING_OBJECT
+#undef  TARGET_OBJC_CONSTRUCT_STRING_OBJECT
 #define TARGET_OBJC_CONSTRUCT_STRING_OBJECT darwin_objc_construct_string
 
-#undef TARGET_STRING_OBJECT_REF_TYPE_P
+#undef  TARGET_OBJC_DECLARE_UNRESOLVED_CLASS_REFERENCE
+#define TARGET_OBJC_DECLARE_UNRESOLVED_CLASS_REFERENCE \
+       darwin_objc_declare_unresolved_class_reference
+
+#undef  TARGET_OBJC_DECLARE_CLASS_DEFINITION
+#define TARGET_OBJC_DECLARE_CLASS_DEFINITION \
+       darwin_objc_declare_class_definition
+
+#undef  TARGET_STRING_OBJECT_REF_TYPE_P
 #define TARGET_STRING_OBJECT_REF_TYPE_P darwin_cfstring_ref_p
 
 #undef TARGET_CHECK_STRING_OBJECT_FORMAT_ARG
index 5855778109d0321e2fcf0ee0cd7bad7bdbd26fc0..6bc7f73f679232ae0acb549c8f088881cdb07588 100644 (file)
@@ -616,8 +616,6 @@ int darwin_label_is_anonymous_local_objc_name (const char *name);
          fprintf (FILE, "\"%s\"", xname);                                   \
        else if (darwin_label_is_anonymous_local_objc_name (xname))          \
          fprintf (FILE, "L%s", xname);                                      \
-       else if (!strncmp (xname, ".objc_class_name_", 17))                  \
-        fprintf (FILE, "%s", xname);                                        \
        else if (xname[0] != '"' && name_needs_quotes (xname))               \
         asm_fprintf (FILE, "\"%U%s\"", xname);                              \
        else                                                                 \
@@ -700,29 +698,6 @@ extern GTY(()) section * darwin_sections[NUM_DARWIN_SECTIONS];
 #undef  TARGET_ASM_RELOC_RW_MASK
 #define TARGET_ASM_RELOC_RW_MASK machopic_reloc_rw_mask
 
-
-#define ASM_DECLARE_UNRESOLVED_REFERENCE(FILE,NAME)                    \
-    do {                                                               \
-        if (FILE) {                                                    \
-          if (MACHOPIC_INDIRECT)                                       \
-            fprintf (FILE, "\t.lazy_reference ");                      \
-          else                                                         \
-            fprintf (FILE, "\t.reference ");                           \
-          assemble_name (FILE, NAME);                                  \
-          fprintf (FILE, "\n");                                        \
-        }                                                              \
-       } while (0)
-
-#define ASM_DECLARE_CLASS_REFERENCE(FILE,NAME)                         \
-    do {                                                               \
-        if (FILE) {                                                    \
-          fprintf (FILE, "\t");                                        \
-          assemble_name (FILE, NAME);                                  \
-          fprintf (FILE, "=0\n");                                      \
-          (*targetm.asm_out.globalize_label) (FILE, NAME);             \
-        }                                                              \
-       } while (0)
-
 /* Globalizing directive for a label.  */
 #define GLOBAL_ASM_OP "\t.globl "
 #define TARGET_ASM_GLOBALIZE_LABEL darwin_globalize_label
index 94016c30b55a7d18632f4967ce0b482c624aa3ae..da9e8397300908f7132dfaf61b14152100a8aab7 100644 (file)
@@ -700,6 +700,14 @@ should use @code{TARGET_HANDLE_C_OPTION} instead.
 Targets may provide a string object type that can be used within and between C, C++ and their respective Objective-C dialects. A string object might, for example, embed encoding and length information. These objects are considered opaque to the compiler and handled as references. An ideal implementation makes the composition of the string object match that of the Objective-C @code{NSString} (@code{NXString} for GNUStep), allowing efficient interworking between C-only and Objective-C code. If a target implements string objects then this hook should return a reference to such an object constructed from the normal `C' string representation provided in @var{string}. At present, the hook is used by Objective-C only, to obtain a common-format string object when the target provides one.
 @end deftypefn
 
+@deftypefn {C Target Hook} void TARGET_OBJC_DECLARE_UNRESOLVED_CLASS_REFERENCE (const char *@var{classname})
+Declare that Objective C class @var{classname} is referenced  by the current TU.
+@end deftypefn
+
+@deftypefn {C Target Hook} void TARGET_OBJC_DECLARE_CLASS_DEFINITION (const char *@var{classname})
+Declare that Objective C class @var{classname} is defined  by the current TU.
+@end deftypefn
+
 @deftypefn {C Target Hook} bool TARGET_STRING_OBJECT_REF_TYPE_P (const_tree @var{stringref})
 If a target implements string objects then this hook should return @code{true} if @var{stringref} is a valid reference to such an object.
 @end deftypefn
@@ -8258,20 +8266,6 @@ On systems where the assembler can handle quoted names, you can use this
 macro to provide more human-readable names.
 @end defmac
 
-@defmac ASM_DECLARE_CLASS_REFERENCE (@var{stream}, @var{name})
-A C statement (sans semicolon) to output to the stdio stream
-@var{stream} commands to declare that the label @var{name} is an
-Objective-C class reference.  This is only needed for targets whose
-linkers have special support for NeXT-style runtimes.
-@end defmac
-
-@defmac ASM_DECLARE_UNRESOLVED_REFERENCE (@var{stream}, @var{name})
-A C statement (sans semicolon) to output to the stdio stream
-@var{stream} commands to declare that the label @var{name} is an
-unresolved Objective-C class reference.  This is only needed for targets
-whose linkers have special support for NeXT-style runtimes.
-@end defmac
-
 @node Initialization
 @subsection How Initialization Functions Are Handled
 @cindex initialization routines
index afb3e441060c21020f8254417cd50cd9a4a8a808..28a6c36cb3fa353157c565f6721e53b444e08d78 100644 (file)
@@ -696,6 +696,10 @@ should use @code{TARGET_HANDLE_C_OPTION} instead.
 
 @hook TARGET_OBJC_CONSTRUCT_STRING_OBJECT
 
+@hook TARGET_OBJC_DECLARE_UNRESOLVED_CLASS_REFERENCE
+
+@hook TARGET_OBJC_DECLARE_CLASS_DEFINITION
+
 @hook TARGET_STRING_OBJECT_REF_TYPE_P
 
 @hook TARGET_CHECK_STRING_OBJECT_FORMAT_ARG
@@ -8157,20 +8161,6 @@ On systems where the assembler can handle quoted names, you can use this
 macro to provide more human-readable names.
 @end defmac
 
-@defmac ASM_DECLARE_CLASS_REFERENCE (@var{stream}, @var{name})
-A C statement (sans semicolon) to output to the stdio stream
-@var{stream} commands to declare that the label @var{name} is an
-Objective-C class reference.  This is only needed for targets whose
-linkers have special support for NeXT-style runtimes.
-@end defmac
-
-@defmac ASM_DECLARE_UNRESOLVED_REFERENCE (@var{stream}, @var{name})
-A C statement (sans semicolon) to output to the stdio stream
-@var{stream} commands to declare that the label @var{name} is an
-unresolved Objective-C class reference.  This is only needed for targets
-whose linkers have special support for NeXT-style runtimes.
-@end defmac
-
 @node Initialization
 @subsection How Initialization Functions Are Handled
 @cindex initialization routines
index 2b7c2b404612c4082f062f376fb90c922957eb37..a2b987bc941dc9bf3d8a02eef7e279fcc174bffe 100644 (file)
@@ -1,3 +1,14 @@
+2013-09-01  Iain Sandoe  <iain@codesourcery.com>
+
+       Backported from 4.8
+       2012-06-19  Steven Bosscher  <steven@gcc.gnu.org>
+
+       * objc-next-runtime-abi-01.c: Do not include tm.h and output.h.
+       Include c-family/c-target.h.
+       (handle_next_class_ref): Rewrite to emit top-level asm statements.
+       (handle_next_impent): Likewise.
+       * objc/Make-lang.in: Fix dependencies for objc-next-runtime-abi-01.o.
+
 2013-04-11  Release Manager
 
        * GCC 4.7.3 released.
index 5cca11a6b4d602524920e288407422dcd830791e..7cc8f84e26c8eece9b0f943ae13b2a2c1901c4c0 100644 (file)
@@ -106,7 +106,7 @@ objc/objc-next-runtime-abi-01.o: objc/objc-next-runtime-abi-01.c \
    gt-objc-objc-next-runtime-abi-01.h \
    $(START_HDRS) \
    $(GGC_H) $(DIAGNOSTIC_CORE_H) $(FLAGS_H) input.h \
-   $(TARGET_H) output.h \
+   $(TARGET_H) \
    objc/objc-encoding.h \
    objc/objc-next-metadata-tags.h \
    objc/objc-runtime-hooks.h \
index 7d6a21256322591b7d5400ceef5a58805d6bcb1c..92bf6135e2b0c9fd368701ef85cb798d84d3bea9 100644 (file)
@@ -26,7 +26,6 @@ along with GCC; see the file COPYING3.  If not see
 #include "config.h"
 #include "system.h"
 #include "coretypes.h"
-#include "tm.h"
 #include "tree.h"
 
 #ifdef OBJCPLUS
@@ -49,7 +48,7 @@ along with GCC; see the file COPYING3.  If not see
 
 #include "ggc.h"
 #include "target.h"
-#include "output.h"
+#include "c-family/c-target.h"
 #include "tree-iterator.h"
 
 #include "objc-runtime-hooks.h"
@@ -2268,47 +2267,50 @@ generate_objc_symtab_decl (void)
                   init_objc_symtab (TREE_TYPE (UOBJC_SYMBOLS_decl)));
 }
 
+/* Any target implementing NeXT ObjC m32 ABI has to ensure that objects
+   refer to, and define, symbols that enforce linkage of classes into the
+   executable image, preserving unix archive semantics.
+
+   At present (4.8), the only targets implementing this are Darwin; these
+   use top level asms to implement a scheme (see config/darwin-c.c).  The
+   latter method is a hack, but compatible with LTO see also PR48109 for
+   further discussion and other possible methods.  */
 
 static void
-handle_next_class_ref (tree chain)
+handle_next_class_ref (tree chain ATTRIBUTE_UNUSED)
 {
-  const char *name = IDENTIFIER_POINTER (TREE_VALUE (chain));
-  char *string = (char *) alloca (strlen (name) + 30);
-
-  sprintf (string, ".objc_class_name_%s", name);
-
-#ifdef ASM_DECLARE_UNRESOLVED_REFERENCE
-  ASM_DECLARE_UNRESOLVED_REFERENCE (asm_out_file, string);
-#else
-  return ; /* NULL build for targets other than Darwin.  */
-#endif
+  if (targetcm.objc_declare_unresolved_class_reference)
+    {
+      const char *name = IDENTIFIER_POINTER (TREE_VALUE (chain));
+      char *string = (char *) alloca (strlen (name) + 30);
+      sprintf (string, ".objc_class_name_%s", name);
+      targetcm.objc_declare_unresolved_class_reference (string);
+    }
 }
 
 static void
-handle_next_impent (struct imp_entry *impent)
+handle_next_impent (struct imp_entry *impent ATTRIBUTE_UNUSED)
 {
-  char buf[BUFSIZE];
-
-  switch (TREE_CODE (impent->imp_context))
+  if (targetcm.objc_declare_class_definition)
     {
-    case CLASS_IMPLEMENTATION_TYPE:
-      snprintf (buf, BUFSIZE, ".objc_class_name_%s",
-               IDENTIFIER_POINTER (CLASS_NAME (impent->imp_context)));
-      break;
-    case CATEGORY_IMPLEMENTATION_TYPE:
-      snprintf (buf, BUFSIZE, "*.objc_category_name_%s_%s",
-               IDENTIFIER_POINTER (CLASS_NAME (impent->imp_context)),
-               IDENTIFIER_POINTER (CLASS_SUPER_NAME (impent->imp_context)));
-      break;
-    default:
-      return;
-    }
+      char buf[BUFSIZE];
 
-#ifdef ASM_DECLARE_CLASS_REFERENCE
-  ASM_DECLARE_CLASS_REFERENCE (asm_out_file, buf);
-#else
-  return ; /* NULL build for targets other than Darwin.  */
-#endif
+      switch (TREE_CODE (impent->imp_context))
+       {
+         case CLASS_IMPLEMENTATION_TYPE:
+           snprintf (buf, BUFSIZE, ".objc_class_name_%s",
+                     IDENTIFIER_POINTER (CLASS_NAME (impent->imp_context)));
+           break;
+         case CATEGORY_IMPLEMENTATION_TYPE:
+           snprintf (buf, BUFSIZE, "*.objc_category_name_%s_%s",
+                     IDENTIFIER_POINTER (CLASS_NAME (impent->imp_context)),
+                     IDENTIFIER_POINTER (CLASS_SUPER_NAME (impent->imp_context)));
+           break;
+         default:
+           return;
+       }
+      targetcm.objc_declare_class_definition (buf);
+    }
 }
 
 static void
@@ -2415,8 +2417,7 @@ objc_generate_v1_next_metadata (void)
 
   /* Dump the class references.  This forces the appropriate classes
      to be linked into the executable image, preserving unix archive
-     semantics.  This can be removed when we move to a more dynamically
-     linked environment.  */
+     semantics.  */
 
   for (chain = cls_ref_chain; chain; chain = TREE_CHAIN (chain))
     {