freebsd.h revision 95810
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 95810 2002-04-30 17:15:01Z obrien $ */
27
28#undef  TARGET_VERSION
29#define TARGET_VERSION fprintf (stderr, " (i386 FreeBSD/ELF)");
30
31#undef  CC1_SPEC
32#define CC1_SPEC "%(cc1_cpu) %{profile:-p} \
33  %{gline:%{!g:%{!g0:%{!g1:%{!g2: -g1}}}}} \
34  %{maout: %{!mno-underscores: %{!munderscores: -munderscores }}}"
35
36#undef  ASM_SPEC
37#define ASM_SPEC	"%{v*: -v} %{maout: %{fpic:-k} %{fPIC:-k}}"
38
39#undef  ASM_FINAL_SPEC
40#define ASM_FINAL_SPEC	"%|"
41
42/* Provide a LINK_SPEC appropriate for FreeBSD.  Here we provide support
43   for the special GCC options -static and -shared, which allow us to
44   link things in one of these three modes by applying the appropriate
45   combinations of options at link-time. We like to support here for
46   as many of the other GNU linker options as possible. But I don't
47   have the time to search for those flags. I am sure how to add
48   support for -soname shared_object_name. H.J.
49
50   When the -shared link option is used a final link is not being
51   done.  */
52
53#undef	LINK_SPEC
54#define LINK_SPEC "\
55 %{p:%e`-p' not supported; use `-pg' and gprof(1)} \
56  %{maout: %{shared:-Bshareable} \
57    %{!shared:%{!nostdlib:%{!r:%{!e*:-e start}}} -dc -dp %{static:-Bstatic} \
58      %{pg:-Bstatic} %{Z}} \
59    %{assert*} %{R*}} \
60  %{!maout: \
61    %{Wl,*:%*} \
62    %{v:-V} \
63    %{assert*} %{R*} %{rpath*} %{defsym*} \
64    %{shared:-Bshareable %{h*} %{soname*}} \
65    %{!shared: \
66      %{!static: \
67	%{rdynamic: -export-dynamic} \
68	%{!dynamic-linker: -dynamic-linker /usr/libexec/ld-elf.so.1}} \
69      %{static:-Bstatic}} \
70    %{symbolic:-Bsymbolic}}"
71
72/* Provide a STARTFILE_SPEC appropriate for FreeBSD.  Here we add the magical
73   crtbegin.o file (see crtstuff.c) which provides part of the support for
74   getting C++ file-scope static object constructed before entering `main'.  */
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 \
90    %{!shared:crtbegin.o%s} \
91    %{shared:crtbeginS.o%s}}"
92
93/* Provide an ENDFILE_SPEC appropriate for FreeBSD/i386.  Here we tack on our
94   own magical crtend.o file (see crtstuff.c) which provides part of the
95   support for getting C++ file-scope static object constructed before
96   entering `main', followed by the normal "finalizer" file, `crtn.o'.  */
97
98#undef  ENDFILE_SPEC
99#define ENDFILE_SPEC "\
100  %{!maout: \
101    %{!shared:crtend.o%s} \
102    %{shared:crtendS.o%s} crtn.o%s}"
103
104
105/************************[  Target stuff  ]***********************************/
106
107/* Define the actual types of some ANSI-mandated types.
108   Needs to agree with <machine/ansi.h>.  GCC defaults come from c-decl.c,
109   c-common.c, and config/<arch>/<arch>.h.  */
110
111#undef  SIZE_TYPE
112#define SIZE_TYPE	"unsigned int"
113
114#undef  PTRDIFF_TYPE
115#define PTRDIFF_TYPE	"int"
116
117#undef  WCHAR_TYPE_SIZE
118#define WCHAR_TYPE_SIZE	BITS_PER_WORD
119
120#undef  TARGET_VERSION
121#define TARGET_VERSION	fprintf (stderr, " (i386 FreeBSD/ELF)");
122
123#define MASK_PROFILER_EPILOGUE	010000000000
124#define MASK_AOUT		004000000000	/* a.out not elf */
125#define MASK_UNDERSCORES	002000000000	/* use leading _ */
126
127#define TARGET_PROFILER_EPILOGUE	(target_flags & MASK_PROFILER_EPILOGUE)
128#define TARGET_AOUT			(target_flags & MASK_AOUT)
129#define TARGET_ELF			((target_flags & MASK_AOUT) == 0)
130#define TARGET_UNDERSCORES		((target_flags & MASK_UNDERSCORES) != 0)
131
132#undef	SUBTARGET_SWITCHES
133#define SUBTARGET_SWITCHES						\
134  { "profiler-epilogue",	 MASK_PROFILER_EPILOGUE, "Function profiler epilogue"}, \
135  { "no-profiler-epilogue",	-MASK_PROFILER_EPILOGUE, "No function profiler epilogue"}, \
136  { "aout",			 MASK_AOUT, "Generate an a.out (vs. ELF) binary"}, \
137  { "no-aout",			-MASK_AOUT, "Do not generate an a.out binary"}, \
138  { "underscores",		 MASK_UNDERSCORES, "Add leading underscores to symbols"}, \
139  { "no-underscores",		-MASK_UNDERSCORES, "Do not add leading underscores to symbols"},
140
141/* This goes away when the math emulator is fixed.  */
142#undef  TARGET_SUBTARGET_DEFAULT
143#define TARGET_SUBTARGET_DEFAULT \
144  (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_NO_FANCY_MATH_387)
145
146/* Don't default to pcc-struct-return, we want to retain compatibility with
147   older gcc versions AND pcc-struct-return is nonreentrant.
148   (even though the SVR4 ABI for the i386 says that records and unions are
149   returned in memory).  */
150
151#undef  DEFAULT_PCC_STRUCT_RETURN
152#define DEFAULT_PCC_STRUCT_RETURN 0
153
154/* The a.out tools do not support "linkonce" sections. */
155#undef  SUPPORTS_ONE_ONLY
156#define SUPPORTS_ONE_ONLY	TARGET_ELF
157
158/* Prefix for internally generated assembler labels.  If we aren't using
159   underscores, we are using prefix `.'s to identify labels that should
160   be ignored, as in `i386/gas.h' --karl@cs.umb.edu  */
161#undef  LPREFIX
162#define LPREFIX ((TARGET_UNDERSCORES) ? "L" : ".L")
163
164/* supply our own hook for calling __main() from main() */
165#undef  INVOKE__main
166#define INVOKE__main
167#undef  GEN_CALL__MAIN
168#define GEN_CALL__MAIN							\
169  do {									\
170    if (!(TARGET_ELF))							\
171      emit_library_call (gen_rtx (SYMBOL_REF, Pmode, NAME__MAIN), 0,	\
172			 VOIDmode, 0);					\
173  } while (0)
174
175/* Tell final.c that we don't need a label passed to mcount.  */
176#define NO_PROFILE_COUNTERS	1
177
178/* Output assembler code to FILE to begin profiling of the current function.
179   LABELNO is an optional label.  */
180
181#undef  FUNCTION_PROFILER
182#define FUNCTION_PROFILER(FILE, LABELNO)  \
183  do {									\
184    char *_name = TARGET_AOUT ? "mcount" : ".mcount";			\
185    if (flag_pic)							\
186      fprintf ((FILE), "\tcall *%s@GOT(%%ebx)\n", _name);		\
187    else								\
188      fprintf ((FILE), "\tcall %s\n", _name);				\
189  } while (0)
190
191/* Output assembler code to FILE to end profiling of the current function.  */
192
193#undef  FUNCTION_PROFILER_EPILOGUE	/* BDE will need to fix this. */
194
195
196/************************[  Assembler stuff  ]********************************/
197
198/* Override the default comment-starter of "/" from unix.h.  */
199#undef  ASM_COMMENT_START
200#define ASM_COMMENT_START "#"
201
202#undef  ASM_APP_ON
203#define ASM_APP_ON	"#APP\n"
204
205#undef  ASM_APP_OFF
206#define ASM_APP_OFF	"#NO_APP\n"
207
208/* This is how to store into the string BUF
209   the symbol_ref name of an internal numbered label where
210   PREFIX is the class of label and NUM is the number within the class.
211   This is suitable for output with `assemble_name'.  */
212#undef	ASM_GENERATE_INTERNAL_LABEL
213#define ASM_GENERATE_INTERNAL_LABEL(LABEL, PREFIX, NUM)			\
214  sprintf ((LABEL), "*%s%s%u", (TARGET_UNDERSCORES) ? "" : ".",		\
215	   (PREFIX), (unsigned) (NUM))
216
217/* This is how to output an internal numbered label where
218   PREFIX is the class of label and NUM is the number within the class.
219   For most svr4/ELF systems, the convention is that any symbol which begins
220   with a period is not put into the linker symbol table by the assembler.  */
221#undef	ASM_OUTPUT_INTERNAL_LABEL
222#define	ASM_OUTPUT_INTERNAL_LABEL(FILE, PREFIX, NUM)			\
223  fprintf ((FILE), "%s%s%u:\n", (TARGET_UNDERSCORES) ? "" : ".",	\
224	   (PREFIX), (unsigned) (NUM))
225
226/* This is how to output a reference to a user-level label named NAME.  */
227#undef  ASM_OUTPUT_LABELREF
228#define ASM_OUTPUT_LABELREF(FILE, NAME)					\
229  do {									\
230    char *_name = (NAME);						\
231    /* Hack to avoid writing lots of rtl in				\
232       FUNCTION_PROFILER_EPILOGUE ().  */				\
233    if (*_name == '.' && strcmp(_name + 1, "mexitcount") == 0)		\
234      {									\
235	if (TARGET_AOUT)						\
236	  _name++;							\
237	if (flag_pic)							\
238	  fprintf ((FILE), "*%s@GOT(%%ebx)", _name);			\
239	else								\
240	  fprintf ((FILE), "%s", _name);				\
241      }									\
242    else								\
243      fprintf (FILE, "%s%s", TARGET_UNDERSCORES ? "_" : "", _name);	\
244} while (0)
245
246/* This is how to hack on the symbol code of certain relcalcitrant
247   symbols to modify their output in output_pic_addr_const ().  */
248
249#undef  ASM_HACK_SYMBOLREF_CODE	/* BDE will need to fix this. */
250
251/* This is how to output an element of a case-vector that is relative.
252   This is only used for PIC code.  See comments by the `casesi' insn in
253   i386.md for an explanation of the expression this outputs. */
254#undef  ASM_OUTPUT_ADDR_DIFF_ELT
255#define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, BODY, VALUE, REL)		\
256  fprintf ((FILE), "\t.long _GLOBAL_OFFSET_TABLE_+[.-%s%d]\n", LPREFIX, (VALUE))
257
258#undef  ASM_OUTPUT_ALIGN
259#define ASM_OUTPUT_ALIGN(FILE, LOG)      				\
260  if ((LOG)!=0) {							\
261    if (in_text_section())						\
262      fprintf ((FILE), "\t.p2align %d,0x90\n", (LOG));			\
263    else								\
264      fprintf ((FILE), "\t.p2align %d\n", (LOG));			\
265  }
266
267#undef  ASM_OUTPUT_ALIGNED_COMMON
268#define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN)		\
269  do {									\
270    if (TARGET_ELF)							\
271      {									\
272	fprintf ((FILE), "%s", COMMON_ASM_OP);				\
273	assemble_name ((FILE), (NAME));					\
274	fprintf ((FILE), ",%u,%u\n", (SIZE), (ALIGN) / BITS_PER_UNIT);	\
275      }									\
276    else								\
277      {									\
278	int rounded = (SIZE);						\
279	if (rounded == 0) rounded = 1;					\
280	rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;		\
281	rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)	\
282		   * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));		\
283	fprintf ((FILE), "%s ", COMMON_ASM_OP);				\
284	assemble_name ((FILE), (NAME));					\
285	fprintf ((FILE), ",%u\n", (rounded));				\
286      }									\
287  } while (0)
288
289/* This says how to output assembler code to declare an
290   uninitialized internal linkage data object.  Under SVR4,
291   the linker seems to want the alignment of data objects
292   to depend on their types.  We do exactly that here.  */
293
294#undef  ASM_OUTPUT_ALIGNED_LOCAL
295#define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN)		\
296  do {									\
297    if (TARGET_ELF)							\
298      {									\
299	fprintf ((FILE), "%s", LOCAL_ASM_OP);				\
300	assemble_name ((FILE), (NAME));					\
301	fprintf ((FILE), "\n");						\
302	ASM_OUTPUT_ALIGNED_COMMON ((FILE), (NAME), (SIZE), (ALIGN));	\
303      }									\
304    else								\
305      {									\
306	int rounded = (SIZE);						\
307	if (rounded == 0) rounded = 1;					\
308	rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1;		\
309	rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT)	\
310		   * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));		\
311	fputs ("\t.lcomm\t", (FILE));					\
312	assemble_name ((FILE), (NAME));					\
313	fprintf ((FILE), ",%u\n", (rounded));				\
314      }									\
315  } while (0)
316
317/* How to output some space.  The rules are different depending on the
318   object format.  */
319#undef  ASM_OUTPUT_SKIP
320#define ASM_OUTPUT_SKIP(FILE, SIZE) 					\
321  do {									\
322    if (TARGET_ELF)							\
323      {									\
324        fprintf ((FILE), "%s%u\n", SKIP_ASM_OP, (SIZE));		\
325      }									\
326    else								\
327      {									\
328        fprintf ((FILE), "\t.space\t%u\n", (SIZE));			\
329      }									\
330  } while (0)
331
332#undef  ASM_OUTPUT_SOURCE_LINE
333#define ASM_OUTPUT_SOURCE_LINE(FILE, LINE)				\
334  do {									\
335    static int sym_lineno = 1;						\
336    if (TARGET_ELF)							\
337      {									\
338	fprintf ((FILE), ".stabn 68,0,%d,.LM%d-", (LINE), sym_lineno);	\
339	assemble_name ((FILE), 						\
340		XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));	\
341	fprintf ((FILE), "\n.LM%d:\n", sym_lineno);			\
342	sym_lineno += 1;						\
343      }									\
344    else								\
345      {									\
346	fprintf ((FILE), "\t%s %d,0,%d\n", ASM_STABD_OP, N_SLINE,	\
347		lineno);						\
348      }									\
349  } while (0)
350
351/* A C statement to output to the stdio stream FILE an assembler
352   command to advance the location counter to a multiple of 1<<LOG
353   bytes if it is within MAX_SKIP bytes.
354
355   This is used to align code labels according to Intel recommendations.  */
356
357#ifdef HAVE_GAS_MAX_SKIP_P2ALIGN
358#define ASM_OUTPUT_MAX_SKIP_ALIGN(FILE, LOG, MAX_SKIP)					\
359  if ((LOG) != 0) {														\
360    if ((MAX_SKIP) == 0) fprintf ((FILE), "\t.p2align %d\n", (LOG));	\
361    else fprintf ((FILE), "\t.p2align %d,,%d\n", (LOG), (MAX_SKIP));	\
362  }
363#endif
364
365
366/************************[  Debugger stuff  ]*********************************/
367
368/* The a.out tools do not support "Lscope" .stabs symbols. */
369#undef  NO_DBX_FUNCTION_END
370#define NO_DBX_FUNCTION_END	TARGET_AOUT
371
372/* In ELF, the function stabs come first, before the relative offsets.  */
373#undef  DBX_FUNCTION_FIRST
374#define DBX_CHECK_FUNCTION_FIRST TARGET_ELF
375
376#undef  DBX_REGISTER_NUMBER
377#define DBX_REGISTER_NUMBER(n)	(TARGET_64BIT ? dbx64_register_map[n]	\
378				: (write_symbols == DWARF2_DEBUG	\
379	    			  || write_symbols == DWARF_DEBUG)	\
380				  ? svr4_dbx_register_map[(n)]		\
381				  : dbx_register_map[(n)])
382
383/* tag end of file in elf mode */
384#undef  DBX_OUTPUT_MAIN_SOURCE_FILE_END
385#define DBX_OUTPUT_MAIN_SOURCE_FILE_END(FILE, FILENAME)			\
386  do {									\
387    if (TARGET_ELF) {							\
388      fprintf ((FILE), "\t.text\n\t.stabs \"\",%d,0,0,%LLetext\n%LLetext:\n", \
389		N_SO);							\
390    }									\
391  } while (0)
392
393/* stabs-in-elf has offsets relative to function beginning */
394#undef  DBX_OUTPUT_LBRAC
395#define DBX_OUTPUT_LBRAC(FILE, NAME)					\
396  do {									\
397    fprintf (asmfile, "%s %d,0,0,", ASM_STABN_OP, N_LBRAC);		\
398    assemble_name (asmfile, buf);					\
399    if (TARGET_ELF)							\
400      {									\
401        fputc ('-', asmfile);						\
402        assemble_name (asmfile,						\
403	      	 XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));	\
404      }									\
405    fprintf (asmfile, "\n");						\
406  } while (0)
407
408#undef  DBX_OUTPUT_RBRAC
409#define DBX_OUTPUT_RBRAC(FILE, NAME)					\
410  do {									\
411    fprintf (asmfile, "%s %d,0,0,", ASM_STABN_OP, N_RBRAC);		\
412    assemble_name (asmfile, buf);					\
413    if (TARGET_ELF)							\
414      {									\
415        fputc ('-', asmfile);						\
416        assemble_name (asmfile,						\
417		 XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));	\
418      }									\
419    fprintf (asmfile, "\n");						\
420  } while (0)
421