OSDN Git Service

2002-07-24 Chris Demetriou <cgd@broadcom.com>
[pf3gnuchains/gcc-fork.git] / gcc / config / mips / elf.h
1 /* Definitions of target machine for GNU compiler.  MIPS R3000 version with
2    GOFAST floating point library.
3    Copyright (C) 1994, 1997, 1999, 2000, 2002 Free Software Foundation, Inc.
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 /* Use ELF.  */
23 #define OBJECT_FORMAT_ELF
24
25 /* All ELF targets can support DWARF-2.  */
26
27 #ifndef DWARF2_DEBUGGING_INFO
28 #define DWARF2_DEBUGGING_INFO 1
29 #endif
30
31 /* Until we figure out what MIPS ELF targets normally use, just do
32    stabs in ELF.  */
33 #ifndef PREFERRED_DEBUGGING_TYPE
34 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
35 #endif
36
37 /* Mostly like ECOFF.  */
38 #include "gofast.h"
39 #include "mips/ecoff.h"
40
41 /* We need to use .esize and .etype instead of .size and .type to
42    avoid conflicting with ELF directives.  */
43 #undef PUT_SDB_SIZE
44 #define PUT_SDB_SIZE(a)                                 \
45 do {                                                    \
46   extern FILE *asm_out_text_file;                       \
47   fprintf (asm_out_text_file, "\t.esize\t");            \
48   fprintf (asm_out_text_file, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT) (a)); \
49   fprintf (asm_out_text_file, ";");                     \
50 } while (0)
51
52 #undef PUT_SDB_TYPE
53 #define PUT_SDB_TYPE(a)                                 \
54 do {                                                    \
55   extern FILE *asm_out_text_file;                       \
56   fprintf (asm_out_text_file, "\t.etype\t0x%x;", (a));  \
57 } while (0)
58
59 /* Biggest alignment supported by the object file format of this
60    machine.  Use this macro to limit the alignment which can be
61    specified using the `__attribute__ ((aligned (N)))' construct.  If
62    not defined, the default value is `BIGGEST_ALIGNMENT'.  */
63
64 #undef MAX_OFILE_ALIGNMENT
65 #define MAX_OFILE_ALIGNMENT (32768*8)
66
67 /* Switch into a generic section.  */
68 #undef TARGET_ASM_NAMED_SECTION
69 #define TARGET_ASM_NAMED_SECTION  default_elf_asm_named_section
70
71 /* Given that Irix has it's own headers, not having TARGET_GAS here
72    seems a mistake.  If we actually need to be prepared for file
73    switching, then we need a custom TARGET_ASM_NAMED_SECTION too.  */
74
75 #undef TEXT_SECTION
76 #define TEXT_SECTION()                          \
77 do {                                            \
78   if (TARGET_FILE_SWITCHING)                    \
79     abort ();                                   \
80   fputs (TEXT_SECTION_ASM_OP, asm_out_file);    \
81   fputc ('\n', asm_out_file);                   \
82 } while (0)
83
84 /* The following macro defines the format used to output the second
85    operand of the .type assembler directive.  Different svr4 assemblers
86    expect various different forms for this operand.  The one given here
87    is just a default.  You may need to override it in your machine-
88    specific tm.h file (depending upon the particulars of your assembler).  */
89
90 #define TYPE_OPERAND_FMT        "@%s"
91
92 /* Define the strings used for the special svr4 .type and .size directives.
93    These strings generally do not vary from one system running svr4 to
94    another, but if a given system (e.g. m88k running svr) needs to use
95    different pseudo-op names for these, they may be overridden in the
96    file which includes this one.  */
97
98 #undef TYPE_ASM_OP
99 #undef SIZE_ASM_OP
100 #define TYPE_ASM_OP     "\t.type\t"
101 #define SIZE_ASM_OP     "\t.size\t"
102
103 /* If defined, a C expression whose value is a string containing the
104    assembler operation to identify the following data as
105    uninitialized global data.  If not defined, and neither
106    `ASM_OUTPUT_BSS' nor `ASM_OUTPUT_ALIGNED_BSS' are defined,
107    uninitialized global data will be output in the data section if
108    `-fno-common' is passed, otherwise `ASM_OUTPUT_COMMON' will be
109    used.  */
110
111 #ifndef BSS_SECTION_ASM_OP
112 #define BSS_SECTION_ASM_OP      "\t.section\t.bss"
113 #endif
114
115 #undef  SBSS_SECTION_ASM_OP
116 #define SBSS_SECTION_ASM_OP     "\t.section .sbss"
117
118 /* Like `ASM_OUTPUT_BSS' except takes the required alignment as a
119    separate, explicit argument.  If you define this macro, it is used
120    in place of `ASM_OUTPUT_BSS', and gives you more flexibility in
121    handling the required alignment of the variable.  The alignment is
122    specified as the number of bits.
123
124    Try to use function `asm_output_aligned_bss' defined in file
125    `varasm.c' when defining this macro.  */
126 #ifndef ASM_OUTPUT_ALIGNED_BSS
127 #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \
128 do {                                                                    \
129   ASM_GLOBALIZE_LABEL (FILE, NAME);                                     \
130   if (SIZE > 0 && SIZE <= mips_section_threshold)                       \
131     sbss_section ();                                                    \
132   else                                                                  \
133     bss_section ();                                                     \
134   ASM_OUTPUT_ALIGN (FILE, floor_log2 (ALIGN / BITS_PER_UNIT));          \
135   last_assemble_variable_decl = DECL;                                   \
136   ASM_DECLARE_OBJECT_NAME (FILE, NAME, DECL);                           \
137   ASM_OUTPUT_SKIP (FILE, SIZE ? SIZE : 1);                              \
138 } while (0)
139 #endif
140
141 /* These macros generate the special .type and .size directives which
142    are used to set the corresponding fields of the linker symbol table
143    entries in an ELF object file under SVR4.  These macros also output
144    the starting labels for the relevant functions/objects.  */
145
146 /* Write the extra assembler code needed to declare an object properly.  */
147
148 #undef ASM_DECLARE_OBJECT_NAME
149 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL)                       \
150   do {                                                                  \
151     fprintf (FILE, "%s", TYPE_ASM_OP);                          \
152     assemble_name (FILE, NAME);                                         \
153     putc (',', FILE);                                                   \
154     fprintf (FILE, TYPE_OPERAND_FMT, "object");                         \
155     putc ('\n', FILE);                                                  \
156     size_directive_output = 0;                                          \
157     if (!flag_inhibit_size_directive && DECL_SIZE (DECL))               \
158       {                                                                 \
159         size_directive_output = 1;                                      \
160         fprintf (FILE, "%s", SIZE_ASM_OP);                              \
161         assemble_name (FILE, NAME);                                     \
162         fprintf (FILE, ",");                                            \
163         fprintf (FILE, HOST_WIDE_INT_PRINT_DEC,                         \
164           int_size_in_bytes (TREE_TYPE (DECL)));                        \
165         fprintf (FILE, "\n");                                           \
166       }                                                                 \
167     mips_declare_object (FILE, NAME, "", ":\n", 0);                     \
168   } while (0)
169
170 /* Output the size directive for a decl in rest_of_decl_compilation
171    in the case where we did not do so before the initializer.
172    Once we find the error_mark_node, we know that the value of
173    size_directive_output was set
174    by ASM_DECLARE_OBJECT_NAME when it was run for the same decl.  */
175
176 #undef ASM_FINISH_DECLARE_OBJECT
177 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END)         \
178 do {                                                                     \
179      const char *name = XSTR (XEXP (DECL_RTL (DECL), 0), 0);             \
180      if (!flag_inhibit_size_directive && DECL_SIZE (DECL)                \
181          && ! AT_END && TOP_LEVEL                                        \
182          && DECL_INITIAL (DECL) == error_mark_node                       \
183          && !size_directive_output)                                      \
184        {                                                                 \
185          size_directive_output = 1;                                      \
186          fprintf (FILE, "%s", SIZE_ASM_OP);                              \
187          assemble_name (FILE, name);                                     \
188          fprintf (FILE, ",");                                            \
189          fprintf (FILE, HOST_WIDE_INT_PRINT_DEC,                         \
190                   int_size_in_bytes (TREE_TYPE (DECL)));                 \
191          fprintf (FILE, "\n");                                           \
192        }                                                                 \
193    } while (0)
194
195 #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2)                            \
196  do { fputc ( '\t', FILE);                                            \
197       assemble_name (FILE, LABEL1);                                   \
198       fputs ( " = ", FILE);                                           \
199       assemble_name (FILE, LABEL2);                                   \
200       fputc ( '\n', FILE);                                            \
201  } while (0)
202
203 /* Note about .weak vs. .weakext
204    The mips native assemblers support .weakext, but not .weak.
205    mips-elf gas supports .weak, but not .weakext.
206    mips-elf gas has been changed to support both .weak and .weakext,
207    but until that support is generally available, the 'if' below
208    should serve.  */
209
210 #undef ASM_WEAKEN_LABEL
211 #define ASM_WEAKEN_LABEL(FILE,NAME) ASM_OUTPUT_WEAK_ALIAS(FILE,NAME,0)
212 #define ASM_OUTPUT_WEAK_ALIAS(FILE,NAME,VALUE)  \
213  do {                                           \
214   if (TARGET_GAS)                               \
215       fputs ("\t.weak\t", FILE);                \
216   else                                          \
217       fputs ("\t.weakext\t", FILE);             \
218   assemble_name (FILE, NAME);                   \
219   if (VALUE)                                    \
220     {                                           \
221       fputc (' ', FILE);                        \
222       assemble_name (FILE, VALUE);              \
223     }                                           \
224   fputc ('\n', FILE);                           \
225  } while (0)
226
227 #define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1)
228
229 #define TARGET_ASM_UNIQUE_SECTION  mips_unique_section
230
231 /* A list of other sections which the compiler might be "in" at any
232    given time.  */
233 #undef EXTRA_SECTIONS
234 #define EXTRA_SECTIONS in_sdata, in_sbss
235
236 #undef EXTRA_SECTION_FUNCTIONS
237 #define EXTRA_SECTION_FUNCTIONS                                         \
238   SECTION_FUNCTION_TEMPLATE(sdata_section, in_sdata, SDATA_SECTION_ASM_OP) \
239   SECTION_FUNCTION_TEMPLATE(sbss_section, in_sbss, SBSS_SECTION_ASM_OP)
240
241 #define SECTION_FUNCTION_TEMPLATE(FN, ENUM, OP)                               \
242 void FN ()                                                            \
243 {                                                                     \
244   if (in_section != ENUM)                                             \
245     {                                                                 \
246       fprintf (asm_out_file, "%s\n", OP);                             \
247       in_section = ENUM;                                              \
248     }                                                                 \
249 }
250
251 /* On elf, we *do* have support for the .init and .fini sections, and we
252    can put stuff in there to be executed before and after `main'.  We let
253    crtstuff.c and other files know this by defining the following symbols.
254    The definitions say how to change sections to the .init and .fini
255    sections.  This is the same for all known elf assemblers.  */
256
257 #undef  INIT_SECTION_ASM_OP
258 #define INIT_SECTION_ASM_OP     "\t.section\t.init"
259 #undef  FINI_SECTION_ASM_OP
260 #define FINI_SECTION_ASM_OP     "\t.section\t.fini"
261
262 /* Don't set the target flags, this is done by the linker script */
263 #undef LIB_SPEC
264 #define LIB_SPEC ""
265
266 #undef  STARTFILE_SPEC
267 #define STARTFILE_SPEC "crti%O%s crtbegin%O%s %{!mno-crt0:crt0%O%s}"
268
269 #undef  ENDFILE_SPEC
270 #define ENDFILE_SPEC "crtend%O%s crtn%O%s"