1 /* Definitions for Intel 386 running FreeBSD with either a.out or ELF format
2 Copyright (C) 1994, 1995 Free Software Foundation, Inc.
3 Contributed by Eric Youngdale.
4 Modified for stabs-in-ELF by H.J. Lu.
5 Adapted from Linux version by John Polstra.
6 Added support for generating "old a.out gas" on the fly by Peter Wemm.
8 This file is part of GNU CC.
10 GNU CC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
15 GNU CC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GNU CC; see the file COPYING. If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA. */
25 /* A lie, I guess, but the general idea behind FreeBSD/ELF is that we are
26 supposed to be outputting something that will assemble under SVr4.
27 This gets us pretty close. */
28 #include <i386/i386.h> /* Base i386 target machine definitions */
29 #include <i386/att.h> /* Use the i386 AT&T assembler syntax */
30 #include <linux.h> /* some common stuff */
32 /* Don't assume anything about the header files. */
33 #define NO_IMPLICIT_EXTERN_C
35 /* This defines which switch letters take arguments. On svr4, most of
36 the normal cases (defined in gcc.c) apply, and we also have -h* and
37 -z* options (for the linker). We have a slightly different mix. We
38 have -R (alias --rpath), no -z, --soname (-h), --assert etc. */
40 #undef SWITCH_TAKES_ARG
41 #define SWITCH_TAKES_ARG(CHAR) \
53 || (CHAR) == 'z' /* ignored by ld */ \
56 #undef WORD_SWITCH_TAKES_ARG
57 #define WORD_SWITCH_TAKES_ARG(STR) \
58 (DEFAULT_WORD_SWITCH_TAKES_ARG (STR) \
59 || !strcmp (STR, "rpath") || !strcmp (STR, "rpath-link") \
60 || !strcmp (STR, "soname") || !strcmp (STR, "defsym") \
61 || !strcmp (STR, "assert") || !strcmp (STR, "dynamic-linker"))
64 #define TARGET_VERSION fprintf (stderr, " (i386 FreeBSD)");
66 #define MASK_PROFILER_EPILOGUE 010000000000
67 #define MASK_AOUT 004000000000 /* a.out not elf */
68 #define MASK_UNDERSCORES 002000000000 /* use leading _ */
70 #define TARGET_PROFILER_EPILOGUE (target_flags & MASK_PROFILER_EPILOGUE)
71 #define TARGET_AOUT (target_flags & MASK_AOUT)
72 #define TARGET_ELF ((target_flags & MASK_AOUT) == 0)
73 #define TARGET_UNDERSCORES ((target_flags & MASK_UNDERSCORES) != 0)
75 #undef SUBTARGET_SWITCHES
76 #define SUBTARGET_SWITCHES \
77 { "profiler-epilogue", MASK_PROFILER_EPILOGUE}, \
78 { "no-profiler-epilogue", -MASK_PROFILER_EPILOGUE}, \
79 { "aout", MASK_AOUT}, \
80 { "no-aout", -MASK_AOUT}, \
81 { "underscores", MASK_UNDERSCORES}, \
82 { "no-underscores", -MASK_UNDERSCORES},
84 /* The svr4 ABI for the i386 says that records and unions are returned
86 /* On FreeBSD, we do not. */
87 #undef DEFAULT_PCC_STRUCT_RETURN
88 #define DEFAULT_PCC_STRUCT_RETURN 0
90 /* Prefix for internally generated assembler labels. If we aren't using
91 underscores, we are using prefix `.'s to identify labels that should
92 be ignored, as in `i386/gas.h' --karl@cs.umb.edu */
94 #define LPREFIX ((TARGET_UNDERSCORES) ? "L" : ".L")
96 /* Override the default comment-starter of "/". */
97 #undef ASM_COMMENT_START
98 #define ASM_COMMENT_START "#"
101 #define COMMENT_BEGIN "#"
104 #define ASM_APP_ON "#APP\n"
107 #define ASM_APP_OFF "#NO_APP\n"
109 /* Output at beginning of assembler file. */
110 /* The .file command should always begin the output. */
112 #undef ASM_FILE_START
113 #define ASM_FILE_START(FILE) \
115 output_file_directive (FILE, main_input_filename); \
117 fprintf (FILE, "\t.version\t\"01.01\"\n"); \
120 /* Identify the front-end which produced this file. To keep symbol
121 space down, and not confuse kdb, only do this if the language is
122 not C. (svr4.h defines ASM_IDENTIFY_GCC but neglects this) */
123 #undef ASM_IDENTIFY_LANGUAGE
124 #define ASM_IDENTIFY_LANGUAGE(STREAM) \
126 if (strcmp (lang_identify (), "c") != 0) \
127 output_lang_identify (STREAM); \
130 /* This is how to store into the string BUF
131 the symbol_ref name of an internal numbered label where
132 PREFIX is the class of label and NUM is the number within the class.
133 This is suitable for output with `assemble_name'. */
134 #undef ASM_GENERATE_INTERNAL_LABEL
135 #define ASM_GENERATE_INTERNAL_LABEL(BUF,PREFIX,NUMBER) \
136 sprintf ((BUF), "*%s%s%d", (TARGET_UNDERSCORES) ? "" : ".", \
139 /* This is how to output an internal numbered label where
140 PREFIX is the class of label and NUM is the number within the class. */
141 #undef ASM_OUTPUT_INTERNAL_LABEL
142 #define ASM_OUTPUT_INTERNAL_LABEL(FILE,PREFIX,NUM) \
143 fprintf (FILE, "%s%s%d:\n", (TARGET_UNDERSCORES) ? "" : ".", \
146 /* This is how to output a reference to a user-level label named NAME. */
147 #undef ASM_OUTPUT_LABELREF
148 #define ASM_OUTPUT_LABELREF(FILE,NAME) \
149 fprintf (FILE, "%s%s", (TARGET_UNDERSCORES) ? "_" : "", NAME)
152 /* This is how to output an element of a case-vector that is relative.
153 This is only used for PIC code. See comments by the `casesi' insn in
154 i386.md for an explanation of the expression this outputs. */
155 #undef ASM_OUTPUT_ADDR_DIFF_ELT
156 #define ASM_OUTPUT_ADDR_DIFF_ELT(FILE, VALUE, REL) \
157 fprintf (FILE, "\t.long _GLOBAL_OFFSET_TABLE_+[.-%s%d]\n", LPREFIX, VALUE)
159 #undef ASM_OUTPUT_ALIGN
160 #define ASM_OUTPUT_ALIGN(FILE,LOG) \
161 if ((LOG)!=0) fprintf ((FILE), "\t.p2align %d\n", (LOG))
163 /* Align labels, etc. at 4-byte boundaries.
164 For the 486, align to 16-byte boundary for sake of cache. */
165 #undef ASM_OUTPUT_ALIGN_CODE
166 #define ASM_OUTPUT_ALIGN_CODE(FILE) \
167 fprintf ((FILE), "\t.p2align %d,0x90\n", i386_align_jumps)
169 /* Align start of loop at 4-byte boundary. */
170 #undef ASM_OUTPUT_LOOP_ALIGN
171 #define ASM_OUTPUT_LOOP_ALIGN(FILE) \
172 fprintf ((FILE), "\t.p2align %d,0x90\n", i386_align_loops)
175 /* conditionalize the use of ".section rodata" on elf mode - otherwise .text */
176 #undef USE_CONST_SECTION
177 #define USE_CONST_SECTION TARGET_ELF
179 /* A C statement (sans semicolon) to output an element in the table of
180 global constructors. */
181 #undef ASM_OUTPUT_CONSTRUCTOR
182 #define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME) \
186 fprintf (FILE, "\t%s\t ", INT_ASM_OP); \
187 assemble_name (FILE, NAME); \
188 fprintf (FILE, "\n"); \
190 fprintf (asm_out_file, "%s \"%s__CTOR_LIST__\",22,0,0,", ASM_STABS_OP, \
191 (TARGET_UNDERSCORES) ? "_" : ""); \
192 assemble_name (asm_out_file, name); \
193 fputc ('\n', asm_out_file); \
197 /* A C statement (sans semicolon) to output an element in the table of
198 global destructors. */
199 #undef ASM_OUTPUT_DESTRUCTOR
200 #define ASM_OUTPUT_DESTRUCTOR(FILE,NAME) \
204 fprintf (FILE, "\t%s\t ", INT_ASM_OP); \
205 assemble_name (FILE, NAME); \
206 fprintf (FILE, "\n"); \
208 fprintf (asm_out_file, "%s \"%s__DTOR_LIST__\",22,0,0,", ASM_STABS_OP, \
209 (TARGET_UNDERSCORES) ? "_" : ""); \
210 assemble_name (asm_out_file, name); \
211 fputc ('\n', asm_out_file); \
215 /* This says how to output assembler code to declare an
216 uninitialized internal linkage data object. Under SVR4,
217 the linker seems to want the alignment of data objects
218 to depend on their types. We do exactly that here. */
220 #undef ASM_OUTPUT_ALIGNED_LOCAL
221 #define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN) \
224 fprintf ((FILE), "\t%s\t", LOCAL_ASM_OP); \
225 assemble_name ((FILE), (NAME)); \
226 fprintf ((FILE), "\n"); \
227 ASM_OUTPUT_ALIGNED_COMMON (FILE, NAME, SIZE, ALIGN); \
229 int rounded = (SIZE); \
230 if (rounded == 0) rounded = 1; \
231 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1; \
232 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT) \
233 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT)); \
234 fputs (".lcomm ", (FILE)); \
235 assemble_name ((FILE), (NAME)); \
236 fprintf ((FILE), ",%u\n", (rounded)); \
240 #undef ASM_OUTPUT_ALIGNED_COMMON
241 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN) \
244 fprintf ((FILE), "\t%s\t", COMMON_ASM_OP); \
245 assemble_name ((FILE), (NAME)); \
246 fprintf ((FILE), ",%u,%u\n", (SIZE), (ALIGN) / BITS_PER_UNIT); \
248 int rounded = (SIZE); \
249 if (rounded == 0) rounded = 1; \
250 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1; \
251 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT) \
252 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT)); \
253 fputs (".comm ", (FILE)); \
254 assemble_name ((FILE), (NAME)); \
255 fprintf ((FILE), ",%u\n", (rounded)); \
259 /* Turn off svr4.h version, it chokes the old gas. The old layout
260 works fine under new gas anyway. */
261 #undef ASM_OUTPUT_ASCII
263 /* How to output some space */
264 #undef ASM_OUTPUT_SKIP
265 #define ASM_OUTPUT_SKIP(FILE,SIZE) \
268 fprintf (FILE, "\t%s\t%u\n", SKIP_ASM_OP, (SIZE)); \
270 fprintf (FILE, "\t.space %u\n", (SIZE)); \
274 #undef ASM_OUTPUT_SOURCE_LINE
275 #define ASM_OUTPUT_SOURCE_LINE(file, line) \
277 static int sym_lineno = 1; \
279 fprintf (file, ".stabn 68,0,%d,.LM%d-", line, sym_lineno); \
280 assemble_name (file, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));\
281 fprintf (file, "\n.LM%d:\n", sym_lineno); \
284 fprintf (file, "\t%s %d,0,%d\n", ASM_STABD_OP, N_SLINE, lineno); \
288 /* in elf, the function stabs come first, before the relative offsets */
289 #undef DBX_FUNCTION_FIRST
290 #define DBX_CHECK_FUNCTION_FIRST TARGET_ELF
292 /* tag end of file in elf mode */
293 #undef DBX_OUTPUT_MAIN_SOURCE_FILE_END
294 #define DBX_OUTPUT_MAIN_SOURCE_FILE_END(FILE, FILENAME) \
297 fprintf (FILE, "\t.text\n\t.stabs \"\",%d,0,0,.Letext\n.Letext:\n", N_SO); \
301 /* stabs-in-elf has offsets relative to function beginning */
302 #undef DBX_OUTPUT_LBRAC
303 #define DBX_OUTPUT_LBRAC(file,name) \
305 fprintf (asmfile, "%s %d,0,0,", ASM_STABN_OP, N_LBRAC); \
306 assemble_name (asmfile, buf); \
308 fputc ('-', asmfile); \
309 assemble_name (asmfile, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0)); \
311 fprintf (asmfile, "\n"); \
314 #undef DBX_OUTPUT_RBRAC
315 #define DBX_OUTPUT_RBRAC(file,name) \
317 fprintf (asmfile, "%s %d,0,0,", ASM_STABN_OP, N_RBRAC); \
318 assemble_name (asmfile, buf); \
320 fputc ('-', asmfile); \
321 assemble_name (asmfile, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0)); \
323 fprintf (asmfile, "\n"); \
327 /* Define macro used to output shift-double opcodes when the shift
328 count is in %cl. Some assemblers require %cl as an argument;
331 *OLD* GAS requires the %cl argument, so override i386/unix.h. */
333 #undef AS3_SHIFT_DOUBLE
334 #define AS3_SHIFT_DOUBLE(a,b,c,d) AS3 (a,b,c,d)
336 /* Indicate that jump tables go in the text section. This is
337 necessary when compiling PIC code. */
338 #define JUMP_TABLES_IN_TEXT_SECTION
340 /* override the exception table positioning */
341 #define EXCEPTION_SECTION_FUNCTION \
344 named_section (NULL_TREE, ".gcc_except_table"); \
349 readonly_data_section (); \
353 /* supply our own hook for calling __main() from main() */
354 #define GEN_CALL__MAIN \
357 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, NAME__MAIN), 0, \
361 /* Use dollar signs in special g++ assembler names. */
362 #undef NO_DOLLAR_IN_LABEL
364 /* Map i386 registers to the numbers dwarf expects. Of course this is different
365 from what stabs expects. */
367 #undef DWARF_DBX_REGISTER_NUMBER
368 #define DWARF_DBX_REGISTER_NUMBER(n) \
377 : ((n) >= FIRST_STACK_REG && (n) <= LAST_STACK_REG) ? (n)+3 \
380 /* Now what stabs expects in the register. */
381 #define STABS_DBX_REGISTER_NUMBER(n) \
392 #undef DBX_REGISTER_NUMBER
393 #define DBX_REGISTER_NUMBER(n) ((write_symbols == DWARF_DEBUG) \
394 ? DWARF_DBX_REGISTER_NUMBER(n) \
395 : STABS_DBX_REGISTER_NUMBER(n))
397 /* Tell final.c that we don't need a label passed to mcount. */
398 #define NO_PROFILE_DATA
400 /* Output assembler code to FILE to increment profiler label # LABELNO
401 for profiling a function entry. */
402 /* Redefine this to not pass an unused label in %edx. */
404 #undef FUNCTION_PROFILER
405 #define FUNCTION_PROFILER(FILE, LABELNO) \
408 fprintf (FILE, "\tcall *%s@GOT(%%ebx)\n", \
409 TARGET_AOUT ? "mcount" : ".mcount"); \
411 fprintf (FILE, "\tcall %s\n", TARGET_AOUT ? "mcount" : ".mcount"); \
414 #define FUNCTION_PROFILER_EPILOGUE(FILE) \
416 if (TARGET_PROFILER_EPILOGUE) \
419 fprintf (FILE, "\tcall *%s@GOT(%%ebx)\n", \
420 TARGET_AOUT ? "mexitcount" : ".mexitcount"); \
422 fprintf (FILE, "\tcall %s\n", \
423 TARGET_AOUT ? "mexitcount" : ".mexitcount"); \
428 #define SIZE_TYPE "unsigned int"
431 #define PTRDIFF_TYPE "int"
434 #define WCHAR_TYPE "int"
436 #define WCHAR_UNSIGNED 0
438 #undef WCHAR_TYPE_SIZE
439 #define WCHAR_TYPE_SIZE BITS_PER_WORD
441 /* FREEBSD_NATIVE is defined when gcc is integrated into the FreeBSD
442 source tree so it can be configured appropriately without using
443 the GNU configure/build mechanism. */
445 #ifdef FREEBSD_NATIVE
447 /* Look for the include files in the system-defined places. */
449 #define GPLUSPLUS_INCLUDE_DIR "/usr/include/g++"
451 #define GCC_INCLUDE_DIR "/usr/include"
453 /* FreeBSD has GCC_INCLUDE_DIR first. */
454 #define INCLUDE_DEFAULTS \
456 { GCC_INCLUDE_DIR, 0, 0 }, \
457 { GPLUSPLUS_INCLUDE_DIR, 1, 1 }, \
461 /* Under FreeBSD, the normal location of the compiler back ends is the
462 /usr/libexec directory. */
464 #define STANDARD_EXEC_PREFIX "/usr/libexec/"
466 /* Under FreeBSD, the normal location of the various *crt*.o files is the
467 /usr/lib directory. */
469 #define STANDARD_STARTFILE_PREFIX "/usr/lib/"
471 /* On FreeBSD, gcc is called 'cc' */
472 #define GCC_NAME "cc"
474 /* FreeBSD is 4.4BSD derived */
477 #endif /* FREEBSD_NATIVE */
479 #undef CPP_PREDEFINES
480 #define CPP_PREDEFINES "-Dunix -Di386 -D__FreeBSD__=4 -D__FreeBSD_cc_version=400001 -Asystem(unix) -Asystem(FreeBSD) -Acpu(i386) -Amachine(i386)"
483 #if TARGET_CPU_DEFAULT == 2
485 %{!maout: -D__ELF__} \
486 %{munderscores: -D__UNDERSCORES__} \
487 %{maout: %{!mno-underscores: -D__UNDERSCORES__}} \
488 %{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__} %{!m386:-D__i486__}"
491 %{!maout: -D__ELF__} \
492 %{munderscores: -D__UNDERSCORES__} \
493 %{maout: %{!mno-underscores: -D__UNDERSCORES__}} \
494 %{fPIC:-D__PIC__ -D__pic__} %{fpic:-D__PIC__ -D__pic__} %{m486:-D__i486__}"
499 %{gline:%{!g:%{!g0:%{!g1:%{!g2: -g1}}}}} \
500 %{maout: %{!mno-underscores: %{!munderscores: -munderscores }}}"
503 #define ASM_SPEC "%{v*: -v} %{maout: %{fpic:-k} %{fPIC:-k}}"
505 /* Like the default, except no -lg, and no -p. */
507 #define LIB_SPEC "%{!shared:%{!pg:%{!pthread:%{!kthread:-lc}%{kthread:-lpthread -lc}}%{pthread:-lc_r}}%{pg:%{!pthread:%{!kthread:-lc_p}%{kthread:-lpthread_p -lc_p}}%{pthread:-lc_r_p}}}"
509 /* Let gcc locate this for us according to the -m rules */
511 #define LIBGCC_SPEC "%{!shared:libgcc.a%s}"
513 /* Provide a LINK_SPEC appropriate for FreeBSD. Here we provide support
514 for the special GCC options -static and -shared, which allow us to
515 link things in one of these three modes by applying the appropriate
516 combinations of options at link-time. We like to support here for
517 as many of the other GNU linker options as possible. But I don't
518 have the time to search for those flags. I am sure how to add
519 support for -soname shared_object_name. H.J.
521 When the -shared link option is used a final link is not being
526 %{p:%e`-p' not supported; use `-pg' and gprof(1)} \
527 %{maout: %{shared:-Bshareable} \
528 %{!shared:%{!nostdlib:%{!r:%{!e*:-e start}}} -dc -dp %{static:-Bstatic} \
529 %{pg:-Bstatic} %{Z}} \
534 %{assert*} %{R*} %{rpath*} %{defsym*} \
535 %{shared:-Bshareable %{h*} %{soname*}} \
536 %{symbolic:-Bsymbolic} \
539 %{rdynamic: -export-dynamic} \
540 %{!dynamic-linker: -dynamic-linker /usr/libexec/ld-elf.so.1}} \
541 %{static:-Bstatic}}}"
543 /* Get perform_* macros to build libgcc.a. */
544 #include "i386/perform.h"
546 #undef STARTFILE_SPEC
547 #define STARTFILE_SPEC "\
548 %{maout: %{shared:c++rt0.o%s} \
549 %{!shared:%{pg:gcrt0.o%s}%{!pg:%{static:scrt0.o%s}%{!static:crt0.o%s}}}} \
550 %{!maout: %{!shared: \
551 %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s} %{!p:crt1.o%s}}} \
552 crti.o%s %{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}}"
555 #define ENDFILE_SPEC \
556 "%{!maout: %{!shared:crtend.o%s} %{shared:crtendS.o%s} crtn.o%s}"
558 /* This goes away when the math emulator is fixed. */
559 #undef TARGET_DEFAULT
560 #define TARGET_DEFAULT (MASK_NO_FANCY_MATH_387 | 0301)
565 /* to assist building libgcc2.c */
567 #undef OBJECT_FORMAT_ELF