OSDN Git Service

abf12bcc22f0b3e28fd58e2830f7f0d37ca05a01
[pf3gnuchains/gcc-fork.git] / gcc / config / alpha / elf.h
1 /* Definitions of target machine for GNU compiler, for DEC Alpha w/ELF.
2    Copyright (C) 1996 Free Software Foundation, Inc.
3    Contributed by Richard Henderson (rth@tamu.edu).
4
5 This file is part of GNU CC.
6
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING.  If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA.    */
21
22 /* This is used on Alpha platforms that use the ELF format.
23 Currently only Linux uses this. */
24
25 #undef TARGET_VERSION
26 #define TARGET_VERSION fprintf (stderr, " (Alpha Linux/ELF)");
27
28 #undef OBJECT_FORMAT_COFF
29 #undef EXTENDED_COFF
30 #define OBJECT_FORMAT_ELF
31
32 #define SDB_DEBUGGING_INFO
33
34 #undef ASM_FINAL_SPEC
35
36 #undef CPP_PREDEFINES
37 #define CPP_PREDEFINES "\
38 -D__alpha -D__alpha__ -D__linux__ -D__linux -D_LONGLONG -Dlinux -Dunix \
39 -Asystem(linux) -Acpu(alpha) -Amachine(alpha) -D__ELF__"
40
41 #undef LINK_SPEC
42 #define LINK_SPEC "-m elf64_alpha -G 8 %{O*:-O3} %{!O*:-O1}     \
43   %{shared:-shared}                                             \
44   %{!shared:                                                    \
45     %{!static:                                                  \
46       %{rdynamic:-export-dynamic}                               \
47       %{!dynamic-linker:-dynamic-linker /lib/ld-gnu.so.1}}      \
48     %{static:-static}}"
49
50 /* Output at beginning of assembler file.  */
51
52 #undef ASM_FILE_START
53 #define ASM_FILE_START(FILE)                                    \
54 {                                                               \
55   alpha_write_verstamp (FILE);                                  \
56   output_file_directive (FILE, main_input_filename);            \
57   fprintf (FILE, "\t.version\t\"01.01\"\n");                    \
58   fprintf (FILE, "\t.set noat\n");                              \
59 }
60
61 #define ASM_OUTPUT_SOURCE_LINE(STREAM, LINE)                            \
62   alpha_output_lineno (STREAM, LINE)
63 extern void alpha_output_lineno ();
64
65 extern void output_file_directive ();
66
67 /* Attach a special .ident directive to the end of the file to identify
68    the version of GCC which compiled this code.  The format of the
69    .ident string is patterned after the ones produced by native svr4
70    C compilers.  */
71
72 #define IDENT_ASM_OP ".ident"
73
74 #ifdef IDENTIFY_WITH_IDENT
75 #define ASM_IDENTIFY_GCC(FILE) /* nothing */
76 #define ASM_IDENTIFY_LANGUAGE(FILE)                     \
77  fprintf(FILE, "\t%s \"GCC (%s) %s\"\n", IDENT_ASM_OP,  \
78          lang_identify(), version_string)
79 #else
80 #define ASM_FILE_END(FILE)                                      \
81 do {                                                            \
82      fprintf ((FILE), "\t%s\t\"GCC: (GNU) %s\"\n",              \
83               IDENT_ASM_OP, version_string);                    \
84    } while (0)
85 #endif
86
87 /* Allow #sccs in preprocessor.  */
88
89 #define SCCS_DIRECTIVE
90
91 /* Output #ident as a .ident.  */
92
93 #define ASM_OUTPUT_IDENT(FILE, NAME) \
94   fprintf (FILE, "\t%s\t\"%s\"\n", IDENT_ASM_OP, NAME);
95
96 /* This is how to allocate empty space in some section.  The .zero
97    pseudo-op is used for this on most svr4 assemblers.  */
98
99 #define SKIP_ASM_OP     ".zero"
100
101 #undef ASM_OUTPUT_SKIP
102 #define ASM_OUTPUT_SKIP(FILE,SIZE) \
103   fprintf (FILE, "\t%s\t%u\n", SKIP_ASM_OP, (SIZE))
104
105 /* Output the label which precedes a jumptable.  Note that for all svr4
106    systems where we actually generate jumptables (which is to say every
107    svr4 target except i386, where we use casesi instead) we put the jump-
108    tables into the .rodata section and since other stuff could have been
109    put into the .rodata section prior to any given jumptable, we have to
110    make sure that the location counter for the .rodata section gets pro-
111    perly re-aligned prior to the actual beginning of the jump table.  */
112
113 #define ALIGN_ASM_OP ".align"
114
115 #ifndef ASM_OUTPUT_BEFORE_CASE_LABEL
116 #define ASM_OUTPUT_BEFORE_CASE_LABEL(FILE,PREFIX,NUM,TABLE) \
117   ASM_OUTPUT_ALIGN ((FILE), 2);
118 #endif
119
120 #undef ASM_OUTPUT_CASE_LABEL
121 #define ASM_OUTPUT_CASE_LABEL(FILE,PREFIX,NUM,JUMPTABLE)                \
122   do {                                                                  \
123     ASM_OUTPUT_BEFORE_CASE_LABEL (FILE, PREFIX, NUM, JUMPTABLE)         \
124     ASM_OUTPUT_INTERNAL_LABEL (FILE, PREFIX, NUM);                      \
125   } while (0)
126
127 /* The standard SVR4 assembler seems to require that certain builtin
128    library routines (e.g. .udiv) be explicitly declared as .globl
129    in each assembly file where they are referenced.  */
130
131 #define ASM_OUTPUT_EXTERNAL_LIBCALL(FILE, FUN)                          \
132   ASM_GLOBALIZE_LABEL (FILE, XSTR (FUN, 0))
133
134 /* This says how to output assembler code to declare an
135    uninitialized external linkage data object.  Under SVR4,
136    the linker seems to want the alignment of data objects
137    to depend on their types.  We do exactly that here.  */
138
139 #define COMMON_ASM_OP   ".comm"
140
141 #undef ASM_OUTPUT_ALIGNED_COMMON
142 #define ASM_OUTPUT_ALIGNED_COMMON(FILE, NAME, SIZE, ALIGN)              \
143 do {                                                                    \
144   fprintf ((FILE), "\t%s\t", COMMON_ASM_OP);                            \
145   assemble_name ((FILE), (NAME));                                       \
146   fprintf ((FILE), ",%u,%u\n", (SIZE), (ALIGN) / BITS_PER_UNIT);        \
147 } while (0)
148
149 /* This says how to output assembler code to declare an
150    uninitialized internal linkage data object.  Under SVR4,
151    the linker seems to want the alignment of data objects
152    to depend on their types.  We do exactly that here.  */
153
154 #define LOCAL_ASM_OP    ".local"
155
156 #undef ASM_OUTPUT_ALIGNED_LOCAL
157 #define ASM_OUTPUT_ALIGNED_LOCAL(FILE, NAME, SIZE, ALIGN)               \
158 do {                                                                    \
159   fprintf ((FILE), "\t%s\t", LOCAL_ASM_OP);                             \
160   assemble_name ((FILE), (NAME));                                       \
161   fprintf ((FILE), "\n");                                               \
162   ASM_OUTPUT_ALIGNED_COMMON (FILE, NAME, SIZE, ALIGN);                  \
163 } while (0)
164
165 /* This is the pseudo-op used to generate a 32-bit word of data with a
166    specific value in some section.  This is the same for all known svr4
167    assemblers.  */
168
169 #define INT_ASM_OP              ".long"
170
171 /* This is the pseudo-op used to generate a contiguous sequence of byte
172    values from a double-quoted string WITHOUT HAVING A TERMINATING NUL
173    AUTOMATICALLY APPENDED.  This is the same for most svr4 assemblers.  */
174
175 #undef ASCII_DATA_ASM_OP
176 #define ASCII_DATA_ASM_OP       ".ascii"
177
178 /* Support const sections and the ctors and dtors sections for g++.
179    Note that there appears to be two different ways to support const
180    sections at the moment.  You can either #define the symbol
181    READONLY_DATA_SECTION (giving it some code which switches to the
182    readonly data section) or else you can #define the symbols
183    EXTRA_SECTIONS, EXTRA_SECTION_FUNCTIONS, SELECT_SECTION, and
184    SELECT_RTX_SECTION.  We do both here just to be on the safe side.  */
185
186 #define USE_CONST_SECTION       1
187
188 #define CONST_SECTION_ASM_OP    ".section\t.rodata"
189
190 /* Define the pseudo-ops used to switch to the .ctors and .dtors sections.
191
192    Note that we want to give these sections the SHF_WRITE attribute
193    because these sections will actually contain data (i.e. tables of
194    addresses of functions in the current root executable or shared library
195    file) and, in the case of a shared library, the relocatable addresses
196    will have to be properly resolved/relocated (and then written into) by
197    the dynamic linker when it actually attaches the given shared library
198    to the executing process.  (Note that on SVR4, you may wish to use the
199    `-z text' option to the ELF linker, when building a shared library, as
200    an additional check that you are doing everything right.  But if you do
201    use the `-z text' option when building a shared library, you will get
202    errors unless the .ctors and .dtors sections are marked as writable
203    via the SHF_WRITE attribute.)  */
204
205 #define CTORS_SECTION_ASM_OP    ".section\t.ctors,\"aw\""
206 #define DTORS_SECTION_ASM_OP    ".section\t.dtors,\"aw\""
207
208 /* On svr4, we *do* have support for the .init and .fini sections, and we
209    can put stuff in there to be executed before and after `main'.  We let
210    crtstuff.c and other files know this by defining the following symbols.
211    The definitions say how to change sections to the .init and .fini
212    sections.  This is the same for all known svr4 assemblers.  */
213
214 #define INIT_SECTION_ASM_OP     ".section\t.init"
215 #define FINI_SECTION_ASM_OP     ".section\t.fini"
216
217 /* A default list of other sections which we might be "in" at any given
218    time.  For targets that use additional sections (e.g. .tdesc) you
219    should override this definition in the target-specific file which
220    includes this file.  */
221
222 #undef EXTRA_SECTIONS
223 #define EXTRA_SECTIONS in_const, in_ctors, in_dtors
224
225 /* A default list of extra section function definitions.  For targets
226    that use additional sections (e.g. .tdesc) you should override this
227    definition in the target-specific file which includes this file.  */
228
229 #undef EXTRA_SECTION_FUNCTIONS
230 #define EXTRA_SECTION_FUNCTIONS                                         \
231   CONST_SECTION_FUNCTION                                                \
232   CTORS_SECTION_FUNCTION                                                \
233   DTORS_SECTION_FUNCTION
234
235 #undef READONLY_DATA_SECTION
236 #define READONLY_DATA_SECTION() const_section ()
237
238 extern void text_section ();
239
240 #define CONST_SECTION_FUNCTION                                          \
241 void                                                                    \
242 const_section ()                                                        \
243 {                                                                       \
244   if (!USE_CONST_SECTION)                                               \
245     text_section();                                                     \
246   else if (in_section != in_const)                                      \
247     {                                                                   \
248       fprintf (asm_out_file, "%s\n", CONST_SECTION_ASM_OP);             \
249       in_section = in_const;                                            \
250     }                                                                   \
251 }
252
253 #define CTORS_SECTION_FUNCTION                                          \
254 void                                                                    \
255 ctors_section ()                                                        \
256 {                                                                       \
257   if (in_section != in_ctors)                                           \
258     {                                                                   \
259       fprintf (asm_out_file, "%s\n", CTORS_SECTION_ASM_OP);             \
260       in_section = in_ctors;                                            \
261     }                                                                   \
262 }
263
264 #define DTORS_SECTION_FUNCTION                                          \
265 void                                                                    \
266 dtors_section ()                                                        \
267 {                                                                       \
268   if (in_section != in_dtors)                                           \
269     {                                                                   \
270       fprintf (asm_out_file, "%s\n", DTORS_SECTION_ASM_OP);             \
271       in_section = in_dtors;                                            \
272     }                                                                   \
273 }
274
275 /* Switch into a generic section.
276    This is currently only used to support section attributes.
277
278    We make the section read-only and executable for a function decl,
279    read-only for a const data decl, and writable for a non-const data decl.  */
280 #define ASM_OUTPUT_SECTION_NAME(FILE, DECL, NAME) \
281   fprintf (FILE, ".section\t%s,\"%s\",@progbits\n", NAME, \
282            (DECL) && TREE_CODE (DECL) == FUNCTION_DECL ? "ax" : \
283            (DECL) && TREE_READONLY (DECL) ? "a" : "aw")
284
285
286 /* A C statement (sans semicolon) to output an element in the table of
287    global constructors.  */
288 #define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME)                               \
289   do {                                                                  \
290     ctors_section ();                                                   \
291     fprintf (FILE, "\t%s\t ", INT_ASM_OP);                              \
292     assemble_name (FILE, NAME);                                         \
293     fprintf (FILE, "\n");                                               \
294   } while (0)
295
296 /* A C statement (sans semicolon) to output an element in the table of
297    global destructors.  */
298 #define ASM_OUTPUT_DESTRUCTOR(FILE,NAME)                                \
299   do {                                                                  \
300     dtors_section ();                                                   \
301     fprintf (FILE, "\t%s\t ", INT_ASM_OP);                              \
302     assemble_name (FILE, NAME);                                         \
303     fprintf (FILE, "\n");                                               \
304   } while (0)
305
306 /* A C statement or statements to switch to the appropriate
307    section for output of DECL.  DECL is either a `VAR_DECL' node
308    or a constant of some sort.  RELOC indicates whether forming
309    the initial value of DECL requires link-time relocations.  */
310
311 #define SELECT_SECTION(DECL,RELOC)                                      \
312 {                                                                       \
313   if (TREE_CODE (DECL) == STRING_CST)                                   \
314     {                                                                   \
315       if (! flag_writable_strings)                                      \
316         const_section ();                                               \
317       else                                                              \
318         data_section ();                                                \
319     }                                                                   \
320   else if (TREE_CODE (DECL) == VAR_DECL)                                \
321     {                                                                   \
322       if ((flag_pic && RELOC)                                           \
323           || !TREE_READONLY (DECL) || TREE_SIDE_EFFECTS (DECL)          \
324           || !DECL_INITIAL (DECL)                                       \
325           || (DECL_INITIAL (DECL) != error_mark_node                    \
326               && !TREE_CONSTANT (DECL_INITIAL (DECL))))                 \
327         data_section ();                                                \
328       else                                                              \
329         const_section ();                                               \
330     }                                                                   \
331   else                                                                  \
332     const_section ();                                                   \
333 }
334
335 /* A C statement or statements to switch to the appropriate
336    section for output of RTX in mode MODE.  RTX is some kind
337    of constant in RTL.  The argument MODE is redundant except
338    in the case of a `const_int' rtx.  Currently, these always
339    go into the const section.  */
340
341 #undef SELECT_RTX_SECTION
342 #define SELECT_RTX_SECTION(MODE,RTX) const_section()
343
344 /* Define the strings used for the special svr4 .type and .size directives.
345    These strings generally do not vary from one system running svr4 to
346    another, but if a given system (e.g. m88k running svr) needs to use
347    different pseudo-op names for these, they may be overridden in the
348    file which includes this one.  */
349
350 #define TYPE_ASM_OP     ".type"
351 #define SIZE_ASM_OP     ".size"
352
353 /* This is how we tell the assembler that a symbol is weak.  */
354
355 #define ASM_WEAKEN_LABEL(FILE,NAME) \
356   do { fputs ("\t.weak\t", FILE); assemble_name (FILE, NAME); \
357        fputc ('\n', FILE); } while (0)
358
359 /* This is how we tell the assembler that two symbols have the same value.  */
360
361 #define ASM_OUTPUT_DEF(FILE,NAME1,NAME2) \
362   do { assemble_name(FILE, NAME1);       \
363        fputs(" = ", FILE);               \
364        assemble_name(FILE, NAME2);       \
365        fputc('\n', FILE); } while (0)
366
367 /* The following macro defines the format used to output the second
368    operand of the .type assembler directive.  Different svr4 assemblers
369    expect various different forms for this operand.  The one given here
370    is just a default.  You may need to override it in your machine-
371    specific tm.h file (depending upon the particulars of your assembler).  */
372
373 #define TYPE_OPERAND_FMT        "@%s"
374
375 /* Write the extra assembler code needed to declare a function's result.
376    Most svr4 assemblers don't require any special declaration of the
377    result value, but there are exceptions.  */
378
379 #ifndef ASM_DECLARE_RESULT
380 #define ASM_DECLARE_RESULT(FILE, RESULT)
381 #endif
382
383 /* These macros generate the special .type and .size directives which
384    are used to set the corresponding fields of the linker symbol table
385    entries in an ELF object file under SVR4.  These macros also output
386    the starting labels for the relevant functions/objects.  */
387
388 /* Write the extra assembler code needed to declare an object properly.  */
389
390 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL)                       \
391   do {                                                                  \
392     fprintf (FILE, "\t%s\t ", TYPE_ASM_OP);                             \
393     assemble_name (FILE, NAME);                                         \
394     putc (',', FILE);                                                   \
395     fprintf (FILE, TYPE_OPERAND_FMT, "object");                         \
396     putc ('\n', FILE);                                                  \
397     size_directive_output = 0;                                          \
398     if (!flag_inhibit_size_directive && DECL_SIZE (DECL))               \
399       {                                                                 \
400         size_directive_output = 1;                                      \
401         fprintf (FILE, "\t%s\t ", SIZE_ASM_OP);                         \
402         assemble_name (FILE, NAME);                                     \
403         fprintf (FILE, ",%d\n",  int_size_in_bytes (TREE_TYPE (DECL))); \
404       }                                                                 \
405     ASM_OUTPUT_LABEL(FILE, NAME);                                       \
406   } while (0)
407
408 /* Output the size directive for a decl in rest_of_decl_compilation
409    in the case where we did not do so before the initializer.
410    Once we find the error_mark_node, we know that the value of
411    size_directive_output was set
412    by ASM_DECLARE_OBJECT_NAME when it was run for the same decl.  */
413
414 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END)         \
415 do {                                                                     \
416      char *name = XSTR (XEXP (DECL_RTL (DECL), 0), 0);                   \
417      if (!flag_inhibit_size_directive && DECL_SIZE (DECL)                \
418          && ! AT_END && TOP_LEVEL                                        \
419          && DECL_INITIAL (DECL) == error_mark_node                       \
420          && !size_directive_output)                                      \
421        {                                                                 \
422          size_directive_output = 1;                                      \
423          fprintf (FILE, "\t%s\t ", SIZE_ASM_OP);                         \
424          assemble_name (FILE, name);                                     \
425          fprintf (FILE, ",%d\n",  int_size_in_bytes (TREE_TYPE (DECL))); \
426        }                                                                 \
427    } while (0)
428
429 /* A table of bytes codes used by the ASM_OUTPUT_ASCII and
430    ASM_OUTPUT_LIMITED_STRING macros.  Each byte in the table
431    corresponds to a particular byte value [0..255].  For any
432    given byte value, if the value in the corresponding table
433    position is zero, the given character can be output directly.
434    If the table value is 1, the byte must be output as a \ooo
435    octal escape.  If the tables value is anything else, then the
436    byte value should be output as a \ followed by the value
437    in the table.  Note that we can use standard UN*X escape
438    sequences for many control characters, but we don't use
439    \a to represent BEL because some svr4 assemblers (e.g. on
440    the i386) don't know about that.  Also, we don't use \v
441    since some versions of gas, such as 2.2 did not accept it.  */
442
443 #define ESCAPES \
444 "\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\
445 \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\
446 \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\
447 \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\
448 \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\
449 \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\
450 \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\
451 \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"
452
453 /* Some svr4 assemblers have a limit on the number of characters which
454    can appear in the operand of a .string directive.  If your assembler
455    has such a limitation, you should define STRING_LIMIT to reflect that
456    limit.  Note that at least some svr4 assemblers have a limit on the
457    actual number of bytes in the double-quoted string, and that they
458    count each character in an escape sequence as one byte.  Thus, an
459    escape sequence like \377 would count as four bytes.
460
461    If your target assembler doesn't support the .string directive, you
462    should define this to zero.
463 */
464
465 #define STRING_LIMIT    ((unsigned) 256)
466
467 #define STRING_ASM_OP   ".string"
468
469 /*
470  * We always use gas here, so we don't worry about ECOFF assembler problems.
471  */
472 #undef TARGET_GAS
473 #define TARGET_GAS      (1)
474
475 #undef PREFERRED_DEBUGGING_TYPE
476 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
477
478 /* Provide a STARTFILE_SPEC appropriate for Linux.  Here we add
479    the Linux magical crtbegin.o file (see crtstuff.c) which
480    provides part of the support for getting C++ file-scope static
481    object constructed before entering `main'. */
482    
483 #undef  STARTFILE_SPEC
484 #define STARTFILE_SPEC \
485   "%{!shared: \
486      %{pg:gcrt1.o%s} %{!pg:%{p:gcrt1.o%s} %{!p:crt1.o%s}}}\
487    crti.o%s %{!shared:crtbegin.o%s} %{shared:crtbeginS.o%s}"
488
489 /* Provide a ENDFILE_SPEC appropriate for Linux.  Here we tack on
490    the Linux magical crtend.o file (see crtstuff.c) which
491    provides part of the support for getting C++ file-scope static
492    object constructed before entering `main', followed by a normal
493    Linux "finalizer" file, `crtn.o'.  */
494
495 #undef  ENDFILE_SPEC
496 #define ENDFILE_SPEC \
497   "%{!shared:crtend.o%s} %{shared:crtendS.o%s} crtn.o%s"