PR rtl-optimization/26254
[official-gcc.git] / gcc / config / elfos.h
blob31e309d9b07f4377c9629ff4ab6b2d7aa44dc36f
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).
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 2, 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 COPYING. If not, write to
21 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
22 Boston, MA 02110-1301, USA. */
24 #define TARGET_OBJFMT_CPP_BUILTINS() \
25 do \
26 { \
27 builtin_define ("__ELF__"); \
28 } \
29 while (0)
31 /* Define a symbol indicating that we are using elfos.h.
32 Some CPU specific configuration files use this. */
33 #define USING_ELFOS_H
35 /* The prefix to add to user-visible assembler symbols.
37 For ELF systems the convention is *not* to prepend a leading
38 underscore onto user-level symbol names. */
40 #undef USER_LABEL_PREFIX
41 #define USER_LABEL_PREFIX ""
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
51 /* Use periods rather than dollar signs in special g++ assembler names. */
53 #define NO_DOLLAR_IN_LABEL
55 /* Writing `int' for a bit-field forces int alignment for the structure. */
57 #ifndef PCC_BITFIELD_TYPE_MATTERS
58 #define PCC_BITFIELD_TYPE_MATTERS 1
59 #endif
61 /* Handle #pragma weak and #pragma pack. */
63 #define HANDLE_SYSV_PRAGMA 1
65 /* All ELF targets can support DWARF-2. */
67 #define DWARF2_DEBUGGING_INFO 1
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. */
73 #ifndef PREFERRED_DEBUGGING_TYPE
74 #define PREFERRED_DEBUGGING_TYPE DWARF2_DEBUG
75 #endif
77 /* All SVR4 targets use the ELF object file format. */
78 #define OBJECT_FORMAT_ELF
81 /* Output #ident as a .ident. */
83 #define ASM_OUTPUT_IDENT(FILE, NAME) \
84 fprintf (FILE, "%s\"%s\"\n", IDENT_ASM_OP, NAME);
86 #define IDENT_ASM_OP "\t.ident\t"
88 #undef SET_ASM_OP
89 #define SET_ASM_OP "\t.set\t"
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
95 /* This is how to allocate empty space in some section. The .zero
96 pseudo-op is used for this on most svr4 assemblers. */
98 #define SKIP_ASM_OP "\t.zero\t"
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))
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'.
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. */
113 #undef ASM_GENERATE_INTERNAL_LABEL
114 #define ASM_GENERATE_INTERNAL_LABEL(LABEL, PREFIX, NUM) \
115 do \
117 sprintf (LABEL, "*.%s%u", PREFIX, (unsigned) (NUM)); \
119 while (0)
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. */
129 #undef ALIGN_ASM_OP
130 #define ALIGN_ASM_OP "\t.align\t"
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
137 #undef ASM_OUTPUT_CASE_LABEL
138 #define ASM_OUTPUT_CASE_LABEL(FILE, PREFIX, NUM, JUMPTABLE) \
139 do \
141 ASM_OUTPUT_BEFORE_CASE_LABEL (FILE, PREFIX, NUM, JUMPTABLE) \
142 (*targetm.asm_out.internal_label) (FILE, PREFIX, NUM); \
144 while (0)
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. */
150 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN) \
151 (*targetm.asm_out.globalize_label) (FILE, XSTR (FUN, 0))
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. */
158 #define COMMON_ASM_OP "\t.comm\t"
160 #undef ASM_OUTPUT_ALIGNED_COMMON
161 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN) \
162 do \
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); \
169 while (0)
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. */
176 #define LOCAL_ASM_OP "\t.local\t"
178 #undef ASM_OUTPUT_ALIGNED_LOCAL
179 #define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN) \
180 do \
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); \
187 while (0)
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. */
193 #undef ASCII_DATA_ASM_OP
194 #define ASCII_DATA_ASM_OP "\t.ascii\t"
196 /* Support a read-only data section. */
197 #define READONLY_DATA_SECTION_ASM_OP "\t.section\t.rodata"
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. */
205 #define INIT_SECTION_ASM_OP "\t.section\t.init"
206 #define FINI_SECTION_ASM_OP "\t.section\t.fini"
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
215 #define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1)
217 /* Switch into a generic section. */
218 #define TARGET_ASM_NAMED_SECTION default_elf_asm_named_section
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
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. */
233 #define TYPE_ASM_OP "\t.type\t"
234 #define SIZE_ASM_OP "\t.size\t"
236 /* This is how we tell the assembler that a symbol is weak. */
238 #define ASM_WEAKEN_LABEL(FILE, NAME) \
239 do \
241 fputs ("\t.weak\t", (FILE)); \
242 assemble_name ((FILE), (NAME)); \
243 fputc ('\n', (FILE)); \
245 while (0)
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). */
253 #define TYPE_OPERAND_FMT "@%s"
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. */
259 #ifndef ASM_DECLARE_RESULT
260 #define ASM_DECLARE_RESULT(FILE, RESULT)
261 #endif
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. */
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. */
272 #ifndef ASM_DECLARE_FUNCTION_NAME
273 #define ASM_DECLARE_FUNCTION_NAME(FILE, NAME, DECL) \
274 do \
276 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "function"); \
277 ASM_DECLARE_RESULT (FILE, DECL_RESULT (DECL)); \
278 ASM_OUTPUT_LABEL (FILE, NAME); \
280 while (0)
281 #endif
283 /* Write the extra assembler code needed to declare an object properly. */
285 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL) \
286 do \
288 HOST_WIDE_INT size; \
290 ASM_OUTPUT_TYPE_DIRECTIVE (FILE, NAME, "object"); \
292 size_directive_output = 0; \
293 if (!flag_inhibit_size_directive \
294 && (DECL) && DECL_SIZE (DECL)) \
296 size_directive_output = 1; \
297 size = int_size_in_bytes (TREE_TYPE (DECL)); \
298 ASM_OUTPUT_SIZE_DIRECTIVE (FILE, NAME, size); \
301 ASM_OUTPUT_LABEL (FILE, NAME); \
303 while (0)
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. */
311 #undef ASM_FINISH_DECLARE_OBJECT
312 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END)\
313 do \
315 const char *name = XSTR (XEXP (DECL_RTL (DECL), 0), 0); \
316 HOST_WIDE_INT size; \
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) \
324 size_directive_output = 1; \
325 size = int_size_in_bytes (TREE_TYPE (DECL)); \
326 ASM_OUTPUT_SIZE_DIRECTIVE (FILE, name, size); \
329 while (0)
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 \
336 if (!flag_inhibit_size_directive) \
337 ASM_OUTPUT_MEASURED_SIZE (FILE, FNAME); \
339 while (0)
340 #endif
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. */
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"
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.
374 If your target assembler doesn't support the .string directive, you
375 should define this to zero.
378 #define STRING_LIMIT ((unsigned) 256)
380 #define STRING_ASM_OP "\t.string\t"
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). */
389 #define ASM_OUTPUT_LIMITED_STRING(FILE, STR) \
390 do \
392 register const unsigned char *_limited_str = \
393 (const unsigned char *) (STR); \
394 register unsigned ch; \
396 fprintf ((FILE), "%s\"", STRING_ASM_OP); \
398 for (; (ch = *_limited_str); _limited_str++) \
400 register int escape; \
402 switch (escape = ESCAPES[ch]) \
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; \
417 fprintf ((FILE), "\"\n"); \
419 while (0)
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. */
428 #undef ASM_OUTPUT_ASCII
429 #define ASM_OUTPUT_ASCII(FILE, STR, LENGTH) \
430 do \
432 register const unsigned char *_ascii_bytes = \
433 (const unsigned char *) (STR); \
434 register const unsigned char *limit = _ascii_bytes + (LENGTH); \
435 register unsigned bytes_in_chunk = 0; \
437 for (; _ascii_bytes < limit; _ascii_bytes++) \
439 register const unsigned char *p; \
441 if (bytes_in_chunk >= 60) \
443 fprintf ((FILE), "\"\n"); \
444 bytes_in_chunk = 0; \
447 for (p = _ascii_bytes; p < limit && *p != '\0'; p++) \
448 continue; \
450 if (p < limit && (p - _ascii_bytes) <= (long)STRING_LIMIT) \
452 if (bytes_in_chunk > 0) \
454 fprintf ((FILE), "\"\n"); \
455 bytes_in_chunk = 0; \
458 ASM_OUTPUT_LIMITED_STRING ((FILE), _ascii_bytes); \
459 _ascii_bytes = p; \
461 else \
463 register int escape; \
464 register unsigned ch; \
466 if (bytes_in_chunk == 0) \
467 fprintf ((FILE), "%s\"", ASCII_DATA_ASM_OP); \
469 switch (escape = ESCAPES[ch = *_ascii_bytes]) \
471 case 0: \
472 putc (ch, (FILE)); \
473 bytes_in_chunk++; \
474 break; \
475 case 1: \
476 fprintf ((FILE), "\\%03o", ch); \
477 bytes_in_chunk += 4; \
478 break; \
479 default: \
480 putc ('\\', (FILE)); \
481 putc (escape, (FILE)); \
482 bytes_in_chunk += 2; \
483 break; \
488 if (bytes_in_chunk > 0) \
489 fprintf ((FILE), "\"\n"); \
491 while (0)