freebsd.h revision 95349
1/* Definitions for Intel 386 running FreeBSD with either a.out or ELF format
2   Copyright (C) 1996, 2000, 2002 Free Software Foundation, Inc.
3   Contributed by Eric Youngdale.
4   Modified for stabs-in-ELF by H.J. Lu.
5   Adapted from GNU/Linux version by John Polstra.
6   Added support for generating "old a.out gas" on the fly by Peter Wemm.
7   Continued development by David O'Brien <obrien@freebsd.org>
8
9This file is part of GNU CC.
10
11GNU CC is free software; you can redistribute it and/or modify
12it under the terms of the GNU General Public License as published by
13the Free Software Foundation; either version 2, or (at your option)
14any later version.
15
16GNU CC is distributed in the hope that it will be useful,
17but WITHOUT ANY WARRANTY; without even the implied warranty of
18MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License
22along with GNU CC; see the file COPYING.  If not, write to
23the Free Software Foundation, 59 Temple Place - Suite 330,
24Boston, MA 02111-1307, USA.  */
25
26/* $FreeBSD: head/contrib/gcc/config/i386/freebsd.h 95349 2002-04-24 04:49:34Z obrien $ */
27
28#undef  CPP_PREDEFINES
29#define CPP_PREDEFINES 							\
30  "-Di386 -Acpu(i386) -Amachine(i386)"					\
31  FBSD_CPP_PREDEFINES
32
33#undef  CC1_SPEC
34#define CC1_SPEC "\
35  %{gline:%{!g:%{!g0:%{!g1:%{!g2: -g1}}}}} \
36  %{maout: %{!mno-underscores: %{!munderscores: -munderscores }}}"
37
38#undef  ASM_SPEC
39#define ASM_SPEC	"%{v*: -v} %{maout: %{fpic:-k} %{fPIC:-k}}"
40
41#undef  ASM_FINAL_SPEC
42#define ASM_FINAL_SPEC	"%|"
43
44/* Provide a LINK_SPEC appropriate for FreeBSD.  Here we provide support
45   for the special GCC options -static and -shared, which allow us to
46   link things in one of these three modes by applying the appropriate
47   combinations of options at link-time. We like to support here for
48   as many of the other GNU linker options as possible. But I don't
49   have the time to search for those flags. I am sure how to add
50   support for -soname shared_object_name. H.J.
51
52   When the -shared link option is used a final link is not being
53   done.  */
54
55#undef	LINK_SPEC
56#define LINK_SPEC "\
57 %{p:%e`-p' not supported; use `-pg' and gprof(1)} \
58  %{maout: %{shared:-Bshareable} \
59    %{!shared:%{!nostdlib:%{!r:%{!e*:-e start}}} -dc -dp %{static:-Bstatic} \
60      %{pg:-Bstatic} %{Z}} \
61    %{assert*} %{R*}} \
62  %{!maout: \
63    %{Wl,*:%*} \
64    %{v:-V} \
65    %{assert*} %{R*} %{rpath*} %{defsym*} \
66    %{shared:-Bshareable %{h*} %{soname*}} \
67    %{!shared: \
68      %{!static: \
69	%{rdynamic: -export-dynamic} \
70	%{!dynamic-linker: -dynamic-linker /usr/libexec/ld-elf.so.1}} \
71      %{static:-Bstatic}} \
72    %{symbolic:-Bsymbolic}}"
73
74/* Provide a STARTFILE_SPEC appropriate for FreeBSD.  Here we add the magical
75   crtbegin.o file (see crtstuff.c) which provides part of the support for
76   getting C++ file-scope static object constructed before entering `main'.  */
77
78#undef STARTFILE_SPEC
79#define STARTFILE_SPEC "\
80  %{maout: %{shared:c++rt0.o%s} \
81    %{!shared: \
82      %{pg:gcrt0.o%s}%{!pg: \
83	%{static:scrt0.o%s} \
84	%{!static:crt0.o%s}}}} \
85  %{!maout: \
86    %{!shared: \
87      %{pg:gcrt1.o%s} \
88      %{!pg: \
89	%{p:gcrt1.o%s} \
90	%{!p:crt1.o%s}}} \
91    crti.o%s \
92    %{!shared:crtbegin.o%s} \
93    %{shared:crtbeginS.o%s}}"
94
95/* Provide an ENDFILE_SPEC appropriate for FreeBSD/i386.  Here we tack on our
96   own magical crtend.o file (see crtstuff.c) which provides part of the
97   support for getting C++ file-scope static object constructed before
98   entering `main', followed by the normal "finalizer" file, `crtn.o'.  */
99
100#undef  ENDFILE_SPEC
101#define ENDFILE_SPEC "\
102  %{!maout: \
103    %{!shared:crtend.o%s} \
104    %{shared:crtendS.o%s} crtn.o%s}"
105
106
107/************************[  Target stuff  ]***********************************/
108
109/* Define the actual types of some ANSI-mandated types.
110   Needs to agree with <machine/ansi.h>.  GCC defaults come from c-decl.c,
111   c-common.c, and config/<arch>/<arch>.h.  */
112
113#undef  SIZE_TYPE
114#define SIZE_TYPE	"unsigned int"
115
116#undef  PTRDIFF_TYPE
117#define PTRDIFF_TYPE	"int"
118
119#undef  WCHAR_TYPE_SIZE
120#define WCHAR_TYPE_SIZE	BITS_PER_WORD
121
122/* This is the pseudo-op used to generate a 32-bit word of data with a
123   specific value in some section.  */
124
125#undef  INT_ASM_OP
126#define INT_ASM_OP	".long"
127
128/* Biggest alignment supported by the object file format of this
129   machine.  Use this macro to limit the alignment which can be
130   specified using the `__attribute__ ((aligned (N)))' construct.  If
131   not defined, the default value is `BIGGEST_ALIGNMENT'.  */
132
133#define MAX_OFILE_ALIGNMENT (32768*8)
134
135#undef  TARGET_VERSION
136#define TARGET_VERSION	fprintf (stderr, " (i386 FreeBSD/ELF)");
137
138#define MASK_PROFILER_EPILOGUE	010000000000
139#define MASK_AOUT		004000000000	/* a.out not elf */
140#define MASK_UNDERSCORES	002000000000	/* use leading _ */
141
142#define TARGET_PROFILER_EPILOGUE	(target_flags & MASK_PROFILER_EPILOGUE)
143#define TARGET_AOUT			(target_flags & MASK_AOUT)
144#define TARGET_ELF			((target_flags & MASK_AOUT) == 0)
145#define TARGET_UNDERSCORES		((target_flags & MASK_UNDERSCORES) != 0)
146
147#undef	SUBTARGET_SWITCHES
148#define SUBTARGET_SWITCHES						\
149  { "profiler-epilogue",	 MASK_PROFILER_EPILOGUE, "Function profiler epilogue"}, \
150  { "no-profiler-epilogue",	-MASK_PROFILER_EPILOGUE, "No function profiler epilogue"}, \
151  { "aout",			 MASK_AOUT, "Generate an a.out (vs. ELF) binary"}, \
152  { "no-aout",			-MASK_AOUT, "Do not generate an a.out binary"}, \
153  { "underscores",		 MASK_UNDERSCORES, "Add leading underscores to symbols"}, \
154  { "no-underscores",		-MASK_UNDERSCORES, "Do not add leading underscores to symbols"},
155
156/* This goes away when the math emulator is fixed.  */
157#undef  TARGET_DEFAULT
158#define TARGET_DEFAULT \
159  (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_NO_FANCY_MATH_387)
160
161/* Don't default to pcc-struct-return, we want to retain compatibility with
162   older gcc versions AND pcc-struct-return is nonreentrant.
163   (even though the SVR4 ABI for the i386 says that records and unions are
164   returned in memory).  */
165
166#undef  DEFAULT_PCC_STRUCT_RETURN
167#define DEFAULT_PCC_STRUCT_RETURN 0
168
169/* The a.out tools do not support "linkonce" sections. */
170#undef  SUPPORTS_ONE_ONLY
171#define SUPPORTS_ONE_ONLY	TARGET_ELF
172
173/* Prefix for internally generated assembler labels.  If we aren't using
174   underscores, we are using prefix `.'s to identify labels that should
175   be ignored, as in `i386/gas.h' --karl@cs.umb.edu  */
176#undef  LPREFIX
177#define LPREFIX ((TARGET_UNDERSCORES) ? "L" : ".L")
178
179/* supply our own hook for calling __main() from main() */
180#undef  INVOKE__main
181#define INVOKE__main
182#undef  GEN_CALL__MAIN
183#define GEN_CALL__MAIN							\
184  do {									\
185    if (!(TARGET_ELF))							\
186      emit_library_call (gen_rtx (SYMBOL_REF, Pmode, NAME__MAIN), 0,	\
187			 VOIDmode, 0);					\
188  } while (0)
189
190/* Indicate that jump tables go in the text section.  This is
191   necessary when compiling PIC code.  */
192#undef  JUMP_TABLES_IN_TEXT_SECTION
193#define JUMP_TABLES_IN_TEXT_SECTION	(flag_pic)
194
195/* override the exception table positioning */
196#undef  EXCEPTION_SECTION
197#define EXCEPTION_SECTION() \
198  do {									\
199    if (TARGET_ELF)							\
200      {									\
201	named_section (NULL_TREE, ".gcc_except_table", 0);		\
202      }									\
203    else								\
204      {									\
205	if (flag_pic)							\
206	  data_section ();						\
207	else								\
208	  readonly_data_section ();					\
209      }									\
210  } while (0);
211
212/* Tell final.c that we don't need a label passed to mcount.  */
213#undef  NO_PROFILE_COUNTERS
214#define NO_PROFILE_COUNTERS
215
216/* Output assembler code to FILE to begin profiling of the current function.
217   LABELNO is an optional label.  */
218
219#undef  FUNCTION_PROFILER
220#define FUNCTION_PROFILER(FILE, LABELNO)  \
221  do {									\
222    char *_name = TARGET_AOUT ? "mcount" : ".mcount";			\
223    if (flag_pic)							\
224      fprintf ((FILE), "\tcall *%s@GOT(%%ebx)\n", _name);		\
225    else								\
226      fprintf ((FILE), "\tcall %s\n", _name);				\
227  } while (0)
228
229/* Output assembler code to FILE to end profiling of the current function.  */
230
231#undef  FUNCTION_PROFILER_EPILOGUE
232#define FUNCTION_PROFILER_EPILOGUE(FILE, DO_RTL)			\
233  do {									\
234    if (TARGET_PROFILER_EPILOGUE)					\
235      {									\
236	if (DO_RTL)							\
237	  {								\
238	  /* ".mexitcount" is specially handled in			\
239	     ASM_HACK_SYMBOLREF () so that we don't need to handle	\
240	     flag_pic or TARGET_AOUT here.  */				\
241	    rtx xop;							\
242	    xop = gen_rtx_MEM (FUNCTION_MODE,				\
243			    gen_rtx_SYMBOL_REF (Pmode, ".mexitcount"));	\
244	    emit_call_insn (gen_rtx (CALL, VOIDmode, xop, const0_rtx));	\
245	  }								\
246	else								\
247	  {								\
248	  /* XXX this !DO_RTL case is broken but not actually used.  */	\
249	    char *_name = TARGET_AOUT ? "mcount" : ".mcount";		\
250	    if (flag_pic)						\
251	      fprintf (FILE, "\tcall *%s@GOT(%%ebx)\n", _name);		\
252	    else							\
253	      fprintf (FILE, "\tcall %s\n", _name);			\
254	  }								\
255      }									\
256  } while (0)
257
258
259/************************[  Assembler stuff  ]********************************/
260
261/* Override the default comment-starter of "/" from unix.h.  */
262#undef  ASM_COMMENT_START
263#define ASM_COMMENT_START "#"
264
265#undef  ASM_APP_ON
266#define ASM_APP_ON	"#APP\n"
267
268#undef  ASM_APP_OFF
269#define ASM_APP_OFF	"#NO_APP\n"
270
271/* Enable alias attribute support.  */
272#undef  SET_ASM_OP
273#define SET_ASM_OP	".set"
274
275/* This is how to begin an assembly language file.
276   The .file command should always begin the output.
277   ELF also needs a .version.  */
278
279#undef  ASM_FILE_START
280#define ASM_FILE_START(FILE)						\
281  do {									\
282    output_file_directive ((FILE), main_input_filename);		\
283    if (TARGET_ELF)							\
284      fprintf ((FILE), "\t.version\t\"01.01\"\n");			\
285  } while (0)
286
287/* This is how to store into the string BUF
288   the symbol_ref name of an internal numbered label where
289   PREFIX is the class of label and NUM is the number within the class.
290   This is suitable for output with `assemble_name'.  */
291#undef	ASM_GENERATE_INTERNAL_LABEL
292#define ASM_GENERATE_INTERNAL_LABEL(BUF, PREFIX, NUMBER)		\
293  sprintf ((BUF), "*%s%s%d", (TARGET_UNDERSCORES) ? "" : ".",		\
294	   (PREFIX), (NUMBER))
295
296/* This is how to output an internal numbered label where
297   PREFIX is the class of label and NUM is the number within the class.
298   For most svr4/ELF systems, the convention is that any symbol which begins
299   with a period is not put into the linker symbol table by the assembler.  */
300#undef	ASM_OUTPUT_INTERNAL_LABEL
301#define	ASM_OUTPUT_INTERNAL_LABEL(FILE,PREFIX,NUM)			\
302  fprintf ((FILE), "%s%s%d:\n", (TARGET_UNDERSCORES) ? "" : ".",	\
303	   (PREFIX), (NUM))
304
305/* This is how to output a reference to a user-level label named NAME.  */
306#undef  ASM_OUTPUT_LABELREF
307#define ASM_OUTPUT_LABELREF(FILE, NAME)					\
308  do {									\
309    char *_name = (NAME);						\
310    /* Hack to avoid writing lots of rtl in				\
311       FUNCTION_PROFILER_EPILOGUE ().  */				\
312    if (*_name == '.' && strcmp(_name + 1, "mexitcount") == 0)		\
313      {									\
314	if (TARGET_AOUT)						\
315	  _name++;							\
316	if (flag_pic)							\
317	  fprintf ((FILE), "*%s@GOT(%%ebx)", _name);			\
318	else								\
319	  fprintf ((FILE), "%s", _name);				\
320      }									\
321    else								\
322      fprintf (FILE, "%s%s", TARGET_UNDERSCORES ? "_" : "", _name);	\
323} while (0)
324
325/* This is how to hack on the symbol code of certain relcalcitrant
326   symbols to modify their output in output_pic_addr_const ().  */
327
328#undef  ASM_HACK_SYMBOLREF_CODE
329#define ASM_HACK_SYMBOLREF_CODE(NAME, CODE)				\
330  do {									\
331    /* Part of hack to avoid writing lots of rtl in			\
332       FUNCTION_PROFILER_EPILOGUE ().  */				\
333    char *_name = (NAME);						\
334    if (*_name == '.' && strcmp(_name + 1, "mexitcount") == 0)		\
335      (CODE) = 'X';							\
336  } while (0)
337
338/* This is how to output an element of a case-vector that is relative.
339   This is only used for PIC code.  See comments by the `casesi' insn in
340   i386.md for an explanation of the expression this outputs. */
341#undef  ASM_OUTPUT_ADDR_DIFF_ELT
342#define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, BODY, VALUE, REL)		\
343  fprintf ((FILE), "\t.long _GLOBAL_OFFSET_TABLE_+[.-%s%d]\n", LPREFIX, (VALUE))
344
345#undef  ASM_OUTPUT_ALIGN
346#define ASM_OUTPUT_ALIGN(FILE, LOG)      				\
347  if ((LOG)!=0) {							\
348    if (in_text_section())						\
349      fprintf ((FILE), "\t.p2align %d,0x90\n", (LOG));			\
350    else								\
351      fprintf ((FILE), "\t.p2align %d\n", (LOG));			\
352  }
353
354#undef  ASM_OUTPUT_ALIGNED_COMMON
355#define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN)		\
356  do {									\
357    if (TARGET_ELF)							\
358      {									\
359	fprintf ((FILE), "%s", COMMON_ASM_OP);				\
360	assemble_name ((FILE), (NAME));					\
361	fprintf ((FILE), ",%u,%u\n", (SIZE), (ALIGN) / BITS_PER_UNIT);	\
362      }									\
363    else								\
364      {									\
365	int rounded = (SIZE);						\
366	if (rounded == 0) rounded = 1;					\
367	rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;		\
368	rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)	\
369		   * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));		\
370	fprintf ((FILE), "%s ", COMMON_ASM_OP);				\
371	assemble_name ((FILE), (NAME));					\
372	fprintf ((FILE), ",%u\n", (rounded));				\
373      }									\
374  } while (0)
375
376/* This says how to output assembler code to declare an
377   uninitialized internal linkage data object.  Under SVR4,
378   the linker seems to want the alignment of data objects
379   to depend on their types.  We do exactly that here.  */
380
381#undef  ASM_OUTPUT_ALIGNED_LOCAL
382#define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN)		\
383  do {									\
384    if (TARGET_ELF)							\
385      {									\
386	fprintf ((FILE), "%s", LOCAL_ASM_OP);				\
387	assemble_name ((FILE), (NAME));					\
388	fprintf ((FILE), "\n");						\
389	ASM_OUTPUT_ALIGNED_COMMON ((FILE), (NAME), (SIZE), (ALIGN));	\
390      }									\
391    else								\
392      {									\
393	int rounded = (SIZE);						\
394	if (rounded == 0) rounded = 1;					\
395	rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;		\
396	rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)	\
397		   * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));		\
398	fputs ("\t.lcomm\t", (FILE));					\
399	assemble_name ((FILE), (NAME));					\
400	fprintf ((FILE), ",%u\n", (rounded));				\
401      }									\
402  } while (0)
403
404/* How to output some space.  The rules are different depending on the
405   object format.  */
406#undef  ASM_OUTPUT_SKIP
407#define ASM_OUTPUT_SKIP(FILE, SIZE) 					\
408  do {									\
409    if (TARGET_ELF)							\
410      {									\
411        fprintf ((FILE), "%s%u\n", SKIP_ASM_OP, (SIZE));		\
412      }									\
413    else								\
414      {									\
415        fprintf ((FILE), "\t.space\t%u\n", (SIZE));			\
416      }									\
417  } while (0)
418
419#undef  ASM_OUTPUT_SOURCE_LINE
420#define ASM_OUTPUT_SOURCE_LINE(FILE, LINE)				\
421  do {									\
422    static int sym_lineno = 1;						\
423    if (TARGET_ELF)							\
424      {									\
425	fprintf ((FILE), ".stabn 68,0,%d,.LM%d-", (LINE), sym_lineno);	\
426	assemble_name ((FILE), 						\
427		XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));	\
428	fprintf ((FILE), "\n.LM%d:\n", sym_lineno);			\
429	sym_lineno += 1;						\
430      }									\
431    else								\
432      {									\
433	fprintf ((FILE), "\t%s %d,0,%d\n", ASM_STABD_OP, N_SLINE,	\
434		lineno);						\
435      }									\
436  } while (0)
437
438/* These macros generate the special .type and .size directives which
439   are used to set the corresponding fields of the linker symbol table
440   entries in an ELF object file under SVR4.  These macros also output
441   the starting labels for the relevant functions/objects.  */
442
443/* Write the extra assembler code needed to declare a function properly.
444   Some svr4 assemblers need to also have something extra said about the
445   function's return value.  We allow for that here.  */
446
447#undef  ASM_DECLARE_FUNCTION_NAME
448#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)			\
449  do {									\
450    fprintf (FILE, "\t%s\t ", TYPE_ASM_OP);				\
451    assemble_name (FILE, NAME);						\
452    putc (',', FILE);							\
453    fprintf (FILE, TYPE_OPERAND_FMT, "function");			\
454    putc ('\n', FILE);							\
455    ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL));			\
456    ASM_OUTPUT_LABEL(FILE, NAME);					\
457  } while (0)
458
459/* This is how to declare the size of a function.  */
460
461#undef  ASM_DECLARE_FUNCTION_SIZE
462#define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)			\
463  do {									\
464    if (!flag_inhibit_size_directive)					\
465      {									\
466        char label[256];						\
467	static int labelno;						\
468	labelno++;							\
469	ASM_GENERATE_INTERNAL_LABEL (label, "Lfe", labelno);		\
470	ASM_OUTPUT_INTERNAL_LABEL (FILE, "Lfe", labelno);		\
471	fprintf (FILE, "\t%s\t ", SIZE_ASM_OP);				\
472	assemble_name (FILE, (FNAME));					\
473        fprintf (FILE, ",");						\
474	assemble_name (FILE, label);					\
475        fprintf (FILE, "-");						\
476	assemble_name (FILE, (FNAME));					\
477	putc ('\n', FILE);						\
478      }									\
479  } while (0)
480
481
482/* The routine used to output NUL terminated strings.  We use a special
483   version of this for most svr4 targets because doing so makes the
484   generated assembly code more compact (and thus faster to assemble)
485   as well as more readable, especially for targets like the i386
486   (where the only alternative is to output character sequences as
487   comma separated lists of numbers).   */
488
489#undef  ASM_OUTPUT_LIMITED_STRING
490#define ASM_OUTPUT_LIMITED_STRING(FILE, STR)				\
491  do {									\
492      register unsigned char *_limited_str = (unsigned char *) (STR);	\
493      register unsigned ch;						\
494      fprintf ((FILE), "\t%s\t\"", STRING_ASM_OP);			\
495      for (; (ch = *_limited_str); _limited_str++)			\
496        {								\
497	  register int escape;						\
498	  switch (escape = ESCAPES[ch])					\
499	    {								\
500	    case 0:							\
501	      putc (ch, (FILE));					\
502	      break;							\
503	    case 1:							\
504	      fprintf ((FILE), "\\%03o", ch);				\
505	      break;							\
506	    default:							\
507	      putc ('\\', (FILE));					\
508	      putc (escape, (FILE));					\
509	      break;							\
510	    }								\
511        }								\
512      fprintf ((FILE), "\"\n");						\
513  } while (0)
514
515/* Switch into a generic section.
516
517   We make the section read-only and executable for a function decl,
518   read-only for a const data decl, and writable for a non-const data decl.
519
520   If the section has already been defined, we must not
521   emit the attributes here. The SVR4 assembler does not
522   recognize section redefinitions.
523   If DECL is NULL, no attributes are emitted.  */
524
525#undef  ASM_OUTPUT_SECTION_NAME
526#define ASM_OUTPUT_SECTION_NAME(FILE, DECL, NAME, RELOC)		\
527  do {									\
528    static struct section_info						\
529      {									\
530	struct section_info *next;				        \
531	char *name;						        \
532	enum sect_enum {SECT_RW, SECT_RO, SECT_EXEC} type;		\
533      } *sections;							\
534    struct section_info *s;						\
535    char *mode;								\
536    enum sect_enum type;						\
537									\
538    for (s = sections; s; s = s->next)					\
539      if (!strcmp (NAME, s->name))					\
540	break;								\
541									\
542    if (DECL && TREE_CODE (DECL) == FUNCTION_DECL)			\
543      type = SECT_EXEC, mode = "ax";					\
544    else if (DECL && DECL_READONLY_SECTION (DECL, RELOC))		\
545      type = SECT_RO, mode = "a";					\
546    else								\
547      type = SECT_RW, mode = "aw";					\
548									\
549    if (s == 0)								\
550      {									\
551	s = (struct section_info *) xmalloc (sizeof (struct section_info));  \
552	s->name = xmalloc ((strlen (NAME) + 1) * sizeof (*NAME));	\
553	strcpy (s->name, NAME);						\
554	s->type = type;							\
555	s->next = sections;						\
556	sections = s;							\
557	fprintf (FILE, ".section\t%s,\"%s\",@progbits\n", NAME, mode);	\
558      }									\
559    else								\
560      {									\
561	if (DECL && s->type != type)					\
562	  error_with_decl (DECL, "%s causes a section type conflict");	\
563									\
564	fprintf (FILE, ".section\t%s\n", NAME);				\
565      }									\
566  } while (0)
567
568#undef  MAKE_DECL_ONE_ONLY
569#define MAKE_DECL_ONE_ONLY(DECL)	(DECL_WEAK (DECL) = 1)
570#undef  UNIQUE_SECTION_P
571#define UNIQUE_SECTION_P(DECL)		(DECL_ONE_ONLY (DECL))
572#undef  UNIQUE_SECTION
573#define UNIQUE_SECTION(DECL,RELOC)					\
574  do {									\
575    int len;								\
576    char *name, *string, *prefix;					\
577									\
578    name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL));		\
579									\
580    if (! DECL_ONE_ONLY (DECL))						\
581      {									\
582	prefix = ".";                                             	\
583	if (TREE_CODE (DECL) == FUNCTION_DECL)				\
584	  prefix = ".text.";						\
585	else if (DECL_READONLY_SECTION (DECL, RELOC))			\
586	  prefix = ".rodata.";						\
587	else								\
588	  prefix = ".data.";						\
589      }									\
590    else if (TREE_CODE (DECL) == FUNCTION_DECL)				\
591      prefix = ".gnu.linkonce.t.";					\
592    else if (DECL_READONLY_SECTION (DECL, RELOC))			\
593      prefix = ".gnu.linkonce.r.";					\
594    else								\
595      prefix = ".gnu.linkonce.d.";					\
596									\
597    len = strlen (name) + strlen (prefix);				\
598    string = alloca (len + 1);						\
599    sprintf (string, "%s%s", prefix, name);				\
600									\
601    DECL_SECTION_NAME (DECL) = build_string (len, string);		\
602  } while (0)
603
604/* A C statement or statements to switch to the appropriate
605   section for output of DECL.  DECL is either a `VAR_DECL' node
606   or a constant of some sort.  RELOC indicates whether forming
607   the initial value of DECL requires link-time relocations.  */
608
609#undef  SELECT_SECTION
610#define SELECT_SECTION(DECL,RELOC)					\
611  {									\
612    if (flag_pic && RELOC)						\
613      data_section ();							\
614    else if (TREE_CODE (DECL) == STRING_CST)				\
615      {									\
616	if (! flag_writable_strings)					\
617	  const_section ();						\
618	else								\
619	  data_section ();						\
620      }									\
621    else if (TREE_CODE (DECL) == VAR_DECL)				\
622      {									\
623	if (! DECL_READONLY_SECTION (DECL, RELOC))			\
624	  data_section ();						\
625	else								\
626	  const_section ();						\
627      }									\
628    else								\
629      const_section ();							\
630  }
631
632/* A C statement (sans semicolon) to output an element in the table of
633   global constructors.  */
634#undef  ASM_OUTPUT_CONSTRUCTOR
635#define ASM_OUTPUT_CONSTRUCTOR(FILE, NAME)				\
636  do {									\
637    if (TARGET_ELF)							\
638      {									\
639	ctors_section ();						\
640	fprintf ((FILE), "%s ", INT_ASM_OP);				\
641	assemble_name ((FILE), (NAME));					\
642	fprintf ((FILE), "\n");						\
643      }									\
644    else								\
645      {									\
646	fprintf (asm_out_file, "%s \"%s__CTOR_LIST__\",22,0,0,",	\
647		 ASM_STABS_OP, (TARGET_UNDERSCORES) ? "_" : "");	\
648	assemble_name (asm_out_file, name);				\
649	fputc ('\n', asm_out_file);					\
650      }									\
651  } while (0)
652
653/* A C statement (sans semicolon) to output an element in the table of
654   global destructors.  */
655#undef  ASM_OUTPUT_DESTRUCTOR
656#define ASM_OUTPUT_DESTRUCTOR(FILE, NAME)				\
657  do {									\
658    if (TARGET_ELF)							\
659      {									\
660	dtors_section ();						\
661	fprintf ((FILE), "%s ", INT_ASM_OP);				\
662	assemble_name ((FILE), (NAME));					\
663	fprintf ((FILE), "\n");						\
664      }									\
665    else								\
666      {									\
667	fprintf (asm_out_file, "%s \"%s__DTOR_LIST__\",22,0,0,",	\
668		 ASM_STABS_OP, (TARGET_UNDERSCORES) ? "_" : "");	\
669	assemble_name (asm_out_file, name);				\
670	fputc ('\n', asm_out_file);					\
671      }									\
672  } while (0)
673
674/* Define macro used to output shift-double opcodes when the shift
675   count is in %cl.  Some assemblers require %cl as an argument;
676   some don't.
677
678   *OLD* GAS requires the %cl argument, so override i386/unix.h. */
679
680#undef  AS3_SHIFT_DOUBLE
681#define AS3_SHIFT_DOUBLE(a,b,c,d)	AS3 (a,b,c,d)
682
683
684/************************[  Debugger stuff  ]*********************************/
685
686/* The a.out tools do not support "Lscope" .stabs symbols. */
687#undef  NO_DBX_FUNCTION_END
688#define NO_DBX_FUNCTION_END	TARGET_AOUT
689
690/* In ELF, the function stabs come first, before the relative offsets.  */
691#undef  DBX_FUNCTION_FIRST
692#define DBX_CHECK_FUNCTION_FIRST TARGET_ELF
693
694/* Copy this from the svr4 specifications... */
695/* Define the register numbers to be used in Dwarf debugging information.
696   The SVR4 reference port C compiler uses the following register numbers
697   in its Dwarf output code:
698	0 for %eax (gnu regno = 0)
699	1 for %ecx (gnu regno = 2)
700	2 for %edx (gnu regno = 1)
701	3 for %ebx (gnu regno = 3)
702	4 for %esp (gnu regno = 7)
703	5 for %ebp (gnu regno = 6)
704	6 for %esi (gnu regno = 4)
705	7 for %edi (gnu regno = 5)
706   The following three DWARF register numbers are never generated by
707   the SVR4 C compiler or by the GNU compilers, but SDB on x86/svr4
708   believes these numbers have these meanings.
709	8  for %eip    (no gnu equivalent)
710	9  for %eflags (no gnu equivalent)
711	10 for %trapno (no gnu equivalent)
712   It is not at all clear how we should number the FP stack registers
713   for the x86 architecture.  If the version of SDB on x86/svr4 were
714   a bit less brain dead with respect to floating-point then we would
715   have a precedent to follow with respect to DWARF register numbers
716   for x86 FP registers, but the SDB on x86/svr4 is so completely
717   broken with respect to FP registers that it is hardly worth thinking
718   of it as something to strive for compatibility with.
719   The version of x86/svr4 SDB I have at the moment does (partially)
720   seem to believe that DWARF register number 11 is associated with
721   the x86 register %st(0), but that's about all.  Higher DWARF
722   register numbers don't seem to be associated with anything in
723   particular, and even for DWARF regno 11, SDB only seems to under-
724   stand that it should say that a variable lives in %st(0) (when
725   asked via an `=' command) if we said it was in DWARF regno 11,
726   but SDB still prints garbage when asked for the value of the
727   variable in question (via a `/' command).
728   (Also note that the labels SDB prints for various FP stack regs
729   when doing an `x' command are all wrong.)
730   Note that these problems generally don't affect the native SVR4
731   C compiler because it doesn't allow the use of -O with -g and
732   because when it is *not* optimizing, it allocates a memory
733   location for each floating-point variable, and the memory
734   location is what gets described in the DWARF AT_location
735   attribute for the variable in question.
736   Regardless of the severe mental illness of the x86/svr4 SDB, we
737   do something sensible here and we use the following DWARF
738   register numbers.  Note that these are all stack-top-relative
739   numbers.
740	11 for %st(0) (gnu regno = 8)
741	12 for %st(1) (gnu regno = 9)
742	13 for %st(2) (gnu regno = 10)
743	14 for %st(3) (gnu regno = 11)
744	15 for %st(4) (gnu regno = 12)
745	16 for %st(5) (gnu regno = 13)
746	17 for %st(6) (gnu regno = 14)
747	18 for %st(7) (gnu regno = 15)
748*/
749#undef  DWARF_DBX_REGISTER_NUMBER
750#define DWARF_DBX_REGISTER_NUMBER(n) \
751((n) == 0 ? 0 \
752 : (n) == 1 ? 2 \
753 : (n) == 2 ? 1 \
754 : (n) == 3 ? 3 \
755 : (n) == 4 ? 6 \
756 : (n) == 5 ? 7 \
757 : (n) == 6 ? 5 \
758 : (n) == 7 ? 4 \
759 : ((n) >= FIRST_STACK_REG && (n) <= LAST_STACK_REG) ? (n)+3 \
760 : (-1))
761
762/* Now what stabs expects in the register.  */
763#undef  STABS_DBX_REGISTER_NUMBER
764#define STABS_DBX_REGISTER_NUMBER(n) \
765((n) == 0 ? 0 : \
766 (n) == 1 ? 2 : \
767 (n) == 2 ? 1 : \
768 (n) == 3 ? 3 : \
769 (n) == 4 ? 6 : \
770 (n) == 5 ? 7 : \
771 (n) == 6 ? 4 : \
772 (n) == 7 ? 5 : \
773 (n) + 4)
774
775#undef  DBX_REGISTER_NUMBER
776#define DBX_REGISTER_NUMBER(n)	((write_symbols == DWARF2_DEBUG		\
777	    			  || write_symbols == DWARF_DEBUG)	\
778				? DWARF_DBX_REGISTER_NUMBER(n)		\
779				: STABS_DBX_REGISTER_NUMBER(n))
780
781/* tag end of file in elf mode */
782#undef  DBX_OUTPUT_MAIN_SOURCE_FILE_END
783#define DBX_OUTPUT_MAIN_SOURCE_FILE_END(FILE, FILENAME)			\
784  do {									\
785    if (TARGET_ELF) {							\
786      fprintf ((FILE), "\t.text\n\t.stabs \"\",%d,0,0,.Letext\n.Letext:\n", \
787		N_SO);							\
788    }									\
789  } while (0)
790
791/* stabs-in-elf has offsets relative to function beginning */
792#undef  DBX_OUTPUT_LBRAC
793#define DBX_OUTPUT_LBRAC(FILE, NAME)					\
794  do {									\
795    fprintf (asmfile, "%s %d,0,0,", ASM_STABN_OP, N_LBRAC);		\
796    assemble_name (asmfile, buf);					\
797    if (TARGET_ELF)							\
798      {									\
799        fputc ('-', asmfile);						\
800        assemble_name (asmfile,						\
801	      	 XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));	\
802      }									\
803    fprintf (asmfile, "\n");						\
804  } while (0)
805
806#undef  DBX_OUTPUT_RBRAC
807#define DBX_OUTPUT_RBRAC(FILE, NAME)					\
808  do {									\
809    fprintf (asmfile, "%s %d,0,0,", ASM_STABN_OP, N_RBRAC);		\
810    assemble_name (asmfile, buf);					\
811    if (TARGET_ELF)							\
812      {									\
813        fputc ('-', asmfile);						\
814        assemble_name (asmfile,						\
815		 XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));	\
816      }									\
817    fprintf (asmfile, "\n");						\
818  } while (0)
819