freebsd.h revision 96447
1156952Sume/* Definitions for Intel 386 running FreeBSD with either a.out or ELF format 2156952Sume Copyright (C) 1996, 2000, 2002 Free Software Foundation, Inc. 3156952Sume Contributed by Eric Youngdale. 4156952Sume Modified for stabs-in-ELF by H.J. Lu. 5156952Sume Adapted from GNU/Linux version by John Polstra. 6156952Sume Added support for generating "old a.out gas" on the fly by Peter Wemm. 7156952Sume Continued development by David O'Brien <obrien@freebsd.org> 8156952Sume 9156952SumeThis file is part of GNU CC. 10156952Sume 11156952SumeGNU CC is free software; you can redistribute it and/or modify 12156952Sumeit under the terms of the GNU General Public License as published by 13156952Sumethe Free Software Foundation; either version 2, or (at your option) 14156952Sumeany later version. 15156952Sume 16156952SumeGNU CC is distributed in the hope that it will be useful, 17156952Sumebut WITHOUT ANY WARRANTY; without even the implied warranty of 18156952SumeMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19156952SumeGNU General Public License for more details. 20156952Sume 21156952SumeYou should have received a copy of the GNU General Public License 22156952Sumealong with GNU CC; see the file COPYING. If not, write to 23156952Sumethe Free Software Foundation, 59 Temple Place - Suite 330, 24156952SumeBoston, MA 02111-1307, USA. */ 25156952Sume 26156952Sume/* $FreeBSD: head/contrib/gcc/config/i386/freebsd.h 96447 2002-05-12 12:01:12Z obrien $ */ 27156952Sume 28156952Sume#undef TARGET_VERSION 29156952Sume#define TARGET_VERSION fprintf (stderr, " (i386 FreeBSD/ELF)"); 30156952Sume 31156952Sume#undef CC1_SPEC 32156952Sume#define CC1_SPEC "%(cc1_cpu) %{profile:-p} \ 33156952Sume %{gline:%{!g:%{!g0:%{!g1:%{!g2: -g1}}}}} \ 34156952Sume %{maout: %{!mno-underscores: %{!munderscores: -munderscores }}}" 35156952Sume 36156952Sume#undef ASM_SPEC 37156952Sume#define ASM_SPEC "%{v*: -v} %{maout: %{fpic:-k} %{fPIC:-k}}" 38156952Sume 39156952Sume#undef ASM_FINAL_SPEC 40156952Sume#define ASM_FINAL_SPEC "%|" 41156952Sume 42156952Sume/* Provide a LINK_SPEC appropriate for FreeBSD. Here we provide support 43156952Sume for the special GCC options -static and -shared, which allow us to 44156952Sume link things in one of these three modes by applying the appropriate 45156952Sume combinations of options at link-time. We like to support here for 46156952Sume as many of the other GNU linker options as possible. But I don't 47156952Sume have the time to search for those flags. I am sure how to add 48156952Sume support for -soname shared_object_name. H.J. 49170244Sume 50156952Sume When the -shared link option is used a final link is not being 51156956Sume done. */ 52156956Sume 53156952Sume#undef LINK_SPEC 54156952Sume#define LINK_SPEC "\ 55156952Sume %{p:%e`-p' not supported; use `-pg' and gprof(1)} \ 56156956Sume %{maout: %{shared:-Bshareable} \ 57156952Sume %{!shared:%{!nostdlib:%{!r:%{!e*:-e start}}} -dc -dp %{static:-Bstatic} \ 58156952Sume %{pg:-Bstatic} %{Z}} \ 59156952Sume %{assert*} %{R*}} \ 60156952Sume %{!maout: \ 61156952Sume %{Wl,*:%*} \ 62156952Sume %{v:-V} \ 63156952Sume %{assert*} %{R*} %{rpath*} %{defsym*} \ 64156952Sume %{shared:-Bshareable %{h*} %{soname*}} \ 65156952Sume %{!shared: \ 66156952Sume %{!static: \ 67156952Sume %{rdynamic: -export-dynamic} \ 68156956Sume %{!dynamic-linker: -dynamic-linker /usr/libexec/ld-elf.so.1}} \ 69156952Sume %{static:-Bstatic}} \ 70156952Sume %{symbolic:-Bsymbolic}}" 71156952Sume 72156952Sume/* Provide a STARTFILE_SPEC appropriate for FreeBSD. Here we add the magical 73156952Sume crtbegin.o file (see crtstuff.c) which provides part of the support for 74170244Sume getting C++ file-scope static object constructed before entering `main'. */ 75170244Sume 76170244Sume#undef STARTFILE_SPEC 77170244Sume#define STARTFILE_SPEC "\ 78156952Sume %{maout: %{shared:c++rt0.o%s} \ 79156956Sume %{!shared: \ 80156952Sume %{pg:gcrt0.o%s}%{!pg: \ 81156952Sume %{static:scrt0.o%s} \ 82156952Sume %{!static:crt0.o%s}}}} \ 83156952Sume %{!maout: \ 84170244Sume %{!shared: \ 85156952Sume %{pg:gcrt1.o%s} \ 86156952Sume %{!pg: \ 87156952Sume %{p:gcrt1.o%s} \ 88156952Sume %{!p:crt1.o%s}}} \ 89156952Sume crti.o%s \ 90156952Sume %{!shared:crtbegin.o%s} \ 91156952Sume %{shared:crtbeginS.o%s}}" 92156952Sume 93156952Sume/* Provide an ENDFILE_SPEC appropriate for FreeBSD/i386. Here we tack on our 94156952Sume own magical crtend.o file (see crtstuff.c) which provides part of the 95156952Sume support for getting C++ file-scope static object constructed before 96156952Sume entering `main', followed by the normal "finalizer" file, `crtn.o'. */ 97156952Sume 98156952Sume#undef ENDFILE_SPEC 99156952Sume#define ENDFILE_SPEC "\ 100156952Sume %{!maout: \ 101156952Sume %{!shared:crtend.o%s} \ 102156952Sume %{shared:crtendS.o%s} crtn.o%s}" 103156952Sume 104156952Sume/* FreeBSD conditionalizes the use of ".section rodata" depending on 105156952Sume ELF mode - otherwise .text. */ 106156952Sume#undef USE_CONST_SECTION 107156952Sume#define USE_CONST_SECTION TARGET_ELF 108156952Sume 109156952Sume/* ".string" doesn't work for the aout case. */ 110156956Sume#undef STRING_ASM_OP 111156952Sume#define STRING_ASM_OP (TARGET_AOUT ? "\t.asciz\t" : "\t.string\t") 112156952Sume 113170244Sume 114156952Sume/************************[ Target stuff ]***********************************/ 115156952Sume 116156952Sume/* Define the actual types of some ANSI-mandated types. 117156952Sume Needs to agree with <machine/ansi.h>. GCC defaults come from c-decl.c, 118156952Sume c-common.c, and config/<arch>/<arch>.h. */ 119156952Sume 120156952Sume#undef SIZE_TYPE 121156952Sume#define SIZE_TYPE "unsigned int" 122156952Sume 123156952Sume#undef PTRDIFF_TYPE 124156952Sume#define PTRDIFF_TYPE "int" 125170244Sume 126170244Sume#undef WCHAR_TYPE_SIZE 127#define WCHAR_TYPE_SIZE BITS_PER_WORD 128 129#undef TARGET_VERSION 130#define TARGET_VERSION fprintf (stderr, " (i386 FreeBSD/ELF)"); 131 132#define MASK_PROFILER_EPILOGUE 010000000000 133#define MASK_AOUT 004000000000 /* a.out not elf */ 134#define MASK_UNDERSCORES 002000000000 /* use leading _ */ 135 136#define TARGET_PROFILER_EPILOGUE (target_flags & MASK_PROFILER_EPILOGUE) 137#define TARGET_AOUT (target_flags & MASK_AOUT) 138#define TARGET_ELF ((target_flags & MASK_AOUT) == 0) 139#define TARGET_UNDERSCORES ((target_flags & MASK_UNDERSCORES) != 0) 140 141#undef SUBTARGET_SWITCHES 142#define SUBTARGET_SWITCHES \ 143 { "profiler-epilogue", MASK_PROFILER_EPILOGUE, "Function profiler epilogue"}, \ 144 { "no-profiler-epilogue", -MASK_PROFILER_EPILOGUE, "No function profiler epilogue"}, \ 145 { "aout", MASK_AOUT, "Generate an a.out (vs. ELF) binary"}, \ 146 { "no-aout", -MASK_AOUT, "Do not generate an a.out binary"}, \ 147 { "underscores", MASK_UNDERSCORES, "Add leading underscores to symbols"}, \ 148 { "no-underscores", -MASK_UNDERSCORES, "Do not add leading underscores to symbols"}, 149 150/* This goes away when the math emulator is fixed. */ 151#undef TARGET_SUBTARGET_DEFAULT 152#define TARGET_SUBTARGET_DEFAULT \ 153 (MASK_80387 | MASK_IEEE_FP | MASK_FLOAT_RETURNS | MASK_NO_FANCY_MATH_387) 154 155/* Don't default to pcc-struct-return, we want to retain compatibility with 156 older gcc versions AND pcc-struct-return is nonreentrant. 157 (even though the SVR4 ABI for the i386 says that records and unions are 158 returned in memory). */ 159 160#undef DEFAULT_PCC_STRUCT_RETURN 161#define DEFAULT_PCC_STRUCT_RETURN 0 162 163/* The a.out tools do not support "linkonce" sections. */ 164#undef SUPPORTS_ONE_ONLY 165#define SUPPORTS_ONE_ONLY TARGET_ELF 166 167/* Prefix for internally generated assembler labels. If we aren't using 168 underscores, we are using prefix `.'s to identify labels that should 169 be ignored, as in `i386/gas.h' --karl@cs.umb.edu */ 170#undef LPREFIX 171#define LPREFIX ((TARGET_UNDERSCORES) ? "L" : ".L") 172 173/* supply our own hook for calling __main() from main() */ 174#undef INVOKE__main 175#define INVOKE__main 176#undef GEN_CALL__MAIN 177#define GEN_CALL__MAIN \ 178 do { \ 179 if (!(TARGET_ELF)) \ 180 emit_library_call (gen_rtx (SYMBOL_REF, Pmode, NAME__MAIN), 0, \ 181 VOIDmode, 0); \ 182 } while (0) 183 184/* Tell final.c that we don't need a label passed to mcount. */ 185#define NO_PROFILE_COUNTERS 1 186 187/* Output assembler code to FILE to begin profiling of the current function. 188 LABELNO is an optional label. */ 189 190#undef FUNCTION_PROFILER 191#define FUNCTION_PROFILER(FILE, LABELNO) \ 192 do { \ 193 char *_name = TARGET_AOUT ? "mcount" : ".mcount"; \ 194 if (flag_pic) \ 195 fprintf ((FILE), "\tcall *%s@GOT(%%ebx)\n", _name); \ 196 else \ 197 fprintf ((FILE), "\tcall %s\n", _name); \ 198 } while (0) 199 200/* Output assembler code to FILE to end profiling of the current function. */ 201 202#undef FUNCTION_PROFILER_EPILOGUE /* BDE will need to fix this. */ 203 204 205/************************[ Assembler stuff ]********************************/ 206 207/* Override the default comment-starter of "/" from unix.h. */ 208#undef ASM_COMMENT_START 209#define ASM_COMMENT_START "#" 210 211/* Override the default comment-starter of "/APP" from unix.h. */ 212#undef ASM_APP_ON 213#define ASM_APP_ON "#APP\n" 214#undef ASM_APP_OFF 215#define ASM_APP_OFF "#NO_APP\n" 216 217/* This is how to store into the string BUF 218 the symbol_ref name of an internal numbered label where 219 PREFIX is the class of label and NUM is the number within the class. 220 This is suitable for output with `assemble_name'. */ 221#undef ASM_GENERATE_INTERNAL_LABEL 222#define ASM_GENERATE_INTERNAL_LABEL(LABEL, PREFIX, NUM) \ 223 sprintf ((LABEL), "*%s%s%u", (TARGET_UNDERSCORES) ? "" : ".", \ 224 (PREFIX), (unsigned) (NUM)) 225 226/* This is how to output an internal numbered label where 227 PREFIX is the class of label and NUM is the number within the class. 228 For most svr4/ELF systems, the convention is that any symbol which begins 229 with a period is not put into the linker symbol table by the assembler. */ 230#undef ASM_OUTPUT_INTERNAL_LABEL 231#define ASM_OUTPUT_INTERNAL_LABEL(FILE, PREFIX, NUM) \ 232 fprintf ((FILE), "%s%s%u:\n", (TARGET_UNDERSCORES) ? "" : ".", \ 233 (PREFIX), (unsigned) (NUM)) 234 235/* This is how to output a reference to a user-level label named NAME. */ 236#undef ASM_OUTPUT_LABELREF 237#define ASM_OUTPUT_LABELREF(FILE, NAME) \ 238 do { \ 239 char *_name = (NAME); \ 240 /* Hack to avoid writing lots of rtl in \ 241 FUNCTION_PROFILER_EPILOGUE (). */ \ 242 if (*_name == '.' && strcmp(_name + 1, "mexitcount") == 0) \ 243 { \ 244 if (TARGET_AOUT) \ 245 _name++; \ 246 if (flag_pic) \ 247 fprintf ((FILE), "*%s@GOT(%%ebx)", _name); \ 248 else \ 249 fprintf ((FILE), "%s", _name); \ 250 } \ 251 else \ 252 fprintf (FILE, "%s%s", TARGET_UNDERSCORES ? "_" : "", _name); \ 253} while (0) 254 255/* This is how to hack on the symbol code of certain relcalcitrant 256 symbols to modify their output in output_pic_addr_const (). */ 257 258#undef ASM_HACK_SYMBOLREF_CODE /* BDE will need to fix this. */ 259 260#undef ASM_OUTPUT_ALIGN 261#define ASM_OUTPUT_ALIGN(FILE, LOG) \ 262 if ((LOG)!=0) { \ 263 if (in_text_section()) \ 264 fprintf ((FILE), "\t.p2align %d,0x90\n", (LOG)); \ 265 else \ 266 fprintf ((FILE), "\t.p2align %d\n", (LOG)); \ 267 } 268 269#undef ASM_OUTPUT_ALIGNED_COMMON 270#define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN) \ 271 do { \ 272 if (TARGET_ELF) \ 273 { \ 274 fprintf ((FILE), "%s", COMMON_ASM_OP); \ 275 assemble_name ((FILE), (NAME)); \ 276 fprintf ((FILE), ",%u,%u\n", (SIZE), (ALIGN) / BITS_PER_UNIT); \ 277 } \ 278 else \ 279 { \ 280 int rounded = (SIZE); \ 281 if (rounded == 0) rounded = 1; \ 282 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1; \ 283 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT) \ 284 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT)); \ 285 fprintf ((FILE), "%s ", COMMON_ASM_OP); \ 286 assemble_name ((FILE), (NAME)); \ 287 fprintf ((FILE), ",%u\n", (rounded)); \ 288 } \ 289 } while (0) 290 291/* This says how to output assembler code to declare an 292 uninitialized internal linkage data object. Under SVR4, 293 the linker seems to want the alignment of data objects 294 to depend on their types. We do exactly that here. */ 295 296#undef ASM_OUTPUT_ALIGNED_LOCAL 297#define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN) \ 298 do { \ 299 if (TARGET_ELF) \ 300 { \ 301 fprintf ((FILE), "%s", LOCAL_ASM_OP); \ 302 assemble_name ((FILE), (NAME)); \ 303 fprintf ((FILE), "\n"); \ 304 ASM_OUTPUT_ALIGNED_COMMON ((FILE), (NAME), (SIZE), (ALIGN)); \ 305 } \ 306 else \ 307 { \ 308 int rounded = (SIZE); \ 309 if (rounded == 0) rounded = 1; \ 310 rounded += (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1; \ 311 rounded = (rounded / (BIGGEST_ALIGNMENT / BITS_PER_UNIT) \ 312 * (BIGGEST_ALIGNMENT / BITS_PER_UNIT)); \ 313 fputs ("\t.lcomm\t", (FILE)); \ 314 assemble_name ((FILE), (NAME)); \ 315 fprintf ((FILE), ",%u\n", (rounded)); \ 316 } \ 317 } while (0) 318 319/* How to output some space. The rules are different depending on the 320 object format. */ 321#undef ASM_OUTPUT_SKIP 322#define ASM_OUTPUT_SKIP(FILE, SIZE) \ 323 do { \ 324 if (TARGET_ELF) \ 325 { \ 326 fprintf ((FILE), "%s%u\n", SKIP_ASM_OP, (SIZE)); \ 327 } \ 328 else \ 329 { \ 330 fprintf ((FILE), "\t.space\t%u\n", (SIZE)); \ 331 } \ 332 } while (0) 333 334#undef ASM_OUTPUT_SOURCE_LINE 335#define ASM_OUTPUT_SOURCE_LINE(FILE, LINE) \ 336 do { \ 337 static int sym_lineno = 1; \ 338 if (TARGET_ELF) \ 339 { \ 340 fprintf ((FILE), ".stabn 68,0,%d,.LM%d-", (LINE), sym_lineno); \ 341 assemble_name ((FILE), \ 342 XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0)); \ 343 fprintf ((FILE), "\n.LM%d:\n", sym_lineno); \ 344 sym_lineno += 1; \ 345 } \ 346 else \ 347 { \ 348 fprintf ((FILE), "\t%s %d,0,%d\n", ASM_STABD_OP, N_SLINE, \ 349 lineno); \ 350 } \ 351 } while (0) 352 353/* A C statement to output to the stdio stream FILE an assembler 354 command to advance the location counter to a multiple of 1<<LOG 355 bytes if it is within MAX_SKIP bytes. 356 357 This is used to align code labels according to Intel recommendations. */ 358 359/* XXX configuration of this is broken in the same way as HAVE_GAS_SHF_MERGE, 360 but it is easier to fix in an MD way. */ 361 362#ifdef HAVE_GAS_MAX_SKIP_P2ALIGN 363#define ASM_OUTPUT_MAX_SKIP_ALIGN(FILE, LOG, MAX_SKIP) \ 364do { \ 365 if ((LOG) != 0) { \ 366 if (TARGET_AOUT) \ 367 ASM_OUTPUT_ALIGN ((FILE), (LOG)); \ 368 else if ((MAX_SKIP) == 0) \ 369 fprintf ((FILE), "\t.p2align %d\n", (LOG)); \ 370 else \ 371 fprintf ((FILE), "\t.p2align %d,,%d\n", (LOG), (MAX_SKIP)); \ 372 } \ 373} while (0) 374#endif 375 376 377/************************[ Debugger stuff ]*********************************/ 378 379/* The a.out tools do not support "Lscope" .stabs symbols. */ 380#undef NO_DBX_FUNCTION_END 381#define NO_DBX_FUNCTION_END TARGET_AOUT 382 383/* In ELF, the function stabs come first, before the relative offsets. */ 384#undef DBX_FUNCTION_FIRST 385#define DBX_CHECK_FUNCTION_FIRST TARGET_ELF 386 387#undef DBX_REGISTER_NUMBER 388#define DBX_REGISTER_NUMBER(n) (TARGET_64BIT ? dbx64_register_map[n] \ 389 : (write_symbols == DWARF2_DEBUG \ 390 || write_symbols == DWARF_DEBUG) \ 391 ? svr4_dbx_register_map[(n)] \ 392 : dbx_register_map[(n)]) 393 394/* tag end of file in elf mode */ 395#undef DBX_OUTPUT_MAIN_SOURCE_FILE_END 396#define DBX_OUTPUT_MAIN_SOURCE_FILE_END(FILE, FILENAME) \ 397 do { \ 398 if (TARGET_ELF) { \ 399 fprintf ((FILE), "\t.text\n\t.stabs \"\",%d,0,0,%LLetext\n%LLetext:\n", \ 400 N_SO); \ 401 } \ 402 } while (0) 403 404/* stabs-in-elf has offsets relative to function beginning */ 405#undef DBX_OUTPUT_LBRAC 406#define DBX_OUTPUT_LBRAC(FILE, NAME) \ 407 do { \ 408 fprintf (asmfile, "%s %d,0,0,", ASM_STABN_OP, N_LBRAC); \ 409 assemble_name (asmfile, buf); \ 410 if (TARGET_ELF) \ 411 { \ 412 fputc ('-', asmfile); \ 413 assemble_name (asmfile, \ 414 XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0)); \ 415 } \ 416 fprintf (asmfile, "\n"); \ 417 } while (0) 418 419#undef DBX_OUTPUT_RBRAC 420#define DBX_OUTPUT_RBRAC(FILE, NAME) \ 421 do { \ 422 fprintf (asmfile, "%s %d,0,0,", ASM_STABN_OP, N_RBRAC); \ 423 assemble_name (asmfile, buf); \ 424 if (TARGET_ELF) \ 425 { \ 426 fputc ('-', asmfile); \ 427 assemble_name (asmfile, \ 428 XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0)); \ 429 } \ 430 fprintf (asmfile, "\n"); \ 431 } while (0) 432