xref: /netbsd-src/external/gpl3/gcc.old/dist/gcc/config/darwin-c.c (revision 75f6d617e282811cb173c2ccfbf5df0dd71f7045)
1 /* Darwin support needed only by C/C++ frontends.
2    Copyright (C) 2001-2013 Free Software Foundation, Inc.
3    Contributed by Apple Computer Inc.
4 
5 This file is part of GCC.
6 
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
11 
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3.  If not see
19 <http://www.gnu.org/licenses/>.  */
20 
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tm.h"
25 #include "cpplib.h"
26 #include "tree.h"
27 #include "target.h"
28 #include "incpath.h"
29 #include "c-family/c-common.h"
30 #include "c-family/c-pragma.h"
31 #include "c-family/c-format.h"
32 #include "diagnostic-core.h"
33 #include "flags.h"
34 #include "tm_p.h"
35 #include "cppdefault.h"
36 #include "prefix.h"
37 #include "c-family/c-target.h"
38 #include "c-family/c-target-def.h"
39 #include "cgraph.h"
40 #include "../../libcpp/internal.h"
41 
42 /* Pragmas.  */
43 
44 #define BAD(gmsgid) do { warning (OPT_Wpragmas, gmsgid); return; } while (0)
45 #define BAD2(msgid, arg) do { warning (OPT_Wpragmas, msgid, arg); return; } while (0)
46 
47 static bool using_frameworks = false;
48 
49 static const char *find_subframework_header (cpp_reader *pfile, const char *header,
50 					     cpp_dir **dirp);
51 
52 typedef struct align_stack
53 {
54   int alignment;
55   struct align_stack * prev;
56 } align_stack;
57 
58 static struct align_stack * field_align_stack = NULL;
59 
60 /* Maintain a small stack of alignments.  This is similar to pragma
61    pack's stack, but simpler.  */
62 
63 static void
64 push_field_alignment (int bit_alignment)
65 {
66   align_stack *entry = XNEW (align_stack);
67 
68   entry->alignment = maximum_field_alignment;
69   entry->prev = field_align_stack;
70   field_align_stack = entry;
71 
72   maximum_field_alignment = bit_alignment;
73 }
74 
75 static void
76 pop_field_alignment (void)
77 {
78   if (field_align_stack)
79     {
80       align_stack *entry = field_align_stack;
81 
82       maximum_field_alignment = entry->alignment;
83       field_align_stack = entry->prev;
84       free (entry);
85     }
86   else
87     error ("too many #pragma options align=reset");
88 }
89 
90 /* Handlers for Darwin-specific pragmas.  */
91 
92 void
93 darwin_pragma_ignore (cpp_reader *pfile ATTRIBUTE_UNUSED)
94 {
95   /* Do nothing.  */
96 }
97 
98 /* #pragma options align={mac68k|power|reset} */
99 
100 void
101 darwin_pragma_options (cpp_reader *pfile ATTRIBUTE_UNUSED)
102 {
103   const char *arg;
104   tree t, x;
105 
106   if (pragma_lex (&t) != CPP_NAME)
107     BAD ("malformed '#pragma options', ignoring");
108   arg = IDENTIFIER_POINTER (t);
109   if (strcmp (arg, "align"))
110     BAD ("malformed '#pragma options', ignoring");
111   if (pragma_lex (&t) != CPP_EQ)
112     BAD ("malformed '#pragma options', ignoring");
113   if (pragma_lex (&t) != CPP_NAME)
114     BAD ("malformed '#pragma options', ignoring");
115 
116   if (pragma_lex (&x) != CPP_EOF)
117     warning (OPT_Wpragmas, "junk at end of '#pragma options'");
118 
119   arg = IDENTIFIER_POINTER (t);
120   if (!strcmp (arg, "mac68k"))
121     push_field_alignment (16);
122   else if (!strcmp (arg, "power"))
123     push_field_alignment (0);
124   else if (!strcmp (arg, "reset"))
125     pop_field_alignment ();
126   else
127     BAD ("malformed '#pragma options align={mac68k|power|reset}', ignoring");
128 }
129 
130 /* #pragma unused ([var {, var}*]) */
131 
132 void
133 darwin_pragma_unused (cpp_reader *pfile ATTRIBUTE_UNUSED)
134 {
135   tree decl, x;
136   int tok;
137 
138   if (pragma_lex (&x) != CPP_OPEN_PAREN)
139     BAD ("missing '(' after '#pragma unused', ignoring");
140 
141   while (1)
142     {
143       tok = pragma_lex (&decl);
144       if (tok == CPP_NAME && decl)
145 	{
146 	  tree local = lookup_name (decl);
147 	  if (local && (TREE_CODE (local) == PARM_DECL
148 			|| TREE_CODE (local) == VAR_DECL))
149 	    {
150 	      TREE_USED (local) = 1;
151 	      DECL_READ_P (local) = 1;
152 	    }
153 	  tok = pragma_lex (&x);
154 	  if (tok != CPP_COMMA)
155 	    break;
156 	}
157     }
158 
159   if (tok != CPP_CLOSE_PAREN)
160     BAD ("missing ')' after '#pragma unused', ignoring");
161 
162   if (pragma_lex (&x) != CPP_EOF)
163     BAD ("junk at end of '#pragma unused'");
164 }
165 
166 /* Parse the ms_struct pragma.  */
167 void
168 darwin_pragma_ms_struct (cpp_reader *pfile ATTRIBUTE_UNUSED)
169 {
170   const char *arg;
171   tree t;
172 
173   if (pragma_lex (&t) != CPP_NAME)
174     BAD ("malformed '#pragma ms_struct', ignoring");
175   arg = IDENTIFIER_POINTER (t);
176 
177   if (!strcmp (arg, "on"))
178     darwin_ms_struct = true;
179   else if (!strcmp (arg, "off") || !strcmp (arg, "reset"))
180     darwin_ms_struct = false;
181   else
182     BAD ("malformed '#pragma ms_struct {on|off|reset}', ignoring");
183 
184   if (pragma_lex (&t) != CPP_EOF)
185     BAD ("junk at end of '#pragma ms_struct'");
186 }
187 
188 static struct frameworks_in_use {
189   size_t len;
190   const char *name;
191   cpp_dir* dir;
192 } *frameworks_in_use;
193 static int num_frameworks = 0;
194 static int max_frameworks = 0;
195 
196 
197 /* Remember which frameworks have been seen, so that we can ensure
198    that all uses of that framework come from the same framework.  DIR
199    is the place where the named framework NAME, which is of length
200    LEN, was found.  We copy the directory name from NAME, as it will be
201    freed by others.  */
202 
203 static void
204 add_framework (const char *name, size_t len, cpp_dir *dir)
205 {
206   char *dir_name;
207   int i;
208   for (i = 0; i < num_frameworks; ++i)
209     {
210       if (len == frameworks_in_use[i].len
211 	  && strncmp (name, frameworks_in_use[i].name, len) == 0)
212 	{
213 	  return;
214 	}
215     }
216   if (i >= max_frameworks)
217     {
218       max_frameworks = i*2;
219       max_frameworks += i == 0;
220       frameworks_in_use = XRESIZEVEC (struct frameworks_in_use,
221 				      frameworks_in_use, max_frameworks);
222     }
223   dir_name = XNEWVEC (char, len + 1);
224   memcpy (dir_name, name, len);
225   dir_name[len] = '\0';
226   frameworks_in_use[num_frameworks].name = dir_name;
227   frameworks_in_use[num_frameworks].len = len;
228   frameworks_in_use[num_frameworks].dir = dir;
229   ++num_frameworks;
230 }
231 
232 /* Recall if we have seen the named framework NAME, before, and where
233    we saw it.  NAME is LEN bytes long.  The return value is the place
234    where it was seen before.  */
235 
236 static struct cpp_dir*
237 find_framework (const char *name, size_t len)
238 {
239   int i;
240   for (i = 0; i < num_frameworks; ++i)
241     {
242       if (len == frameworks_in_use[i].len
243 	  && strncmp (name, frameworks_in_use[i].name, len) == 0)
244 	{
245 	  return frameworks_in_use[i].dir;
246 	}
247     }
248   return 0;
249 }
250 
251 /* There are two directories in a framework that contain header files,
252    Headers and PrivateHeaders.  We search Headers first as it is more
253    common to upgrade a header from PrivateHeaders to Headers and when
254    that is done, the old one might hang around and be out of data,
255    causing grief.  */
256 
257 struct framework_header {const char * dirName; int dirNameLen; };
258 static struct framework_header framework_header_dirs[] = {
259   { "Headers", 7 },
260   { "PrivateHeaders", 14 },
261   { NULL, 0 }
262 };
263 
264 /* Returns a pointer to a malloced string that contains the real pathname
265    to the file, given the base name and the name.  */
266 
267 static char *
268 framework_construct_pathname (const char *fname, cpp_dir *dir)
269 {
270   const char *buf;
271   size_t fname_len, frname_len;
272   cpp_dir *fast_dir;
273   char *frname;
274   struct stat st;
275   int i;
276 
277   /* Framework names must have a / in them.  */
278   buf = strchr (fname, '/');
279   if (buf)
280     fname_len = buf - fname;
281   else
282     return 0;
283 
284   fast_dir = find_framework (fname, fname_len);
285 
286   /* Framework includes must all come from one framework.  */
287   if (fast_dir && dir != fast_dir)
288     return 0;
289 
290   frname = XNEWVEC (char, strlen (fname) + dir->len + 2
291 		    + strlen(".framework/") + strlen("PrivateHeaders"));
292   strncpy (&frname[0], dir->name, dir->len);
293   frname_len = dir->len;
294   if (frname_len && frname[frname_len-1] != '/')
295     frname[frname_len++] = '/';
296   strncpy (&frname[frname_len], fname, fname_len);
297   frname_len += fname_len;
298   strncpy (&frname[frname_len], ".framework/", strlen (".framework/"));
299   frname_len += strlen (".framework/");
300 
301   if (fast_dir == 0)
302     {
303       frname[frname_len-1] = 0;
304       if (stat (frname, &st) == 0)
305 	{
306 	  /* As soon as we find the first instance of the framework,
307 	     we stop and never use any later instance of that
308 	     framework.  */
309 	  add_framework (fname, fname_len, dir);
310 	}
311       else
312 	{
313 	  /* If we can't find the parent directory, no point looking
314 	     further.  */
315 	  free (frname);
316 	  return 0;
317 	}
318       frname[frname_len-1] = '/';
319     }
320 
321   /* Append framework_header_dirs and header file name */
322   for (i = 0; framework_header_dirs[i].dirName; i++)
323     {
324       strncpy (&frname[frname_len],
325 	       framework_header_dirs[i].dirName,
326 	       framework_header_dirs[i].dirNameLen);
327       strcpy (&frname[frname_len + framework_header_dirs[i].dirNameLen],
328 	      &fname[fname_len]);
329 
330       if (stat (frname, &st) == 0)
331 	return frname;
332     }
333 
334   free (frname);
335   return 0;
336 }
337 
338 /* Search for FNAME in sub-frameworks.  pname is the context that we
339    wish to search in.  Return the path the file was found at,
340    otherwise return 0.  */
341 
342 static const char*
343 find_subframework_file (const char *fname, const char *pname)
344 {
345   char *sfrname;
346   const char *dot_framework = ".framework/";
347   const char *bufptr;
348   int sfrname_len, i, fname_len;
349   struct cpp_dir *fast_dir;
350   static struct cpp_dir subframe_dir;
351   struct stat st;
352 
353   bufptr = strchr (fname, '/');
354 
355   /* Subframework files must have / in the name.  */
356   if (bufptr == 0)
357     return 0;
358 
359   fname_len = bufptr - fname;
360   fast_dir = find_framework (fname, fname_len);
361 
362   /* Sub framework header filename includes parent framework name and
363      header name in the "CarbonCore/OSUtils.h" form. If it does not
364      include slash it is not a sub framework include.  */
365   bufptr = strstr (pname, dot_framework);
366 
367   /* If the parent header is not of any framework, then this header
368      cannot be part of any subframework.  */
369   if (!bufptr)
370     return 0;
371 
372   /* Now translate. For example,                  +- bufptr
373      fname = CarbonCore/OSUtils.h                 |
374      pname = /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h
375      into
376      sfrname = /System/Library/Frameworks/Foundation.framework/Frameworks/CarbonCore.framework/Headers/OSUtils.h */
377 
378   sfrname = XNEWVEC (char, strlen (pname) + strlen (fname) + 2 +
379 			      strlen ("Frameworks/") + strlen (".framework/")
380 			      + strlen ("PrivateHeaders"));
381 
382   bufptr += strlen (dot_framework);
383 
384   sfrname_len = bufptr - pname;
385 
386   strncpy (&sfrname[0], pname, sfrname_len);
387 
388   strncpy (&sfrname[sfrname_len], "Frameworks/", strlen ("Frameworks/"));
389   sfrname_len += strlen("Frameworks/");
390 
391   strncpy (&sfrname[sfrname_len], fname, fname_len);
392   sfrname_len += fname_len;
393 
394   strncpy (&sfrname[sfrname_len], ".framework/", strlen (".framework/"));
395   sfrname_len += strlen (".framework/");
396 
397   /* Append framework_header_dirs and header file name */
398   for (i = 0; framework_header_dirs[i].dirName; i++)
399     {
400       strncpy (&sfrname[sfrname_len],
401 	       framework_header_dirs[i].dirName,
402 	       framework_header_dirs[i].dirNameLen);
403       strcpy (&sfrname[sfrname_len + framework_header_dirs[i].dirNameLen],
404 	      &fname[fname_len]);
405 
406       if (stat (sfrname, &st) == 0)
407 	{
408 	  if (fast_dir != &subframe_dir)
409 	    {
410 	      if (fast_dir)
411 		warning (0, "subframework include %s conflicts with framework include",
412 			 fname);
413 	      else
414 		add_framework (fname, fname_len, &subframe_dir);
415 	    }
416 
417 	  return sfrname;
418 	}
419     }
420   free (sfrname);
421 
422   return 0;
423 }
424 
425 /* Add PATH to the system includes. PATH must be malloc-ed and
426    NUL-terminated.  System framework paths are C++ aware.  */
427 
428 static void
429 add_system_framework_path (char *path)
430 {
431   int cxx_aware = 1;
432   cpp_dir *p;
433 
434   p = XNEW (cpp_dir);
435   p->next = NULL;
436   p->name = path;
437   p->sysp = 1 + !cxx_aware;
438   p->construct = framework_construct_pathname;
439   using_frameworks = 1;
440 
441   add_cpp_dir_path (p, SYSTEM);
442 }
443 
444 /* Add PATH to the bracket includes. PATH must be malloc-ed and
445    NUL-terminated.  */
446 
447 void
448 add_framework_path (char *path)
449 {
450   cpp_dir *p;
451 
452   p = XNEW (cpp_dir);
453   p->next = NULL;
454   p->name = path;
455   p->sysp = 0;
456   p->construct = framework_construct_pathname;
457   using_frameworks = 1;
458 
459   add_cpp_dir_path (p, BRACKET);
460 }
461 
462 static const char *framework_defaults [] =
463   {
464     "/System/Library/Frameworks",
465     "/Library/Frameworks",
466   };
467 
468 /* Register the GNU objective-C runtime include path if STDINC.  */
469 
470 void
471 darwin_register_objc_includes (const char *sysroot, const char *iprefix,
472 			       int stdinc)
473 {
474   const char *fname;
475   size_t len;
476   /* We do not do anything if we do not want the standard includes. */
477   if (!stdinc)
478     return;
479 
480   fname = GCC_INCLUDE_DIR "-gnu-runtime";
481 
482   /* Register the GNU OBJC runtime include path if we are compiling  OBJC
483     with GNU-runtime.  */
484 
485   if (c_dialect_objc () && !flag_next_runtime)
486     {
487       char *str;
488       /* See if our directory starts with the standard prefix.
489 	 "Translate" them, i.e. replace /usr/local/lib/gcc... with
490 	 IPREFIX and search them first.  */
491       if (iprefix && (len = cpp_GCC_INCLUDE_DIR_len) != 0 && !sysroot
492 	  && !strncmp (fname, cpp_GCC_INCLUDE_DIR, len))
493 	{
494 	  str = concat (iprefix, fname + len, NULL);
495           /* FIXME: wrap the headers for C++awareness.  */
496 	  add_path (str, SYSTEM, /*c++aware=*/false, false);
497 	}
498 
499       /* Should this directory start with the sysroot?  */
500       if (sysroot)
501 	str = concat (sysroot, fname, NULL);
502       else
503 	str = update_path (fname, "");
504 
505       add_path (str, SYSTEM, /*c++aware=*/false, false);
506     }
507 }
508 
509 
510 /* Register all the system framework paths if STDINC is true and setup
511    the missing_header callback for subframework searching if any
512    frameworks had been registered.  */
513 
514 void
515 darwin_register_frameworks (const char *sysroot,
516 			    const char *iprefix ATTRIBUTE_UNUSED, int stdinc)
517 {
518   if (stdinc)
519     {
520       size_t i;
521 
522       /* Setup default search path for frameworks.  */
523       for (i=0; i<sizeof (framework_defaults)/sizeof(const char *); ++i)
524 	{
525 	  char *str;
526 	  if (sysroot)
527 	    str = concat (sysroot, xstrdup (framework_defaults [i]), NULL);
528 	  else
529 	    str = xstrdup (framework_defaults[i]);
530 	  /* System Framework headers are cxx aware.  */
531 	  add_system_framework_path (str);
532 	}
533     }
534 
535   if (using_frameworks)
536     cpp_get_callbacks (parse_in)->missing_header = find_subframework_header;
537 }
538 
539 /* Search for HEADER in context dependent way.  The return value is
540    the malloced name of a header to try and open, if any, or NULL
541    otherwise.  This is called after normal header lookup processing
542    fails to find a header.  We search each file in the include stack,
543    using FUNC, starting from the most deeply nested include and
544    finishing with the main input file.  We stop searching when FUNC
545    returns nonzero.  */
546 
547 static const char*
548 find_subframework_header (cpp_reader *pfile, const char *header, cpp_dir **dirp)
549 {
550   const char *fname = header;
551   struct cpp_buffer *b;
552   const char *n;
553 
554   for (b = cpp_get_buffer (pfile);
555        b && cpp_get_file (b) && cpp_get_path (cpp_get_file (b));
556        b = cpp_get_prev (b))
557     {
558       n = find_subframework_file (fname, cpp_get_path (cpp_get_file (b)));
559       if (n)
560 	{
561 	  /* Logically, the place where we found the subframework is
562 	     the place where we found the Framework that contains the
563 	     subframework.  This is useful for tracking wether or not
564 	     we are in a system header.  */
565 	  *dirp = cpp_get_dir (cpp_get_file (b));
566 	  return n;
567 	}
568     }
569 
570   return 0;
571 }
572 
573 /* Return the value of darwin_macosx_version_min suitable for the
574    __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ macro, so '10.4.2'
575    becomes 1040 and '10.10.0' becomes 101000.  The lowest digit is
576    always zero, as is the second lowest for '10.10.x' and above.
577    Print a warning if the version number can't be understood.  */
578 static const char *
579 version_as_macro (void)
580 {
581   static char result[7] = "1000";
582   int minorDigitIdx;
583 
584   if (strncmp (darwin_macosx_version_min, "10.", 3) != 0)
585     goto fail;
586   if (! ISDIGIT (darwin_macosx_version_min[3]))
587     goto fail;
588 
589   minorDigitIdx = 3;
590   result[2] = darwin_macosx_version_min[minorDigitIdx++];
591   if (ISDIGIT (darwin_macosx_version_min[minorDigitIdx]))
592   {
593     /* Starting with OS X 10.10, the macro ends '00' rather than '0',
594        i.e. 10.10.x becomes 101000 rather than 10100.  */
595     result[3] = darwin_macosx_version_min[minorDigitIdx++];
596     result[4] = '0';
597     result[5] = '0';
598     result[6] = '\0';
599   }
600   if (darwin_macosx_version_min[minorDigitIdx] != '\0'
601       && darwin_macosx_version_min[minorDigitIdx] != '.')
602     goto fail;
603 
604   return result;
605 
606  fail:
607   error ("unknown value %qs of -mmacosx-version-min",
608 	 darwin_macosx_version_min);
609   return "1000";
610 }
611 
612 /* Define additional CPP flags for Darwin.   */
613 
614 #define builtin_define(TXT) cpp_define (pfile, TXT)
615 
616 void
617 darwin_cpp_builtins (cpp_reader *pfile)
618 {
619   builtin_define ("__MACH__");
620   builtin_define ("__APPLE__");
621 
622   /* __APPLE_CC__ is defined as some old Apple include files expect it
623      to be defined and won't work if it isn't.  */
624   builtin_define_with_value ("__APPLE_CC__", "1", false);
625 
626   if (darwin_constant_cfstrings)
627     builtin_define ("__CONSTANT_CFSTRINGS__");
628 
629   builtin_define_with_value ("__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__",
630 			     version_as_macro(), false);
631 
632   /* Since we do not (at 4.6) support ObjC gc for the NeXT runtime, the
633      following will cause a syntax error if one tries to compile gc attributed
634      items.  However, without this, NeXT system headers cannot be parsed
635      properly (on systems >= darwin 9).  */
636   if (flag_objc_gc)
637     {
638       builtin_define ("__strong=__attribute__((objc_gc(strong)))");
639       builtin_define ("__weak=__attribute__((objc_gc(weak)))");
640       builtin_define ("__OBJC_GC__");
641     }
642   else
643     {
644       builtin_define ("__strong=");
645       builtin_define ("__weak=");
646     }
647 
648   if (CPP_OPTION (pfile, objc) && flag_objc_abi == 2)
649     builtin_define ("__OBJC2__");
650 }
651 
652 /* Handle C family front-end options.  */
653 
654 static bool
655 handle_c_option (size_t code,
656 		 const char *arg,
657 		 int value ATTRIBUTE_UNUSED)
658 {
659   switch (code)
660     {
661     default:
662       /* Unrecognized options that we said we'd handle turn into
663 	 errors if not listed here.  */
664       return false;
665 
666     case OPT_iframework:
667       add_system_framework_path (xstrdup (arg));
668       break;
669 
670     case OPT_fapple_kext:
671       ;
672     }
673 
674   /* We recognized the option.  */
675   return true;
676 }
677 
678 /* Allow ObjC* access to CFStrings.  */
679 static tree
680 darwin_objc_construct_string (tree str)
681 {
682   if (!darwin_constant_cfstrings)
683     {
684     /* Even though we are not using CFStrings, place our literal
685        into the cfstring_htab hash table, so that the
686        darwin_constant_cfstring_p() function will see it.  */
687       darwin_enter_string_into_cfstring_table (str);
688       /* Fall back to NSConstantString.  */
689       return NULL_TREE;
690     }
691 
692   return darwin_build_constant_cfstring (str);
693 }
694 
695 /* The string ref type is created as CFStringRef by <CFBase.h> therefore, we
696    must match for it explicitly, since it's outside the gcc code.  */
697 
698 static bool
699 darwin_cfstring_ref_p (const_tree strp)
700 {
701   tree tn;
702   if (!strp || TREE_CODE (strp) != POINTER_TYPE)
703     return false;
704 
705   tn = TYPE_NAME (strp);
706   if (tn)
707     tn = DECL_NAME (tn);
708   return (tn
709 	  && IDENTIFIER_POINTER (tn)
710 	  && !strncmp (IDENTIFIER_POINTER (tn), "CFStringRef", 8));
711 }
712 
713 /* At present the behavior of this is undefined and it does nothing.  */
714 static void
715 darwin_check_cfstring_format_arg (tree ARG_UNUSED (format_arg),
716 				  tree ARG_UNUSED (args_list))
717 {
718 }
719 
720 /* The extra format types we recognize.  */
721 EXPORTED_CONST format_kind_info darwin_additional_format_types[] = {
722   { "CFString",   NULL,  NULL, NULL, NULL,
723     NULL, NULL,
724     FMT_FLAG_ARG_CONVERT|FMT_FLAG_PARSE_ARG_CONVERT_EXTERNAL, 0, 0, 0, 0, 0, 0,
725     NULL, NULL
726   }
727 };
728 
729 
730 /* Support routines to dump the class references for NeXT ABI v1, aka
731    32-bits ObjC-2.0, as top-level asms.
732    The following two functions should only be called from
733    objc/objc-next-runtime-abi-01.c.  */
734 
735 static void
736 darwin_objc_declare_unresolved_class_reference (const char *name)
737 {
738   const char *lazy_reference = ".lazy_reference\t";
739   const char *hard_reference = ".reference\t";
740   const char *reference = MACHOPIC_INDIRECT ? lazy_reference : hard_reference;
741   size_t len = strlen (reference) + strlen(name) + 2;
742   char *buf = (char *) alloca (len);
743 
744   gcc_checking_assert (!strncmp (name, ".objc_class_name_", 17));
745 
746   snprintf (buf, len, "%s%s", reference, name);
747   add_asm_node (build_string (strlen (buf), buf));
748 }
749 
750 static void
751 darwin_objc_declare_class_definition (const char *name)
752 {
753   const char *xname = targetm.strip_name_encoding (name);
754   size_t len = strlen (xname) + 7 + 5;
755   char *buf = (char *) alloca (len);
756 
757   gcc_checking_assert (!strncmp (name, ".objc_class_name_", 17)
758 		       || !strncmp (name, "*.objc_category_name_", 21));
759 
760   /* Mimic default_globalize_label.  */
761   snprintf (buf, len, ".globl\t%s", xname);
762   add_asm_node (build_string (strlen (buf), buf));
763 
764   snprintf (buf, len, "%s = 0", xname);
765   add_asm_node (build_string (strlen (buf), buf));
766 }
767 
768 #undef  TARGET_HANDLE_C_OPTION
769 #define TARGET_HANDLE_C_OPTION handle_c_option
770 
771 #undef  TARGET_OBJC_CONSTRUCT_STRING_OBJECT
772 #define TARGET_OBJC_CONSTRUCT_STRING_OBJECT darwin_objc_construct_string
773 
774 #undef  TARGET_OBJC_DECLARE_UNRESOLVED_CLASS_REFERENCE
775 #define TARGET_OBJC_DECLARE_UNRESOLVED_CLASS_REFERENCE \
776 	darwin_objc_declare_unresolved_class_reference
777 
778 #undef  TARGET_OBJC_DECLARE_CLASS_DEFINITION
779 #define TARGET_OBJC_DECLARE_CLASS_DEFINITION \
780 	darwin_objc_declare_class_definition
781 
782 #undef  TARGET_STRING_OBJECT_REF_TYPE_P
783 #define TARGET_STRING_OBJECT_REF_TYPE_P darwin_cfstring_ref_p
784 
785 #undef TARGET_CHECK_STRING_OBJECT_FORMAT_ARG
786 #define TARGET_CHECK_STRING_OBJECT_FORMAT_ARG darwin_check_cfstring_format_arg
787 
788 struct gcc_targetcm targetcm = TARGETCM_INITIALIZER;
789