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