OSDN Git Service

Wed Apr 14 10:48:03 1999 Catherine Moore <clm@cygnus.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 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 /* Until we figure out what MIPS ELF targets normally use, just do
26    stabs in ELF.  */
27 #ifndef PREFERRED_DEBUGGING_TYPE
28 #define PREFERRED_DEBUGGING_TYPE DBX_DEBUG
29 #endif
30
31 /* Mostly like ECOFF.  */
32 #include "gofast.h"
33 #include "mips/ecoff.h"
34
35 /* We need to use .esize and .etype instead of .size and .type to
36    avoid conflicting with ELF directives.  */
37 #undef PUT_SDB_SIZE
38 #define PUT_SDB_SIZE(a)                                 \
39 do {                                                    \
40   extern FILE *asm_out_text_file;                       \
41   fprintf (asm_out_text_file, "\t.esize\t%d;", (a));    \
42 } while (0)
43
44 #undef PUT_SDB_TYPE
45 #define PUT_SDB_TYPE(a)                                 \
46 do {                                                    \
47   extern FILE *asm_out_text_file;                       \
48   fprintf (asm_out_text_file, "\t.etype\t0x%x;", (a));  \
49 } while (0)
50
51 /* Biggest alignment supported by the object file format of this
52    machine.  Use this macro to limit the alignment which can be
53    specified using the `__attribute__ ((aligned (N)))' construct.  If
54    not defined, the default value is `BIGGEST_ALIGNMENT'.  */
55
56 #define MAX_OFILE_ALIGNMENT (32768*8)
57
58 /* A C statement to output something to the assembler file to switch to section
59    NAME for object DECL which is either a FUNCTION_DECL, a VAR_DECL or
60    NULL_TREE.  Some target formats do not support arbitrary sections.  Do not
61    define this macro in such cases.  */
62
63 #define ASM_OUTPUT_SECTION_NAME(F, DECL, NAME, RELOC) \
64 do {                                                            \
65   extern FILE *asm_out_text_file;                               \
66   if ((DECL) && TREE_CODE (DECL) == FUNCTION_DECL)              \
67     fprintf (asm_out_text_file, "\t.section %s,\"ax\",@progbits\n", (NAME)); \
68   else if ((DECL) && DECL_READONLY_SECTION (DECL, RELOC))       \
69     fprintf (F, "\t.section %s,\"a\",@progbits\n", (NAME));     \
70   else                                                          \
71     fprintf (F, "\t.section %s,\"aw\",@progbits\n", (NAME));    \
72 } while (0)
73
74 /* The following macro defines the format used to output the second
75    operand of the .type assembler directive.  Different svr4 assemblers
76    expect various different forms for this operand.  The one given here
77    is just a default.  You may need to override it in your machine-
78    specific tm.h file (depending upon the particulars of your assembler).  */
79
80 #define TYPE_OPERAND_FMT        "@%s"
81
82 /* Define the strings used for the special svr4 .type and .size directives.
83    These strings generally do not vary from one system running svr4 to
84    another, but if a given system (e.g. m88k running svr) needs to use
85    different pseudo-op names for these, they may be overridden in the
86    file which includes this one.  */
87
88 #undef TYPE_ASM_OP
89 #undef SIZE_ASM_OP
90 #define TYPE_ASM_OP     ".type"
91 #define SIZE_ASM_OP     ".size"
92
93 /* These macros generate the special .type and .size directives which
94    are used to set the corresponding fields of the linker symbol table
95    entries in an ELF object file under SVR4.  These macros also output
96    the starting labels for the relevant functions/objects.  */
97
98 /* Write the extra assembler code needed to declare an object properly.  */
99
100 #undef ASM_DECLARE_OBJECT_NAME
101 #define ASM_DECLARE_OBJECT_NAME(FILE, NAME, DECL)                       \
102   do {                                                                  \
103     fprintf (FILE, "\t%s\t ", TYPE_ASM_OP);                             \
104     assemble_name (FILE, NAME);                                         \
105     putc (',', FILE);                                                   \
106     fprintf (FILE, TYPE_OPERAND_FMT, "object");                         \
107     putc ('\n', FILE);                                                  \
108     size_directive_output = 0;                                          \
109     if (!flag_inhibit_size_directive && DECL_SIZE (DECL))               \
110       {                                                                 \
111         size_directive_output = 1;                                      \
112         fprintf (FILE, "\t%s\t ", SIZE_ASM_OP);                         \
113         assemble_name (FILE, NAME);                                     \
114         fprintf (FILE, ",%d\n",  int_size_in_bytes (TREE_TYPE (DECL))); \
115       }                                                                 \
116     mips_declare_object (FILE, NAME, "", ":\n", 0);                     \
117   } while (0)
118
119 /* Output the size directive for a decl in rest_of_decl_compilation
120    in the case where we did not do so before the initializer.
121    Once we find the error_mark_node, we know that the value of
122    size_directive_output was set
123    by ASM_DECLARE_OBJECT_NAME when it was run for the same decl.  */
124
125 #undef ASM_FINISH_DECLARE_OBJECT
126 #define ASM_FINISH_DECLARE_OBJECT(FILE, DECL, TOP_LEVEL, AT_END)         \
127 do {                                                                     \
128      char *name = XSTR (XEXP (DECL_RTL (DECL), 0), 0);                   \
129      if (!flag_inhibit_size_directive && DECL_SIZE (DECL)                \
130          && ! AT_END && TOP_LEVEL                                        \
131          && DECL_INITIAL (DECL) == error_mark_node                       \
132          && !size_directive_output)                                      \
133        {                                                                 \
134          size_directive_output = 1;                                      \
135          fprintf (FILE, "\t%s\t ", SIZE_ASM_OP);                         \
136          assemble_name (FILE, name);                                     \
137          fprintf (FILE, ",%d\n", int_size_in_bytes (TREE_TYPE (DECL)));  \
138        }                                                                 \
139    } while (0)
140
141 #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2)                            \
142  do { fputc ( '\t', FILE);                                            \
143       assemble_name (FILE, LABEL1);                                   \
144       fputs ( " = ", FILE);                                           \
145       assemble_name (FILE, LABEL2);                                   \
146       fputc ( '\n', FILE);                                            \
147  } while (0)
148
149 /* Note about .weak vs. .weakext
150    The mips native assemblers support .weakext, but not .weak.
151    mips-elf gas supports .weak, but not .weakext.
152    mips-elf gas has been changed to support both .weak and .weakext,
153    but until that support is generally available, the 'if' below
154    should serve. */
155
156 #define ASM_WEAKEN_LABEL(FILE,NAME) ASM_OUTPUT_WEAK_ALIAS(FILE,NAME,0)
157 #define ASM_OUTPUT_WEAK_ALIAS(FILE,NAME,VALUE)  \
158  do {                                           \
159   if (TARGET_GAS)                               \
160       fputs ("\t.weak\t", FILE);                \
161   else                                          \
162       fputs ("\t.weakext\t", FILE);             \
163   assemble_name (FILE, NAME);                   \
164   if (VALUE)                                    \
165     {                                           \
166       fputc (' ', FILE);                        \
167       assemble_name (FILE, VALUE);              \
168     }                                           \
169   fputc ('\n', FILE);                           \
170  } while (0)
171
172 #define MAKE_DECL_ONE_ONLY(DECL) (DECL_WEAK (DECL) = 1)
173 #define UNIQUE_SECTION_P(DECL) (DECL_ONE_ONLY (DECL))
174 #define UNIQUE_SECTION(DECL,RELOC)                                         \
175 do {                                                                       \
176   int len, size, sec;                                                      \
177   char *name, *string, *prefix;                                            \
178   static char *prefixes[4][2] = {                                          \
179     { ".text.", ".gnu.linkonce.t." },                                      \
180     { ".rodata.", ".gnu.linkonce.r." },                                    \
181     { ".data.", ".gnu.linkonce.d." },                                      \
182     { ".sdata.", ".gnu.linkonce.s." }                                      \
183   };                                                                       \
184                                                                            \
185   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (DECL));                  \
186   size = int_size_in_bytes (TREE_TYPE (decl));                             \
187                                                                            \
188   /* Determine the base section we are interested in:                      \
189      0=text, 1=rodata, 2=data, 3=sdata.  */                                \
190   if (TREE_CODE (DECL) == FUNCTION_DECL)                                   \
191     sec = 0;                                                               \
192   else if ((TARGET_EMBEDDED_PIC || TARGET_MIPS16)                          \
193       && TREE_CODE (decl) == STRING_CST                                    \
194       && !flag_writable_strings)                                           \
195     {                                                                      \
196       /* For embedded position independent code, put constant strings      \
197          in the text section, because the data section is limited to       \
198          64K in size.  For mips16 code, put strings in the text            \
199          section so that a PC relative load instruction can be used to     \
200          get their address.  */                                            \
201       sec = 0;                                                             \
202     }                                                                      \
203   else if (TARGET_EMBEDDED_DATA)                                           \
204     {                                                                      \
205       /* For embedded applications, always put an object in read-only data \
206          if possible, in order to reduce RAM usage.  */                    \
207                                                                            \
208       if (DECL_READONLY_SECTION (DECL, RELOC))                             \
209         sec = 1;                                                           \
210       else if (size > 0 && size <= mips_section_threshold)                 \
211         sec = 3;                                                           \
212       else                                                                 \
213         sec = 2;                                                           \
214     }                                                                      \
215   else                                                                     \
216     {                                                                      \
217       /* For hosted applications, always put an object in small data if    \
218          possible, as this gives the best performance.  */                 \
219                                                                            \
220       if (size > 0 && size <= mips_section_threshold)                      \
221         sec = 3;                                                           \
222       else if (DECL_READONLY_SECTION (DECL, RELOC))                        \
223         sec = 1;                                                           \
224       else                                                                 \
225         sec = 2;                                                           \
226     }                                                                      \
227                                                                            \
228   prefix = prefixes[sec][DECL_ONE_ONLY (DECL)];                            \
229   len = strlen (name) + strlen (prefix);                                   \
230   string = alloca (len + 1);                                               \
231   sprintf (string, "%s%s", prefix, name);                                  \
232                                                                            \
233   DECL_SECTION_NAME (DECL) = build_string (len, string);                   \
234 } while (0)
235
236 /* Support the ctors/dtors and other sections.  */
237  
238 /* Define the pseudo-ops used to switch to the .ctors and .dtors sections.
239  
240    Note that we want to give these sections the SHF_WRITE attribute
241    because these sections will actually contain data (i.e. tables of
242    addresses of functions in the current root executable or shared library
243    file) and, in the case of a shared library, the relocatable addresses
244    will have to be properly resolved/relocated (and then written into) by
245    the dynamic linker when it actually attaches the given shared library
246    to the executing process.  (Note that on SVR4, you may wish to use the
247    `-z text' option to the ELF linker, when building a shared library, as
248    an additional check that you are doing everything right.  But if you do
249    use the `-z text' option when building a shared library, you will get
250    errors unless the .ctors and .dtors sections are marked as writable
251    via the SHF_WRITE attribute.)  */
252
253 #define CTORS_SECTION_ASM_OP    "\t.section\t.ctors,\"aw\""
254 #define DTORS_SECTION_ASM_OP    "\t.section\t.dtors,\"aw\""
255  
256 /* A list of other sections which the compiler might be "in" at any
257    given time.  */
258 #undef EXTRA_SECTIONS
259 #define EXTRA_SECTIONS in_sdata, in_rdata, in_ctors, in_dtors
260  
261 #define INVOKE__main
262 #define NAME__MAIN "__gccmain"
263 #define SYMBOL__MAIN __gccmain
264
265 #undef EXTRA_SECTION_FUNCTIONS
266 #define EXTRA_SECTION_FUNCTIONS                                         \
267   SECTION_FUNCTION_TEMPLATE(sdata_section, in_sdata, SDATA_SECTION_ASM_OP) \
268   SECTION_FUNCTION_TEMPLATE(rdata_section, in_rdata, RDATA_SECTION_ASM_OP) \
269   SECTION_FUNCTION_TEMPLATE(ctors_section, in_ctors, CTORS_SECTION_ASM_OP) \
270   SECTION_FUNCTION_TEMPLATE(dtors_section, in_dtors, DTORS_SECTION_ASM_OP)
271
272 #define SECTION_FUNCTION_TEMPLATE(FN, ENUM, OP)                               \
273 void FN ()                                                            \
274 {                                                                     \
275   if (in_section != ENUM)                                             \
276     {                                                                 \
277       fprintf (asm_out_file, "%s\n", OP);                             \
278       in_section = ENUM;                                              \
279     }                                                                 \
280 }
281
282
283 /* A C statement (sans semicolon) to output an element in the table of
284    global constructors.  */
285 #define ASM_OUTPUT_CONSTRUCTOR(FILE,NAME)                             \
286   do {                                                                \
287     ctors_section ();                                                 \
288     fprintf (FILE, "\t%s\t", TARGET_LONG64 ? ".dword" : ".word");     \
289     assemble_name (FILE, NAME);                                       \
290     fprintf (FILE, "\n");                                             \
291   } while (0)
292
293
294 /* A C statement (sans semicolon) to output an element in the table of
295    global destructors.  */
296 #define ASM_OUTPUT_DESTRUCTOR(FILE,NAME)                              \
297   do {                                                                \
298     dtors_section ();                                                 \
299     fprintf (FILE, "\t%s\t", TARGET_LONG64 ? ".dword" : ".word");     \
300     assemble_name (FILE, NAME);                                       \
301     fprintf (FILE, "\n");                                             \
302   } while (0)
303
304 #define CTOR_LIST_BEGIN                                 \
305 asm (CTORS_SECTION_ASM_OP);                             \
306 func_ptr __CTOR_LIST__[1] = { (func_ptr) (-1) }
307  
308 #define CTOR_LIST_END                                   \
309 asm (CTORS_SECTION_ASM_OP);                             \
310 func_ptr __CTOR_END__[1] = { (func_ptr) 0 };
311  
312 #define DTOR_LIST_BEGIN                                 \
313 asm (DTORS_SECTION_ASM_OP);                             \
314 func_ptr __DTOR_LIST__[1] = { (func_ptr) (-1) }
315
316 #define DTOR_LIST_END                                   \
317 asm (DTORS_SECTION_ASM_OP);                             \
318 func_ptr __DTOR_END__[1] = { (func_ptr) 0 };
319
320 /* Don't set the target flags, this is done by the linker script */
321 #undef LIB_SPEC
322 #define LIB_SPEC ""
323
324 #undef  STARTFILE_SPEC
325 #define STARTFILE_SPEC "crtbegin%O%s crt0%O%s"
326
327 #undef  ENDFILE_SPEC
328 #define ENDFILE_SPEC "crtend%O%s"