freebsd.h revision 95348
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 95348 2002-04-24 04:48:00Z 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/* Override the default comment-starter of "/" from unix.h.  */
259#undef  ASM_COMMENT_START
260#define ASM_COMMENT_START "#"
261
262#undef  ASM_APP_ON
263#define ASM_APP_ON	"#APP\n"
264
265#undef  ASM_APP_OFF
266#define ASM_APP_OFF	"#NO_APP\n"
267
268/* This is how to begin an assembly language file.
269   The .file command should always begin the output.
270   ELF also needs a .version.  */
271
272#undef  ASM_FILE_START
273#define ASM_FILE_START(FILE)						\
274  do {									\
275    output_file_directive ((FILE), main_input_filename);		\
276    if (TARGET_ELF)							\
277      fprintf ((FILE), "\t.version\t\"01.01\"\n");			\
278  } while (0)
279
280/* This is how to store into the string BUF
281   the symbol_ref name of an internal numbered label where
282   PREFIX is the class of label and NUM is the number within the class.
283   This is suitable for output with `assemble_name'.  */
284#undef	ASM_GENERATE_INTERNAL_LABEL
285#define ASM_GENERATE_INTERNAL_LABEL(BUF, PREFIX, NUMBER)		\
286  sprintf ((BUF), "*%s%s%d", (TARGET_UNDERSCORES) ? "" : ".",		\
287	   (PREFIX), (NUMBER))
288
289/* This is how to output an internal numbered label where
290   PREFIX is the class of label and NUM is the number within the class.
291   For most svr4/ELF systems, the convention is that any symbol which begins
292   with a period is not put into the linker symbol table by the assembler.  */
293#undef	ASM_OUTPUT_INTERNAL_LABEL
294#define	ASM_OUTPUT_INTERNAL_LABEL(FILE,PREFIX,NUM)			\
295  fprintf ((FILE), "%s%s%d:\n", (TARGET_UNDERSCORES) ? "" : ".",	\
296	   (PREFIX), (NUM))
297
298/* This is how to output a reference to a user-level label named NAME.  */
299#undef  ASM_OUTPUT_LABELREF
300#define ASM_OUTPUT_LABELREF(FILE, NAME)					\
301  do {									\
302    char *_name = (NAME);						\
303    /* Hack to avoid writing lots of rtl in				\
304       FUNCTION_PROFILER_EPILOGUE ().  */				\
305    if (*_name == '.' && strcmp(_name + 1, "mexitcount") == 0)		\
306      {									\
307	if (TARGET_AOUT)						\
308	  _name++;							\
309	if (flag_pic)							\
310	  fprintf ((FILE), "*%s@GOT(%%ebx)", _name);			\
311	else								\
312	  fprintf ((FILE), "%s", _name);				\
313      }									\
314    else								\
315      fprintf (FILE, "%s%s", TARGET_UNDERSCORES ? "_" : "", _name);	\
316} while (0)
317
318/* This is how to hack on the symbol code of certain relcalcitrant
319   symbols to modify their output in output_pic_addr_const ().  */
320
321#undef  ASM_HACK_SYMBOLREF_CODE
322#define ASM_HACK_SYMBOLREF_CODE(NAME, CODE)				\
323  do {									\
324    /* Part of hack to avoid writing lots of rtl in			\
325       FUNCTION_PROFILER_EPILOGUE ().  */				\
326    char *_name = (NAME);						\
327    if (*_name == '.' && strcmp(_name + 1, "mexitcount") == 0)		\
328      (CODE) = 'X';							\
329  } while (0)
330
331/* This is how to output an element of a case-vector that is relative.
332   This is only used for PIC code.  See comments by the `casesi' insn in
333   i386.md for an explanation of the expression this outputs. */
334#undef  ASM_OUTPUT_ADDR_DIFF_ELT
335#define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, BODY, VALUE, REL)		\
336  fprintf ((FILE), "\t.long _GLOBAL_OFFSET_TABLE_+[.-%s%d]\n", LPREFIX, (VALUE))
337
338#undef  ASM_OUTPUT_ALIGN
339#define ASM_OUTPUT_ALIGN(FILE, LOG)      				\
340  if ((LOG)!=0) {							\
341    if (in_text_section())						\
342      fprintf ((FILE), "\t.p2align %d,0x90\n", (LOG));			\
343    else								\
344      fprintf ((FILE), "\t.p2align %d\n", (LOG));			\
345  }
346
347#undef  ASM_OUTPUT_ALIGNED_COMMON
348#define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN)		\
349  do {									\
350    if (TARGET_ELF)							\
351      {									\
352	fprintf ((FILE), "%s", COMMON_ASM_OP);				\
353	assemble_name ((FILE), (NAME));					\
354	fprintf ((FILE), ",%u,%u\n", (SIZE), (ALIGN) / BITS_PER_UNIT);	\
355      }									\
356    else								\
357      {									\
358	int rounded = (SIZE);						\
359	if (rounded == 0) rounded = 1;					\
360	rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;		\
361	rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)	\
362		   * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));		\
363	fprintf ((FILE), "%s ", COMMON_ASM_OP);				\
364	assemble_name ((FILE), (NAME));					\
365	fprintf ((FILE), ",%u\n", (rounded));				\
366      }									\
367  } while (0)
368
369/* This says how to output assembler code to declare an
370   uninitialized internal linkage data object.  Under SVR4,
371   the linker seems to want the alignment of data objects
372   to depend on their types.  We do exactly that here.  */
373
374#undef  ASM_OUTPUT_ALIGNED_LOCAL
375#define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN)		\
376  do {									\
377    if (TARGET_ELF)							\
378      {									\
379	fprintf ((FILE), "%s", LOCAL_ASM_OP);				\
380	assemble_name ((FILE), (NAME));					\
381	fprintf ((FILE), "\n");						\
382	ASM_OUTPUT_ALIGNED_COMMON ((FILE), (NAME), (SIZE), (ALIGN));	\
383      }									\
384    else								\
385      {									\
386	int rounded = (SIZE);						\
387	if (rounded == 0) rounded = 1;					\
388	rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;		\
389	rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)	\
390		   * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));		\
391	fputs ("\t.lcomm\t", (FILE));					\
392	assemble_name ((FILE), (NAME));					\
393	fprintf ((FILE), ",%u\n", (rounded));				\
394      }									\
395  } while (0)
396
397/* How to output some space.  The rules are different depending on the
398   object format.  */
399#undef  ASM_OUTPUT_SKIP
400#define ASM_OUTPUT_SKIP(FILE, SIZE) 					\
401  do {									\
402    if (TARGET_ELF)							\
403      {									\
404        fprintf ((FILE), "%s%u\n", SKIP_ASM_OP, (SIZE));		\
405      }									\
406    else								\
407      {									\
408        fprintf ((FILE), "\t.space\t%u\n", (SIZE));			\
409      }									\
410  } while (0)
411
412
413#undef  ASM_OUTPUT_SOURCE_LINE
414#define ASM_OUTPUT_SOURCE_LINE(FILE, LINE)				\
415  do {									\
416    static int sym_lineno = 1;						\
417    if (TARGET_ELF)							\
418      {									\
419	fprintf ((FILE), ".stabn 68,0,%d,.LM%d-", (LINE), sym_lineno);	\
420	assemble_name ((FILE), 						\
421		XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));	\
422	fprintf ((FILE), "\n.LM%d:\n", sym_lineno);			\
423	sym_lineno += 1;						\
424      }									\
425    else								\
426      {									\
427	fprintf ((FILE), "\t%s %d,0,%d\n", ASM_STABD_OP, N_SLINE,	\
428		lineno);						\
429      }									\
430  } while (0)
431
432/* These macros generate the special .type and .size directives which
433   are used to set the corresponding fields of the linker symbol table
434   entries in an ELF object file under SVR4.  These macros also output
435   the starting labels for the relevant functions/objects.  */
436
437/* Write the extra assembler code needed to declare a function properly.
438   Some svr4 assemblers need to also have something extra said about the
439   function's return value.  We allow for that here.  */
440
441#undef  ASM_DECLARE_FUNCTION_NAME
442#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL)			\
443  do {									\
444    fprintf (FILE, "\t%s\t ", TYPE_ASM_OP);				\
445    assemble_name (FILE, NAME);						\
446    putc (',', FILE);							\
447    fprintf (FILE, TYPE_OPERAND_FMT, "function");			\
448    putc ('\n', FILE);							\
449    ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL));			\
450    ASM_OUTPUT_LABEL(FILE, NAME);					\
451  } while (0)
452
453/* This is how to declare the size of a function.  */
454
455#undef  ASM_DECLARE_FUNCTION_SIZE
456#define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL)			\
457  do {									\
458    if (!flag_inhibit_size_directive)					\
459      {									\
460        char label[256];						\
461	static int labelno;						\
462	labelno++;							\
463	ASM_GENERATE_INTERNAL_LABEL (label, "Lfe", labelno);		\
464	ASM_OUTPUT_INTERNAL_LABEL (FILE, "Lfe", labelno);		\
465	fprintf (FILE, "\t%s\t ", SIZE_ASM_OP);				\
466	assemble_name (FILE, (FNAME));					\
467        fprintf (FILE, ",");						\
468	assemble_name (FILE, label);					\
469        fprintf (FILE, "-");						\
470	assemble_name (FILE, (FNAME));					\
471	putc ('\n', FILE);						\
472      }									\
473  } while (0)
474
475
476/* The routine used to output NUL terminated strings.  We use a special
477   version of this for most svr4 targets because doing so makes the
478   generated assembly code more compact (and thus faster to assemble)
479   as well as more readable, especially for targets like the i386
480   (where the only alternative is to output character sequences as
481   comma separated lists of numbers).   */
482
483#undef  ASM_OUTPUT_LIMITED_STRING
484#define ASM_OUTPUT_LIMITED_STRING(FILE, STR)				\
485  do {									\
486      register unsigned char *_limited_str = (unsigned char *) (STR);	\
487      register unsigned ch;						\
488      fprintf ((FILE), "\t%s\t\"", STRING_ASM_OP);			\
489      for (; (ch = *_limited_str); _limited_str++)			\
490        {								\
491	  register int escape;						\
492	  switch (escape = ESCAPES[ch])					\
493	    {								\
494	    case 0:							\
495	      putc (ch, (FILE));					\
496	      break;							\
497	    case 1:							\
498	      fprintf ((FILE), "\\%03o", ch);				\
499	      break;							\
500	    default:							\
501	      putc ('\\', (FILE));					\
502	      putc (escape, (FILE));					\
503	      break;							\
504	    }								\
505        }								\
506      fprintf ((FILE), "\"\n");						\
507  } while (0)
508
509/* Switch into a generic section.
510
511   We make the section read-only and executable for a function decl,
512   read-only for a const data decl, and writable for a non-const data decl.
513
514   If the section has already been defined, we must not
515   emit the attributes here. The SVR4 assembler does not
516   recognize section redefinitions.
517   If DECL is NULL, no attributes are emitted.  */
518
519#undef  ASM_OUTPUT_SECTION_NAME
520#define ASM_OUTPUT_SECTION_NAME(FILE, DECL, NAME, RELOC)		\
521  do {									\
522    static struct section_info						\
523      {									\
524	struct section_info *next;				        \
525	char *name;						        \
526	enum sect_enum {SECT_RW, SECT_RO, SECT_EXEC} type;		\
527      } *sections;							\
528    struct section_info *s;						\
529    char *mode;								\
530    enum sect_enum type;						\
531									\
532    for (s = sections; s; s = s->next)					\
533      if (!strcmp (NAME, s->name))					\
534	break;								\
535									\
536    if (DECL && TREE_CODE (DECL) == FUNCTION_DECL)			\
537      type = SECT_EXEC, mode = "ax";					\
538    else if (DECL && DECL_READONLY_SECTION (DECL, RELOC))		\
539      type = SECT_RO, mode = "a";					\
540    else								\
541      type = SECT_RW, mode = "aw";					\
542									\
543    if (s == 0)								\
544      {									\
545	s = (struct section_info *) xmalloc (sizeof (struct section_info));  \
546	s->name = xmalloc ((strlen (NAME) + 1) * sizeof (*NAME));	\
547	strcpy (s->name, NAME);						\
548	s->type = type;							\
549	s->next = sections;						\
550	sections = s;							\
551	fprintf (FILE, ".section\t%s,\"%s\",@progbits\n", NAME, mode);	\
552      }									\
553    else								\
554      {									\
555	if (DECL && s->type != type)					\
556	  error_with_decl (DECL, "%s causes a section type conflict");	\
557									\
558	fprintf (FILE, ".section\t%s\n", NAME);				\
559      }									\
560  } while (0)
561
562#undef  MAKE_DECL_ONE_ONLY
563#define MAKE_DECL_ONE_ONLY(DECL)	(DECL_WEAK (DECL) = 1)
564#undef  UNIQUE_SECTION_P
565#define UNIQUE_SECTION_P(DECL)		(DECL_ONE_ONLY (DECL))
566#undef  UNIQUE_SECTION
567#define UNIQUE_SECTION(DECL,RELOC)					\
568  do {									\
569    int len;								\
570    char *name, *string, *prefix;					\
571									\
572    name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL));		\
573									\
574    if (! DECL_ONE_ONLY (DECL))						\
575      {									\
576	prefix = ".";                                             	\
577	if (TREE_CODE (DECL) == FUNCTION_DECL)				\
578	  prefix = ".text.";						\
579	else if (DECL_READONLY_SECTION (DECL, RELOC))			\
580	  prefix = ".rodata.";						\
581	else								\
582	  prefix = ".data.";						\
583      }									\
584    else if (TREE_CODE (DECL) == FUNCTION_DECL)				\
585      prefix = ".gnu.linkonce.t.";					\
586    else if (DECL_READONLY_SECTION (DECL, RELOC))			\
587      prefix = ".gnu.linkonce.r.";					\
588    else								\
589      prefix = ".gnu.linkonce.d.";					\
590									\
591    len = strlen (name) + strlen (prefix);				\
592    string = alloca (len + 1);						\
593    sprintf (string, "%s%s", prefix, name);				\
594									\
595    DECL_SECTION_NAME (DECL) = build_string (len, string);		\
596  } while (0)
597
598/* A C statement or statements to switch to the appropriate
599   section for output of DECL.  DECL is either a `VAR_DECL' node
600   or a constant of some sort.  RELOC indicates whether forming
601   the initial value of DECL requires link-time relocations.  */
602
603#undef  SELECT_SECTION
604#define SELECT_SECTION(DECL,RELOC)					\
605  {									\
606    if (flag_pic && RELOC)						\
607      data_section ();							\
608    else if (TREE_CODE (DECL) == STRING_CST)				\
609      {									\
610	if (! flag_writable_strings)					\
611	  const_section ();						\
612	else								\
613	  data_section ();						\
614      }									\
615    else if (TREE_CODE (DECL) == VAR_DECL)				\
616      {									\
617	if (! DECL_READONLY_SECTION (DECL, RELOC))			\
618	  data_section ();						\
619	else								\
620	  const_section ();						\
621      }									\
622    else								\
623      const_section ();							\
624  }
625
626/* A C statement (sans semicolon) to output an element in the table of
627   global constructors.  */
628#undef  ASM_OUTPUT_CONSTRUCTOR
629#define ASM_OUTPUT_CONSTRUCTOR(FILE, NAME)				\
630  do {									\
631    if (TARGET_ELF)							\
632      {									\
633	ctors_section ();						\
634	fprintf ((FILE), "%s ", INT_ASM_OP);				\
635	assemble_name ((FILE), (NAME));					\
636	fprintf ((FILE), "\n");						\
637      }									\
638    else								\
639      {									\
640	fprintf (asm_out_file, "%s \"%s__CTOR_LIST__\",22,0,0,",	\
641		 ASM_STABS_OP, (TARGET_UNDERSCORES) ? "_" : "");	\
642	assemble_name (asm_out_file, name);				\
643	fputc ('\n', asm_out_file);					\
644      }									\
645  } while (0)
646
647/* A C statement (sans semicolon) to output an element in the table of
648   global destructors.  */
649#undef  ASM_OUTPUT_DESTRUCTOR
650#define ASM_OUTPUT_DESTRUCTOR(FILE, NAME)				\
651  do {									\
652    if (TARGET_ELF)							\
653      {									\
654	dtors_section ();						\
655	fprintf ((FILE), "%s ", INT_ASM_OP);				\
656	assemble_name ((FILE), (NAME));					\
657	fprintf ((FILE), "\n");						\
658      }									\
659    else								\
660      {									\
661	fprintf (asm_out_file, "%s \"%s__DTOR_LIST__\",22,0,0,",	\
662		 ASM_STABS_OP, (TARGET_UNDERSCORES) ? "_" : "");	\
663	assemble_name (asm_out_file, name);				\
664	fputc ('\n', asm_out_file);					\
665      }									\
666  } while (0)
667
668/* Define macro used to output shift-double opcodes when the shift
669   count is in %cl.  Some assemblers require %cl as an argument;
670   some don't.
671
672   *OLD* GAS requires the %cl argument, so override i386/unix.h. */
673
674#undef  AS3_SHIFT_DOUBLE
675#define AS3_SHIFT_DOUBLE(a,b,c,d)	AS3 (a,b,c,d)
676
677
678/************************[  Debugger stuff  ]*********************************/
679
680/* Copy this from the svr4 specifications... */
681/* Define the register numbers to be used in Dwarf debugging information.
682   The SVR4 reference port C compiler uses the following register numbers
683   in its Dwarf output code:
684	0 for %eax (gnu regno = 0)
685	1 for %ecx (gnu regno = 2)
686	2 for %edx (gnu regno = 1)
687	3 for %ebx (gnu regno = 3)
688	4 for %esp (gnu regno = 7)
689	5 for %ebp (gnu regno = 6)
690	6 for %esi (gnu regno = 4)
691	7 for %edi (gnu regno = 5)
692   The following three DWARF register numbers are never generated by
693   the SVR4 C compiler or by the GNU compilers, but SDB on x86/svr4
694   believes these numbers have these meanings.
695	8  for %eip    (no gnu equivalent)
696	9  for %eflags (no gnu equivalent)
697	10 for %trapno (no gnu equivalent)
698   It is not at all clear how we should number the FP stack registers
699   for the x86 architecture.  If the version of SDB on x86/svr4 were
700   a bit less brain dead with respect to floating-point then we would
701   have a precedent to follow with respect to DWARF register numbers
702   for x86 FP registers, but the SDB on x86/svr4 is so completely
703   broken with respect to FP registers that it is hardly worth thinking
704   of it as something to strive for compatibility with.
705   The version of x86/svr4 SDB I have at the moment does (partially)
706   seem to believe that DWARF register number 11 is associated with
707   the x86 register %st(0), but that's about all.  Higher DWARF
708   register numbers don't seem to be associated with anything in
709   particular, and even for DWARF regno 11, SDB only seems to under-
710   stand that it should say that a variable lives in %st(0) (when
711   asked via an `=' command) if we said it was in DWARF regno 11,
712   but SDB still prints garbage when asked for the value of the
713   variable in question (via a `/' command).
714   (Also note that the labels SDB prints for various FP stack regs
715   when doing an `x' command are all wrong.)
716   Note that these problems generally don't affect the native SVR4
717   C compiler because it doesn't allow the use of -O with -g and
718   because when it is *not* optimizing, it allocates a memory
719   location for each floating-point variable, and the memory
720   location is what gets described in the DWARF AT_location
721   attribute for the variable in question.
722   Regardless of the severe mental illness of the x86/svr4 SDB, we
723   do something sensible here and we use the following DWARF
724   register numbers.  Note that these are all stack-top-relative
725   numbers.
726	11 for %st(0) (gnu regno = 8)
727	12 for %st(1) (gnu regno = 9)
728	13 for %st(2) (gnu regno = 10)
729	14 for %st(3) (gnu regno = 11)
730	15 for %st(4) (gnu regno = 12)
731	16 for %st(5) (gnu regno = 13)
732	17 for %st(6) (gnu regno = 14)
733	18 for %st(7) (gnu regno = 15)
734*/
735#undef  DWARF_DBX_REGISTER_NUMBER
736#define DWARF_DBX_REGISTER_NUMBER(n) \
737((n) == 0 ? 0 \
738 : (n) == 1 ? 2 \
739 : (n) == 2 ? 1 \
740 : (n) == 3 ? 3 \
741 : (n) == 4 ? 6 \
742 : (n) == 5 ? 7 \
743 : (n) == 6 ? 5 \
744 : (n) == 7 ? 4 \
745 : ((n) >= FIRST_STACK_REG && (n) <= LAST_STACK_REG) ? (n)+3 \
746 : (-1))
747
748/* Now what stabs expects in the register.  */
749#undef  STABS_DBX_REGISTER_NUMBER
750#define STABS_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 ? 4 : \
758 (n) == 7 ? 5 : \
759 (n) + 4)
760
761#undef  DBX_REGISTER_NUMBER
762#define DBX_REGISTER_NUMBER(n)	((write_symbols == DWARF2_DEBUG		\
763	    			  || write_symbols == DWARF_DEBUG)	\
764				? DWARF_DBX_REGISTER_NUMBER(n)		\
765				: STABS_DBX_REGISTER_NUMBER(n))
766
767/* tag end of file in elf mode */
768#undef  DBX_OUTPUT_MAIN_SOURCE_FILE_END
769#define DBX_OUTPUT_MAIN_SOURCE_FILE_END(FILE, FILENAME)			\
770  do {									\
771    if (TARGET_ELF) {							\
772      fprintf ((FILE), "\t.text\n\t.stabs \"\",%d,0,0,.Letext\n.Letext:\n", \
773		N_SO);							\
774    }									\
775  } while (0)
776
777/* stabs-in-elf has offsets relative to function beginning */
778#undef  DBX_OUTPUT_LBRAC
779#define DBX_OUTPUT_LBRAC(FILE, NAME)					\
780  do {									\
781    fprintf (asmfile, "%s %d,0,0,", ASM_STABN_OP, N_LBRAC);		\
782    assemble_name (asmfile, buf);					\
783    if (TARGET_ELF)							\
784      {									\
785        fputc ('-', asmfile);						\
786        assemble_name (asmfile,						\
787	      	 XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));	\
788      }									\
789    fprintf (asmfile, "\n");						\
790  } while (0)
791
792#undef  DBX_OUTPUT_RBRAC
793#define DBX_OUTPUT_RBRAC(FILE, NAME)					\
794  do {									\
795    fprintf (asmfile, "%s %d,0,0,", ASM_STABN_OP, N_RBRAC);		\
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