OSDN Git Service

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