1/* elfos.h -- operating system specific defines to be used when 2 targeting GCC for some generic ELF system 3 Copyright (C) 1991, 1994, 1995, 1999, 2000, 2001, 2002, 2003, 2004 4 Free Software Foundation, Inc. 5 Based on svr4.h contributed by Ron Guilmette (rfg@netcom.com). 6 7This file is part of GCC. 8 9GCC is free software; you can redistribute it and/or modify 10it under the terms of the GNU General Public License as published by 11the Free Software Foundation; either version 2, or (at your option) 12any later version. 13 14GCC is distributed in the hope that it will be useful, 15but WITHOUT ANY WARRANTY; without even the implied warranty of 16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17GNU General Public License for more details. 18 19You should have received a copy of the GNU General Public License 20along with GCC; see the file COPYING. If not, write to 21the Free Software Foundation, 51 Franklin Street, Fifth Floor, 22Boston, MA 02110-1301, USA. */ 23 24#define TARGET_OBJFMT_CPP_BUILTINS() \ 25 do \ 26 { \ 27 builtin_define ("__ELF__"); \ 28 } \ 29 while (0) 30 31/* Define a symbol indicating that we are using elfos.h. 32 Some CPU specific configuration files use this. */ 33#define USING_ELFOS_H 34 35/* The prefix to add to user-visible assembler symbols. 36 37 For ELF systems the convention is *not* to prepend a leading 38 underscore onto user-level symbol names. */ 39 40#undef USER_LABEL_PREFIX 41#define USER_LABEL_PREFIX "" 42 43/* Biggest alignment supported by the object file format of this 44 machine. Use this macro to limit the alignment which can be 45 specified using the `__attribute__ ((aligned (N)))' construct. If 46 not defined, the default value is `BIGGEST_ALIGNMENT'. */ 47#ifndef MAX_OFILE_ALIGNMENT 48#define MAX_OFILE_ALIGNMENT (32768 * 8) 49#endif 50 51/* Use periods rather than dollar signs in special g++ assembler names. */ 52 53#define NO_DOLLAR_IN_LABEL 54 55/* Writing `int' for a bit-field forces int alignment for the structure. */ 56 57#ifndef PCC_BITFIELD_TYPE_MATTERS 58#define PCC_BITFIELD_TYPE_MATTERS 1 59#endif 60 61/* Handle #pragma weak and #pragma pack. */ 62 63#define HANDLE_SYSV_PRAGMA 1 64 65/* All ELF targets can support DWARF-2. */ 66 67#define DWARF2_DEBUGGING_INFO 1 68 69/* The GNU tools operate better with dwarf2, and it is required by some 70 psABI's. Since we don't have any native tools to be compatible with, 71 default to dwarf2. */ 72 73#ifndef PREFERRED_DEBUGGING_TYPE 74#define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG 75#endif 76 77/* All SVR4 targets use the ELF object file format. */ 78#define OBJECT_FORMAT_ELF 79 80 81/* Output #ident as a .ident. */ 82 83#define ASM_OUTPUT_IDENT(FILE, NAME) \ 84 fprintf (FILE, "%s\"%s\"\n", IDENT_ASM_OP, NAME); 85 86#define IDENT_ASM_OP "\t.ident\t" 87 88#undef SET_ASM_OP 89#define SET_ASM_OP "\t.set\t" 90 91/* Most svr4 assemblers want a .file directive at the beginning of 92 their input file. */ 93#define TARGET_ASM_FILE_START_FILE_DIRECTIVE true 94 95/* This is how to allocate empty space in some section. The .zero 96 pseudo-op is used for this on most svr4 assemblers. */ 97 98#define SKIP_ASM_OP "\t.zero\t" 99 100#undef ASM_OUTPUT_SKIP 101#define ASM_OUTPUT_SKIP(FILE, SIZE) \ 102 fprintf ((FILE), "%s"HOST_WIDE_INT_PRINT_UNSIGNED"\n",\ 103 SKIP_ASM_OP, (SIZE)) 104 105/* This is how to store into the string LABEL 106 the symbol_ref name of an internal numbered label where 107 PREFIX is the class of label and NUM is the number within the class. 108 This is suitable for output with `assemble_name'. 109 110 For most svr4 systems, the convention is that any symbol which begins 111 with a period is not put into the linker symbol table by the assembler. */ 112 113#undef ASM_GENERATE_INTERNAL_LABEL 114#define ASM_GENERATE_INTERNAL_LABEL(LABEL, PREFIX, NUM) \ 115 do \ 116 { \ 117 sprintf (LABEL, "*.%s%u", PREFIX, (unsigned) (NUM)); \ 118 } \ 119 while (0) 120 121/* Output the label which precedes a jumptable. Note that for all svr4 122 systems where we actually generate jumptables (which is to say every 123 svr4 target except i386, where we use casesi instead) we put the jump- 124 tables into the .rodata section and since other stuff could have been 125 put into the .rodata section prior to any given jumptable, we have to 126 make sure that the location counter for the .rodata section gets pro- 127 perly re-aligned prior to the actual beginning of the jump table. */ 128 129#undef ALIGN_ASM_OP 130#define ALIGN_ASM_OP "\t.align\t" 131 132#ifndef ASM_OUTPUT_BEFORE_CASE_LABEL 133#define ASM_OUTPUT_BEFORE_CASE_LABEL(FILE, PREFIX, NUM, TABLE) \ 134 ASM_OUTPUT_ALIGN ((FILE), 2); 135#endif 136 137#undef ASM_OUTPUT_CASE_LABEL 138#define ASM_OUTPUT_CASE_LABEL(FILE, PREFIX, NUM, JUMPTABLE) \ 139 do \ 140 { \ 141 ASM_OUTPUT_BEFORE_CASE_LABEL (FILE, PREFIX, NUM, JUMPTABLE) \ 142 (*targetm.asm_out.internal_label) (FILE, PREFIX, NUM); \ 143 } \ 144 while (0) 145 146/* The standard SVR4 assembler seems to require that certain builtin 147 library routines (e.g. .udiv) be explicitly declared as .globl 148 in each assembly file where they are referenced. */ 149 150#define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \ 151 (*targetm.asm_out.globalize_label) (FILE, XSTR (FUN, 0)) 152 153/* This says how to output assembler code to declare an 154 uninitialized external linkage data object. Under SVR4, 155 the linker seems to want the alignment of data objects 156 to depend on their types. We do exactly that here. */ 157 158#define COMMON_ASM_OP "\t.comm\t" 159 160#undef ASM_OUTPUT_ALIGNED_COMMON 161#define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN) \ 162 do \ 163 { \ 164 fprintf ((FILE), "%s", COMMON_ASM_OP); \ 165 assemble_name ((FILE), (NAME)); \ 166 fprintf ((FILE), ","HOST_WIDE_INT_PRINT_UNSIGNED",%u\n", \ 167 (SIZE), (ALIGN) / BITS_PER_UNIT); \ 168 } \ 169 while (0) 170 171/* This says how to output assembler code to declare an 172 uninitialized internal linkage data object. Under SVR4, 173 the linker seems to want the alignment of data objects 174 to depend on their types. We do exactly that here. */ 175 176#define LOCAL_ASM_OP "\t.local\t" 177 178#undef ASM_OUTPUT_ALIGNED_LOCAL 179#define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN) \ 180 do \ 181 { \ 182 fprintf ((FILE), "%s", LOCAL_ASM_OP); \ 183 assemble_name ((FILE), (NAME)); \ 184 fprintf ((FILE), "\n"); \ 185 ASM_OUTPUT_ALIGNED_COMMON (FILE, NAME, SIZE, ALIGN); \ 186 } \ 187 while (0) 188 189/* This is the pseudo-op used to generate a contiguous sequence of byte 190 values from a double-quoted string WITHOUT HAVING A TERMINATING NUL 191 AUTOMATICALLY APPENDED. This is the same for most svr4 assemblers. */ 192 193#undef ASCII_DATA_ASM_OP 194#define ASCII_DATA_ASM_OP "\t.ascii\t" 195 196/* Support a read-only data section. */ 197#define READONLY_DATA_SECTION_ASM_OP "\t.section\t.rodata" 198 199/* On svr4, we *do* have support for the .init and .fini sections, and we 200 can put stuff in there to be executed before and after `main'. We let 201 crtstuff.c and other files know this by defining the following symbols. 202 The definitions say how to change sections to the .init and .fini 203 sections. This is the same for all known svr4 assemblers. */ 204 205#define INIT_SECTION_ASM_OP "\t.section\t.init" 206#define FINI_SECTION_ASM_OP "\t.section\t.fini" 207 208/* Output assembly directive to move to the beginning of current section. */ 209#ifdef HAVE_GAS_SUBSECTION_ORDERING 210# define ASM_SECTION_START_OP "\t.subsection\t-1" 211# define ASM_OUTPUT_SECTION_START(FILE) \ 212 fprintf ((FILE), "%s\n", ASM_SECTION_START_OP) 213#endif 214 215#define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1) 216 217/* Switch into a generic section. */ 218#define TARGET_ASM_NAMED_SECTION default_elf_asm_named_section 219 220#undef TARGET_ASM_SELECT_RTX_SECTION 221#define TARGET_ASM_SELECT_RTX_SECTION default_elf_select_rtx_section 222#undef TARGET_ASM_SELECT_SECTION 223#define TARGET_ASM_SELECT_SECTION default_elf_select_section 224#undef TARGET_HAVE_SWITCHABLE_BSS_SECTIONS 225#define TARGET_HAVE_SWITCHABLE_BSS_SECTIONS true 226 227/* Define the strings used for the special svr4 .type and .size directives. 228 These strings generally do not vary from one system running svr4 to 229 another, but if a given system (e.g. m88k running svr) needs to use 230 different pseudo-op names for these, they may be overridden in the 231 file which includes this one. */ 232 233#define TYPE_ASM_OP "\t.type\t" 234#define SIZE_ASM_OP "\t.size\t" 235 236/* This is how we tell the assembler that a symbol is weak. */ 237 238#define ASM_WEAKEN_LABEL(FILE, NAME) \ 239 do \ 240 { \ 241 fputs ("\t.weak\t", (FILE)); \ 242 assemble_name ((FILE), (NAME)); \ 243 fputc ('\n', (FILE)); \ 244 } \ 245 while (0) 246 247/* The following macro defines the format used to output the second 248 operand of the .type assembler directive. Different svr4 assemblers 249 expect various different forms for this operand. The one given here 250 is just a default. You may need to override it in your machine- 251 specific tm.h file (depending upon the particulars of your assembler). */ 252 253#define TYPE_OPERAND_FMT "@%s" 254 255/* Write the extra assembler code needed to declare a function's result. 256 Most svr4 assemblers don't require any special declaration of the 257 result value, but there are exceptions. */ 258 259#ifndef ASM_DECLARE_RESULT 260#define ASM_DECLARE_RESULT(FILE, RESULT) 261#endif 262 263/* These macros generate the special .type and .size directives which 264 are used to set the corresponding fields of the linker symbol table 265 entries in an ELF object file under SVR4. These macros also output 266 the starting labels for the relevant functions/objects. */ 267 268/* Write the extra assembler code needed to declare a function properly. 269 Some svr4 assemblers need to also have something extra said about the 270 function's return value. We allow for that here. */ 271 272#ifndef ASM_DECLARE_FUNCTION_NAME 273#define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \ 274 do \ 275 { \ 276 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function"); \ 277 ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL)); \ 278 ASM_OUTPUT_LABEL (FILE, NAME); \ 279 } \ 280 while (0) 281#endif 282 283/* Write the extra assembler code needed to declare an object properly. */ 284 285#define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \ 286 do \ 287 { \ 288 HOST_WIDE_INT size; \ 289 \ 290 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object"); \ 291 \ 292 size_directive_output = 0; \ 293 if (!flag_inhibit_size_directive \ 294 && (DECL) && DECL_SIZE (DECL)) \ 295 { \ 296 size_directive_output = 1; \ 297 size = int_size_in_bytes (TREE_TYPE (DECL)); \ 298 ASM_OUTPUT_SIZE_DIRECTIVE (FILE, NAME, size); \ 299 } \ 300 \ 301 ASM_OUTPUT_LABEL (FILE, NAME); \ 302 } \ 303 while (0) 304 305/* Output the size directive for a decl in rest_of_decl_compilation 306 in the case where we did not do so before the initializer. 307 Once we find the error_mark_node, we know that the value of 308 size_directive_output was set 309 by ASM_DECLARE_OBJECT_NAME when it was run for the same decl. */ 310 311#undef ASM_FINISH_DECLARE_OBJECT 312#define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END)\ 313 do \ 314 { \ 315 const char *name = XSTR (XEXP (DECL_RTL (DECL), 0), 0); \ 316 HOST_WIDE_INT size; \ 317 \ 318 if (!flag_inhibit_size_directive \ 319 && DECL_SIZE (DECL) \ 320 && ! AT_END && TOP_LEVEL \ 321 && DECL_INITIAL (DECL) == error_mark_node \ 322 && !size_directive_output) \ 323 { \ 324 size_directive_output = 1; \ 325 size = int_size_in_bytes (TREE_TYPE (DECL)); \ 326 ASM_OUTPUT_SIZE_DIRECTIVE (FILE, name, size); \ 327 } \ 328 } \ 329 while (0) 330 331/* This is how to declare the size of a function. */ 332#ifndef ASM_DECLARE_FUNCTION_SIZE 333#define ASM_DECLARE_FUNCTION_SIZE(FILE, FNAME, DECL) \ 334 do \ 335 { \ 336 if (!flag_inhibit_size_directive) \ 337 ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME); \ 338 } \ 339 while (0) 340#endif 341 342/* A table of bytes codes used by the ASM_OUTPUT_ASCII and 343 ASM_OUTPUT_LIMITED_STRING macros. Each byte in the table 344 corresponds to a particular byte value [0..255]. For any 345 given byte value, if the value in the corresponding table 346 position is zero, the given character can be output directly. 347 If the table value is 1, the byte must be output as a \ooo 348 octal escape. If the tables value is anything else, then the 349 byte value should be output as a \ followed by the value 350 in the table. Note that we can use standard UN*X escape 351 sequences for many control characters, but we don't use 352 \a to represent BEL because some svr4 assemblers (e.g. on 353 the i386) don't know about that. Also, we don't use \v 354 since some versions of gas, such as 2.2 did not accept it. */ 355 356#define ESCAPES \ 357"\1\1\1\1\1\1\1\1btn\1fr\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\ 358\0\0\"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\ 359\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\\\0\0\0\ 360\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1\ 361\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\ 362\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\ 363\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\ 364\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1" 365 366/* Some svr4 assemblers have a limit on the number of characters which 367 can appear in the operand of a .string directive. If your assembler 368 has such a limitation, you should define STRING_LIMIT to reflect that 369 limit. Note that at least some svr4 assemblers have a limit on the 370 actual number of bytes in the double-quoted string, and that they 371 count each character in an escape sequence as one byte. Thus, an 372 escape sequence like \377 would count as four bytes. 373 374 If your target assembler doesn't support the .string directive, you 375 should define this to zero. 376*/ 377 378#define STRING_LIMIT ((unsigned) 256) 379 380#define STRING_ASM_OP "\t.string\t" 381 382/* The routine used to output NUL terminated strings. We use a special 383 version of this for most svr4 targets because doing so makes the 384 generated assembly code more compact (and thus faster to assemble) 385 as well as more readable, especially for targets like the i386 386 (where the only alternative is to output character sequences as 387 comma separated lists of numbers). */ 388 389#define ASM_OUTPUT_LIMITED_STRING(FILE, STR) \ 390 do \ 391 { \ 392 register const unsigned char *_limited_str = \ 393 (const unsigned char *) (STR); \ 394 register unsigned ch; \ 395 \ 396 fprintf ((FILE), "%s\"", STRING_ASM_OP); \ 397 \ 398 for (; (ch = *_limited_str); _limited_str++) \ 399 { \ 400 register int escape; \ 401 \ 402 switch (escape = ESCAPES[ch]) \ 403 { \ 404 case 0: \ 405 putc (ch, (FILE)); \ 406 break; \ 407 case 1: \ 408 fprintf ((FILE), "\\%03o", ch); \ 409 break; \ 410 default: \ 411 putc ('\\', (FILE)); \ 412 putc (escape, (FILE)); \ 413 break; \ 414 } \ 415 } \ 416 \ 417 fprintf ((FILE), "\"\n"); \ 418 } \ 419 while (0) 420 421/* The routine used to output sequences of byte values. We use a special 422 version of this for most svr4 targets because doing so makes the 423 generated assembly code more compact (and thus faster to assemble) 424 as well as more readable. Note that if we find subparts of the 425 character sequence which end with NUL (and which are shorter than 426 STRING_LIMIT) we output those using ASM_OUTPUT_LIMITED_STRING. */ 427 428#undef ASM_OUTPUT_ASCII 429#define ASM_OUTPUT_ASCII(FILE, STR, LENGTH) \ 430 do \ 431 { \ 432 const unsigned char *_ascii_bytes = \ 433 (const unsigned char *) (STR); \ 434 const unsigned char *limit = _ascii_bytes + (LENGTH); \ 435 const unsigned char *last_null = NULL; \ 436 unsigned bytes_in_chunk = 0; \ 437 \ 438 for (; _ascii_bytes < limit; _ascii_bytes++) \ 439 { \ 440 const unsigned char *p; \ 441 \ 442 if (bytes_in_chunk >= 60) \ 443 { \ 444 fprintf ((FILE), "\"\n"); \ 445 bytes_in_chunk = 0; \ 446 } \ 447 \ 448 if (_ascii_bytes > last_null) \ 449 { \ 450 for (p = _ascii_bytes; p < limit && *p != '\0'; p++) \ 451 continue; \ 452 last_null = p; \ 453 } \ 454 else \ 455 p = last_null; \ 456 \ 457 if (p < limit && (p - _ascii_bytes) <= (long)STRING_LIMIT) \ 458 { \ 459 if (bytes_in_chunk > 0) \ 460 { \ 461 fprintf ((FILE), "\"\n"); \ 462 bytes_in_chunk = 0; \ 463 } \ 464 \ 465 ASM_OUTPUT_LIMITED_STRING ((FILE), _ascii_bytes); \ 466 _ascii_bytes = p; \ 467 } \ 468 else \ 469 { \ 470 register int escape; \ 471 register unsigned ch; \ 472 \ 473 if (bytes_in_chunk == 0) \ 474 fprintf ((FILE), "%s\"", ASCII_DATA_ASM_OP); \ 475 \ 476 switch (escape = ESCAPES[ch = *_ascii_bytes]) \ 477 { \ 478 case 0: \ 479 putc (ch, (FILE)); \ 480 bytes_in_chunk++; \ 481 break; \ 482 case 1: \ 483 fprintf ((FILE), "\\%03o", ch); \ 484 bytes_in_chunk += 4; \ 485 break; \ 486 default: \ 487 putc ('\\', (FILE)); \ 488 putc (escape, (FILE)); \ 489 bytes_in_chunk += 2; \ 490 break; \ 491 } \ 492 } \ 493 } \ 494 \ 495 if (bytes_in_chunk > 0) \ 496 fprintf ((FILE), "\"\n"); \ 497 } \ 498 while (0) 499 500/* A C statement (sans semicolon) to output to the stdio stream STREAM 501 any text necessary for declaring the name of an external symbol 502 named NAME whch is referenced in this compilation but not defined. 503 It is needed to properly support non-default visibility. */ 504 505#ifndef ASM_OUTPUT_EXTERNAL 506#define ASM_OUTPUT_EXTERNAL(FILE, DECL, NAME) \ 507 default_elf_asm_output_external (FILE, DECL, NAME) 508#endif 509