OSDN Git Service

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