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